]> andersk Git - moira.git/commitdiff
missing from previous commit
authordanw <danw>
Tue, 3 Mar 1998 00:04:19 +0000 (00:04 +0000)
committerdanw <danw>
Tue, 3 Mar 1998 00:04:19 +0000 (00:04 +0000)
db/doschema.awk [new file with mode: 0644]

diff --git a/db/doschema.awk b/db/doschema.awk
new file mode 100644 (file)
index 0000000..c453d99
--- /dev/null
@@ -0,0 +1,93 @@
+# $Id$
+#
+# Build moira_schema.c and .h from the schema.sql file
+# It knows which one to build cased on whether or not its input is
+# in all caps.
+
+BEGIN {
+       print "/* This file automatically generated */";
+       print "/* Do not edit */\n";
+
+       ntables = 0;
+       maxsize = 0;
+}
+
+$1 == "#" { next; }
+
+/^create/ {
+  cfile = 1;
+  tablename[ntables] = $3;
+  count = 0;
+  next;
+}
+
+/^CREATE/ {
+  hfile = 1;
+  tablename[ntables] = $3;
+  count = 0;
+  next;
+}
+
+NF >= 2 {
+  if ($2 ~ /CHAR\([0-9]*\)/) {
+    t = split($2, temp, "(");
+    if (t != 2) printf "Can't parse %s\n", $2;
+    t = split(temp[2], temp2, ")");
+    if (t != 2) printf "Can't parse %s\n", temp[2];
+    width[count] = temp2[1];
+  } else if ($2 ~ /DATE/)
+    width[count] = 21;
+  else if ($2 ~ /INT/)
+    width[count] = 10;
+  else
+    width[count] = 0;
+
+  if (hfile && width[count]) {
+    printf "#define %s_%s_SIZE %d\n", tablename[ntables], $1, width[count] + 1;
+    if (width[count] > maxsize)
+      maxsize = width[count];
+  }
+
+  count++;
+}
+
+/^\);$/ {
+  if (cfile) {
+    printf "int %s_widths[] = { ", tablename[ntables];
+    for (i = 0; i < count; i++) {
+      printf "%d", width[i];
+      if (i < count-1)
+       printf ", ";
+    }
+    printf "};\n";
+  }
+  ntables++;
+}
+
+END {
+  if (hfile) {
+    printf "\n#define MAX_FIELD_WIDTH %d\n", maxsize;
+    printf "\nenum tables { NO_TABLE,";
+    len = 22;
+  } else {
+    printf "\nint num_tables = %d;\n", ntables;
+    printf "\nchar *table_name[] = { \"none\",";
+    len = 29;
+  }
+
+  for (i = 0; i < ntables; i++) {
+    if (hfile)
+      str = sprintf(" %s_TABLE", tablename[i]);
+    else
+      str = sprintf(" \"%s\"", tablename[i]);
+    if (len + length(str) > 75) {
+      printf "\n ";
+      len = 1;
+    }
+    printf str;
+    if (i != ntables - 1)
+      printf ",";
+    len += length(str);
+  }
+  print "\n};\n";
+}
This page took 0.060367 seconds and 5 git commands to generate.