]>
Commit | Line | Data |
---|---|---|
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 | ||
9 | BEGIN { print "/* This file automatically generated */"; | |
10 | print "/* Do not edit */"; | |
11 | print "#include <stdio.h>"; | |
12 | print "EXEC SQL INCLUDE sqlca;"; | |
13 | print "#include \"dump_db.h\""; | |
14 | print; | |
15 | print "/* This file automatically generated */" > "bkup1.dc"; | |
16 | print "/* Do not edit */" >> "bkup1.dc" | |
17 | print "#include <stdio.h>" >> "bkup1.dc" | |
18 | print "FILE *open_file();" >> "bkup1.dc" | |
19 | print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.dc" | |
20 | } | |
21 | ||
22 | $1=="#" { next; } | |
23 | ||
24 | /^create/ { printf "dump_%s(f)\nFILE *f;\n{\n\tEXEC SQL BEGIN DECLARE SECTION;\n", $3; | |
25 | printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "bkup1.dc" | |
26 | tablename = $3; | |
27 | rangename = substr(tablename, 1, 1); | |
28 | count = 0; | |
29 | next;} | |
30 | ||
31 | NF>=2 { | |
32 | vname[count] = $1; | |
33 | printf "/* %s */\n", $0 | |
34 | if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) { | |
35 | printf "\tint\tt_%s;\n", vname[count] | |
36 | vtype[count]="int" | |
37 | } else if ($2 ~ /CHAR\([0-9]*\)/) { | |
38 | t = split($2, temp, "(") | |
39 | if (t != 2) printf "Can't parse %s\n", $2; | |
40 | t = split(temp[2], temp2, ")") | |
41 | if (t != 2) printf "Can't parse %s\n", temp[2]; | |
42 | printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1; | |
43 | if ($1 == "signature") { | |
44 | vtype[count]="bin" | |
45 | } else { | |
46 | vtype[count]="str" | |
47 | } | |
48 | } else if ($2 ~ /DATE/) { | |
49 | printf "\tchar\tt_%s[26];\n", vname[count] | |
50 | vtype[count]="str" | |
51 | } else printf "Unknown data type %s\n", $2; | |
52 | count++; | |
53 | } | |
54 | ||
55 | /^\);$/ { | |
56 | printf "\tEXEC SQL END DECLARE SECTION;\n"; | |
57 | printf "\tEXEC SQL DECLARE c_%s CURSOR FOR\n", tablename; | |
58 | printf "\t\tSELECT * FROM %s;\n", tablename; | |
59 | printf "\tEXEC SQL OPEN c_%s;\n", tablename; | |
60 | printf "\twhile(1) {\n\tEXEC SQL FETCH c_%s INTO\n", tablename; | |
61 | for (i = 0; i < count; i++) { | |
62 | if (i != 0) printf ",\n"; | |
63 | printf "\t\t:t_%s", vname[i]; | |
64 | } | |
65 | printf ";\n"; | |
66 | printf "\tif(sqlca.sqlcode != 0) break;\n"; | |
67 | for (i = 0; i < count; i++) { | |
68 | if (i != 0) print "\tdump_sep(f);" | |
69 | printf "\tdump_%s(f, t_%s);\n", vtype[i], vname[i]; | |
70 | } | |
71 | printf "\t\tdump_nl(f);\n"; | |
72 | printf "\t}\n"; | |
73 | printf "\tEXEC SQL CLOSE c_%s;\n", tablename; | |
74 | printf "\tsafe_close(f);\n"; | |
75 | printf "}\n"; | |
76 | } | |
77 | END { print "/* All done */" | |
78 | print "}" >>"bkup1.dc" | |
79 | } |