PageRenderTime 92ms CodeModel.GetById 51ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/src/libtomahawk/database/gen_schema.h.sh

http://github.com/tomahawk-player/tomahawk
Shell | 32 lines | 22 code | 7 blank | 3 comment | 1 complexity | 957d33906fd836ad5260ddd22b766dc5 MD5 | raw file
 1#!/bin/bash
 2
 3# !!!! You need to manually generate Schema.sql.h when the schema changes:
 4# ./gen_schema.h.sh ./Schema.sql tomahawk > Schema.sql.h
 5
 6schema=$1
 7name=$2
 8
 9if [ -e "$schema" -a -n "$name" ]
10then
11cat <<EOF
12/*
13    This file was automatically generated from $schema on `date`.
14*/
15
16static const char * ${name}_schema_sql = 
17EOF
18    awk '!/^-/ && length($0) {gsub(/[ \t]+$/, "", $0); gsub("\"","\\\"",$0); gsub("--.*$","",$0); printf("\"%s\"\n",$0);}' "$schema"
19cat <<EOF
20    ;
21
22const char * get_${name}_sql()
23{
24    return ${name}_schema_sql;
25}
26
27
28EOF
29else
30    echo "Usage: $0 <Schema.sql> <name>"
31    exit 1
32fi