3 # Build moira_schema.c and .h from the schema.sql file
4 # It knows which one to build cased on whether or not its input is
8 print "/* This file automatically generated */";
9 print "/* Do not edit */\n";
19 tablename[ntables] = $3;
26 tablename[ntables] = $3;
32 if ($2 ~ /CHAR\([0-9]*\)/) {
33 t = split($2, temp, "(");
34 if (t != 2) printf "Can't parse %s\n", $2;
35 t = split(temp[2], temp2, ")");
36 if (t != 2) printf "Can't parse %s\n", temp[2];
37 width[count] = temp2[1];
38 } else if ($2 ~ /DATE/)
45 if (hfile && width[count]) {
46 printf "#define %s_%s_SIZE %d\n", tablename[ntables], $1, width[count] + 1;
47 if (width[count] > maxsize)
48 maxsize = width[count];
56 printf "int %s_widths[] = { ", tablename[ntables];
57 for (i = 0; i < count; i++) {
58 printf "%d", width[i];
69 printf "\n#define MAX_FIELD_WIDTH %d\n", maxsize + 1;
70 printf "\nenum tables { NO_TABLE,";
73 printf "\nint num_tables = %d;\n", ntables;
74 printf "\nchar *table_name[] = { \"none\",";
78 for (i = 0; i < ntables; i++) {
80 str = sprintf(" %s_TABLE", tablename[i]);
82 str = sprintf(" \"%s\"", tablename[i]);
83 if (len + length(str) > 75) {