4 # This converts the file used to originally create the database
5 # into a program to back it up.
6 # This is not guaranteed to work for all data types; it may
9 BEGIN { print "/* This file automatically generated */";
10 print "/* Do not edit */";
11 print "#include <stdio.h>";
12 print "#include \"dump_db.h\"";
13 print "/* This file automatically generated */" > "bkup1.qc";
14 print "/* Do not edit */" >> "bkup1.qc"
15 print "#include <stdio.h>" >> "bkup1.qc"
16 print "FILE *open_file();" >> "bkup1.qc"
17 print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.qc"
20 /^create/ { printf "dump_%s(f)\nFILE *f;\n", $2;
21 printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $2, $2 >> "bkup1.qc"
23 rangename = substr(tablename, 1, 1);
28 printf "/* %s */\n", $0
30 printf "## int t_%s;\n", vname[count]
32 } else if ($3 ~ /text\([0-9]*\)/) {
33 t = split($3, temp, "(")
34 if (t != 2) printf "Can't parse %s\n", $3;
35 t = split(temp[2], temp2, ")")
36 if (t != 2) printf "Can't parse %s\n", temp[2];
37 printf "## char t_%s[%d];\n", vname[count], temp2[1]+1;
39 } else if ($3 ~ /date/) {
40 printf "## char t_%s[26];\n", vname[count]
42 } else if ($3 ~ /c[0-9]*/) {
43 t = split($3, temp, ",")
44 printf "## char t_%s[%d];\n", vname[count], substr(temp[1], 2) + 1
46 } else printf "Unknown data type %s\n", $3;
50 /^\($/ { print "##{" }
52 printf "## range of %s is %s\n", rangename, tablename
53 printf "## retrieve(\n"
54 for (i = 0; i < count; i++) {
55 if (i != 0) printf ",\n";
56 printf "##\t\tt_%s = %s.%s", vname[i], rangename, vname[i]
60 for (i = 0; i < count; i++) {
61 if (i != 0) print "\t\tdump_sep(f);"
62 printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]
64 printf "\t\tdump_nl(f);\n"
66 printf "\tsafe_close(f);\n"
69 END { print "/* All done */"
70 print "}" >>"bkup1.qc"