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 "/* This file automatically generated */" > "bkup1.qc";
13 print "/* Do not edit */" >> "bkup1.qc"
14 print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.qc"
17 /^create/ { printf "dump_%s(f)\nFILE *f;\n", $2;
18 printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $2, $2 >> "bkup1.qc"
20 rangename = substr(tablename, 1, 1);
25 printf "/* %s */\n", $0
27 printf "## int t_%s;\n", vname[count]
29 } else if ($3 ~ /text\([0-9]*\)/) {
30 t = split($3, temp, "(")
31 if (t != 2) printf "Can't parse %s\n", $3;
32 t = split(temp[2], temp2, ")")
33 if (t != 2) printf "Can't parse %s\n", temp[2];
34 printf "## char t_%s[%d];\n", vname[count], temp2[1]+1;
36 } else if ($3 ~ /date/) {
37 printf "## char t_%s[26];\n", vname[count]
39 } else if ($3 ~ /c[0-9]*/) {
40 t = split($3, temp, ",")
41 printf "## char t_%s[%d];\n", vname[count], substr(temp[1], 2) + 1
43 } else printf "Unknown data type %s\n", $3;
47 /^\($/ { print "##{" }
49 printf "## range of %s is %s\n", rangename, tablename
50 printf "## retrieve(\n"
51 for (i = 0; i < count; i++) {
52 if (i != 0) printf ",\n";
53 printf "##\t\tt_%s = %s.%s", vname[i], rangename, vname[i]
57 for (i = 0; i < count; i++) {
58 if (i != 0) print "\t\tdump_str(f, \":\");"
59 printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]
61 printf "\t\tdump_nl(f);\n"
63 printf "\tsafe_close(f);\n"
66 END { print "/* All done */"
67 print "}" >>"bkup1.qc"