jpayne@68
|
1 BEGIN {
|
jpayne@68
|
2 char_shift=64
|
jpayne@68
|
3 ## "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
jpayne@68
|
4 c2n["A"]=1
|
jpayne@68
|
5 c2n["B"]=2
|
jpayne@68
|
6 c2n["C"]=3
|
jpayne@68
|
7 c2n["D"]=4
|
jpayne@68
|
8 c2n["E"]=5
|
jpayne@68
|
9 c2n["F"]=6
|
jpayne@68
|
10 c2n["G"]=7
|
jpayne@68
|
11 c2n["H"]=8
|
jpayne@68
|
12 c2n["I"]=9
|
jpayne@68
|
13 c2n["J"]=10
|
jpayne@68
|
14 c2n["K"]=11
|
jpayne@68
|
15 c2n["L"]=12
|
jpayne@68
|
16 c2n["M"]=13
|
jpayne@68
|
17 c2n["N"]=14
|
jpayne@68
|
18 c2n["O"]=15
|
jpayne@68
|
19 c2n["P"]=16
|
jpayne@68
|
20 c2n["Q"]=17
|
jpayne@68
|
21 c2n["R"]=18
|
jpayne@68
|
22 c2n["S"]=19
|
jpayne@68
|
23 c2n["T"]=20
|
jpayne@68
|
24 c2n["U"]=21
|
jpayne@68
|
25 c2n["V"]=22
|
jpayne@68
|
26 c2n["W"]=23
|
jpayne@68
|
27 c2n["X"]=24
|
jpayne@68
|
28 c2n["Y"]=25
|
jpayne@68
|
29 c2n["Z"]=26
|
jpayne@68
|
30 c2n["a"]=27
|
jpayne@68
|
31 c2n["b"]=28
|
jpayne@68
|
32 c2n["c"]=29
|
jpayne@68
|
33 c2n["d"]=30
|
jpayne@68
|
34 c2n["e"]=31
|
jpayne@68
|
35 c2n["f"]=32
|
jpayne@68
|
36 c2n["g"]=33
|
jpayne@68
|
37 c2n["h"]=34
|
jpayne@68
|
38 c2n["i"]=35
|
jpayne@68
|
39 c2n["j"]=36
|
jpayne@68
|
40 c2n["k"]=37
|
jpayne@68
|
41 c2n["l"]=38
|
jpayne@68
|
42 c2n["m"]=39
|
jpayne@68
|
43 c2n["n"]=40
|
jpayne@68
|
44 c2n["o"]=41
|
jpayne@68
|
45 c2n["p"]=42
|
jpayne@68
|
46 c2n["q"]=43
|
jpayne@68
|
47 c2n["r"]=44
|
jpayne@68
|
48 c2n["s"]=45
|
jpayne@68
|
49 c2n["t"]=46
|
jpayne@68
|
50 c2n["u"]=47
|
jpayne@68
|
51 c2n["v"]=48
|
jpayne@68
|
52 c2n["w"]=49
|
jpayne@68
|
53 c2n["x"]=50
|
jpayne@68
|
54 c2n["y"]=51
|
jpayne@68
|
55 c2n["z"]=52
|
jpayne@68
|
56 c2n["0"]=53
|
jpayne@68
|
57 c2n["1"]=54
|
jpayne@68
|
58 c2n["2"]=55
|
jpayne@68
|
59 c2n["3"]=56
|
jpayne@68
|
60 c2n["4"]=57
|
jpayne@68
|
61 c2n["5"]=58
|
jpayne@68
|
62 c2n["6"]=59
|
jpayne@68
|
63 c2n["7"]=60
|
jpayne@68
|
64 c2n["8"]=61
|
jpayne@68
|
65 c2n["9"]=62
|
jpayne@68
|
66 c2n["_"]=63
|
jpayne@68
|
67 }
|
jpayne@68
|
68 /^#/ { next }
|
jpayne@68
|
69 /^[ \t]*(error_table|et)[ \t]+[a-zA-Z][a-zA-Z0-9_]+/ {
|
jpayne@68
|
70 table_number = 0
|
jpayne@68
|
71 table_name = $2
|
jpayne@68
|
72 mod_base = 1000000
|
jpayne@68
|
73 for(i=1; i<=length(table_name); i++) {
|
jpayne@68
|
74 table_number=(table_number*char_shift)+c2n[substr(table_name,i,1)]
|
jpayne@68
|
75 }
|
jpayne@68
|
76 # We start playing *_high, *low games here because the some
|
jpayne@68
|
77 # awk programs do not have the necessary precision (sigh)
|
jpayne@68
|
78 tab_base_low = table_number % mod_base
|
jpayne@68
|
79 tab_base_high = int(table_number / mod_base)
|
jpayne@68
|
80 tab_base_sign = 1;
|
jpayne@68
|
81
|
jpayne@68
|
82 # figure out: table_number_base=table_number*256
|
jpayne@68
|
83 tab_base_low = tab_base_low * 256
|
jpayne@68
|
84 tab_base_high = (tab_base_high * 256) + \
|
jpayne@68
|
85 int(tab_base_low / mod_base)
|
jpayne@68
|
86 tab_base_low = tab_base_low % mod_base
|
jpayne@68
|
87
|
jpayne@68
|
88 if (table_number > 128*256*256) {
|
jpayne@68
|
89 # figure out: table_number_base -= 256*256*256*256
|
jpayne@68
|
90 # sub_high, sub_low is 256*256*256*256
|
jpayne@68
|
91 sub_low = 256*256*256 % mod_base
|
jpayne@68
|
92 sub_high = int(256*256*256 / mod_base)
|
jpayne@68
|
93
|
jpayne@68
|
94 sub_low = sub_low * 256
|
jpayne@68
|
95 sub_high = (sub_high * 256) + int(sub_low / mod_base)
|
jpayne@68
|
96 sub_low = sub_low % mod_base
|
jpayne@68
|
97
|
jpayne@68
|
98 tab_base_low = sub_low - tab_base_low;
|
jpayne@68
|
99 tab_base_high = sub_high - tab_base_high;
|
jpayne@68
|
100 tab_base_sign = -1;
|
jpayne@68
|
101 if (tab_base_low < 0) {
|
jpayne@68
|
102 tab_base_low = tab_base_low + mod_base
|
jpayne@68
|
103 tab_base_high--
|
jpayne@68
|
104 }
|
jpayne@68
|
105 }
|
jpayne@68
|
106 curr_low = tab_base_low
|
jpayne@68
|
107 curr_high = tab_base_high
|
jpayne@68
|
108 curr_sign = tab_base_sign
|
jpayne@68
|
109 print "/*" > outfile
|
jpayne@68
|
110 print " * " outfile ":" > outfile
|
jpayne@68
|
111 print " * This file is automatically generated; please do not edit it." > outfile
|
jpayne@68
|
112 print " */" > outfile
|
jpayne@68
|
113 print "" > outfile
|
jpayne@68
|
114 print "#include <com_err.h>" > outfile
|
jpayne@68
|
115 print "" > outfile
|
jpayne@68
|
116 table_item_count = 0
|
jpayne@68
|
117 }
|
jpayne@68
|
118
|
jpayne@68
|
119 /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,/ {
|
jpayne@68
|
120 tag=substr($2,1,length($2)-1)
|
jpayne@68
|
121 if (curr_high == 0) {
|
jpayne@68
|
122 printf "#define %-40s (%dL)\n", tag, \
|
jpayne@68
|
123 curr_sign*curr_low > outfile
|
jpayne@68
|
124 } else {
|
jpayne@68
|
125 printf "#define %-40s (%d%06dL)\n", tag, curr_high*curr_sign, \
|
jpayne@68
|
126 curr_low > outfile
|
jpayne@68
|
127 }
|
jpayne@68
|
128 curr_low += curr_sign;
|
jpayne@68
|
129 if (curr_low >= mod_base) {
|
jpayne@68
|
130 curr_low -= mod_base;
|
jpayne@68
|
131 curr_high++
|
jpayne@68
|
132 }
|
jpayne@68
|
133 if (curr_low < 0) {
|
jpayne@68
|
134 cur_low += mod_base
|
jpayne@68
|
135 cur_high--
|
jpayne@68
|
136 }
|
jpayne@68
|
137 }
|
jpayne@68
|
138
|
jpayne@68
|
139 END {
|
jpayne@68
|
140 if (table_item_count > 256) {
|
jpayne@68
|
141 print "Error table too large!" | "cat 1>&2"
|
jpayne@68
|
142 exit 1
|
jpayne@68
|
143 }
|
jpayne@68
|
144 if (tab_base_high == 0) {
|
jpayne@68
|
145 print "#define ERROR_TABLE_BASE_" table_name " (" \
|
jpayne@68
|
146 sprintf("%d", tab_base_sign*tab_base_low) \
|
jpayne@68
|
147 "L)" > outfile
|
jpayne@68
|
148 } else {
|
jpayne@68
|
149 print "#define ERROR_TABLE_BASE_" table_name " (" \
|
jpayne@68
|
150 sprintf("%d%06d", tab_base_sign*tab_base_high, \
|
jpayne@68
|
151 tab_base_low) "L)" > outfile
|
jpayne@68
|
152 }
|
jpayne@68
|
153 print "" > outfile
|
jpayne@68
|
154 print "extern const struct error_table et_" table_name "_error_table;" > outfile
|
jpayne@68
|
155 print "" > outfile
|
jpayne@68
|
156 print "#if !defined(_WIN32)" > outfile
|
jpayne@68
|
157 print "/* for compatibility with older versions... */" > outfile
|
jpayne@68
|
158 print "extern void initialize_" table_name "_error_table (void) /*@modifies internalState@*/;" > outfile
|
jpayne@68
|
159 print "#else" > outfile
|
jpayne@68
|
160 print "#define initialize_" table_name "_error_table()" > outfile
|
jpayne@68
|
161 print "#endif" > outfile
|
jpayne@68
|
162 print "" > outfile
|
jpayne@68
|
163 print "#if !defined(_WIN32)" > outfile
|
jpayne@68
|
164 print "#define init_" table_name "_err_tbl initialize_" table_name "_error_table" > outfile
|
jpayne@68
|
165 print "#define " table_name "_err_base ERROR_TABLE_BASE_" table_name > outfile
|
jpayne@68
|
166 print "#endif" > outfile
|
jpayne@68
|
167 }
|
jpayne@68
|
168
|