]> andersk Git - moira.git/blame - backup/db2bkup.awk
send mail about update errors
[moira.git] / backup / db2bkup.awk
CommitLineData
6fb7536b 1# $Source$
2# $Header$
3#
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
7# need to be extended.
8
9BEGIN { print "/* This file automatically generated */";
10 print "/* Do not edit */";
11 print "#include <stdio.h>";
d55654f4 12 print "#include \"dump_db.h\"";
6fb7536b 13 print "/* This file automatically generated */" > "bkup1.qc";
14 print "/* Do not edit */" >> "bkup1.qc"
d55654f4 15 print "#include <stdio.h>" >> "bkup1.qc"
16 print "FILE *open_file();" >> "bkup1.qc"
6fb7536b 17 print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.qc"
18}
19
20/^create/ { printf "dump_%s(f)\nFILE *f;\n", $2;
21 printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $2, $2 >> "bkup1.qc"
22 tablename = $2;
23 rangename = substr(tablename, 1, 1);
24 count = 0; }
25
26$2 ~ /\=/ {
27 vname[count] = $1;
28 printf "/* %s */\n", $0
364a4f5d 29 if ($3 ~ /i[124]/) {
6fb7536b 30 printf "## int t_%s;\n", vname[count]
31 vtype[count]="int"
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;
38 vtype[count]="str"
39 } else if ($3 ~ /date/) {
40 printf "## char t_%s[26];\n", vname[count]
41 vtype[count]="str"
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
45 vtype[count]="str"
46 } else printf "Unknown data type %s\n", $3;
47 count++;
48}
49
50/^\($/ { print "##{" }
51/^\)$/ {
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]
57 }
58 printf ")\n"
59 printf "## {\n"
60 for (i = 0; i < count; i++) {
d55654f4 61 if (i != 0) print "\t\tdump_sep(f);"
6fb7536b 62 printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]
63 }
64 printf "\t\tdump_nl(f);\n"
65 printf "## }\n"
66 printf "\tsafe_close(f);\n"
67 printf "##}\n"
68}
69END { print "/* All done */"
70 print "}" >>"bkup1.qc"
71}
This page took 0.06685 seconds and 5 git commands to generate.