]> andersk Git - moira.git/blame - backup/db2bkup.awk
Initial revision
[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>";
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"
15}
16
17/^create/ { printf "dump_%s(f)\nFILE *f;\n", $2;
18 printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $2, $2 >> "bkup1.qc"
19 tablename = $2;
20 rangename = substr(tablename, 1, 1);
21 count = 0; }
22
23$2 ~ /\=/ {
24 vname[count] = $1;
25 printf "/* %s */\n", $0
26 if ($3 ~ /i[24]/) {
27 printf "## int t_%s;\n", vname[count]
28 vtype[count]="int"
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;
35 vtype[count]="str"
36 } else if ($3 ~ /date/) {
37 printf "## char t_%s[26];\n", vname[count]
38 vtype[count]="str"
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
42 vtype[count]="str"
43 } else printf "Unknown data type %s\n", $3;
44 count++;
45}
46
47/^\($/ { print "##{" }
48/^\)$/ {
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]
54 }
55 printf ")\n"
56 printf "## {\n"
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]
60 }
61 printf "\t\tdump_nl(f);\n"
62 printf "## }\n"
63 printf "\tsafe_close(f);\n"
64 printf "##}\n"
65}
66END { print "/* All done */"
67 print "}" >>"bkup1.qc"
68}
This page took 0.072777 seconds and 5 git commands to generate.