/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. # !!!! You need to manually generate Schema.sql.h when the schema changes:
  3. # ./gen_schema.h.sh ./Schema.sql tomahawk > Schema.sql.h
  4. schema=$1
  5. name=$2
  6. if [ -e "$schema" -a -n "$name" ]
  7. then
  8. cat <<EOF
  9. /*
  10. This file was automatically generated from $schema on `date`.
  11. */
  12. static const char * ${name}_schema_sql =
  13. EOF
  14. awk '!/^-/ && length($0) {gsub(/[ \t]+$/, "", $0); gsub("\"","\\\"",$0); gsub("--.*$","",$0); printf("\"%s\"\n",$0);}' "$schema"
  15. cat <<EOF
  16. ;
  17. const char * get_${name}_sql()
  18. {
  19. return ${name}_schema_sql;
  20. }
  21. EOF
  22. else
  23. echo "Usage: $0 <Schema.sql> <name>"
  24. exit 1
  25. fi