blob: 99c33baffd53af0806601d5ceccd9df5a6835e18 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001BEGIN {
Theodore Ts'o153b4492005-05-06 09:42:34 -04002if ( length(outfn) == 0) {
3 outfn = outfile
4}
Theodore Ts'o3839e651997-04-26 13:21:57 +00005char_shift=64
6## "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
7c2n["A"]=1
8c2n["B"]=2
9c2n["C"]=3
10c2n["D"]=4
11c2n["E"]=5
12c2n["F"]=6
13c2n["G"]=7
14c2n["H"]=8
15c2n["I"]=9
16c2n["J"]=10
17c2n["K"]=11
18c2n["L"]=12
19c2n["M"]=13
20c2n["N"]=14
21c2n["O"]=15
22c2n["P"]=16
23c2n["Q"]=17
24c2n["R"]=18
25c2n["S"]=19
26c2n["T"]=20
27c2n["U"]=21
28c2n["V"]=22
29c2n["W"]=23
30c2n["X"]=24
31c2n["Y"]=25
32c2n["Z"]=26
33c2n["a"]=27
34c2n["b"]=28
35c2n["c"]=29
36c2n["d"]=30
37c2n["e"]=31
38c2n["f"]=32
39c2n["g"]=33
40c2n["h"]=34
41c2n["i"]=35
42c2n["j"]=36
43c2n["k"]=37
44c2n["l"]=38
45c2n["m"]=39
46c2n["n"]=40
47c2n["o"]=41
48c2n["p"]=42
49c2n["q"]=43
50c2n["r"]=44
51c2n["s"]=45
52c2n["t"]=46
53c2n["u"]=47
54c2n["v"]=48
55c2n["w"]=49
56c2n["x"]=50
57c2n["y"]=51
58c2n["z"]=52
59c2n["0"]=53
60c2n["1"]=54
61c2n["2"]=55
62c2n["3"]=56
63c2n["4"]=57
64c2n["5"]=58
65c2n["6"]=59
66c2n["7"]=60
67c2n["8"]=61
68c2n["9"]=62
69c2n["_"]=63
70}
71/^#/ { next }
72/^[ \t]*(error_table|et)[ \t]+[a-zA-Z][a-zA-Z0-9_]+/ {
73 table_number = 0
Theodore Ts'o3839e651997-04-26 13:21:57 +000074 mod_base = 1000000
Theodore Ts'o44104b22003-08-01 08:59:40 -040075 if (NF > 2) {
76 table_name = $3
77 base_name = $2
78 } else {
79 table_name = $2
80 base_name = table_name
81 }
82 for(i=1; i<=length(base_name); i++) {
83 table_number=(table_number*char_shift)+c2n[substr(base_name,i,1)]
Theodore Ts'o3839e651997-04-26 13:21:57 +000084 }
85
86 # We start playing *_high, *low games here because the some
87 # awk programs do not have the necessary precision (sigh)
88 tab_base_low = table_number % mod_base
Theodore Ts'ob6627cd1998-06-27 05:23:55 +000089 if (tab_base_low < 0) {
90 # Work around stupid bug in the ARM libm
91 tab_base_low = tab_base_low + mod_base
92 }
Theodore Ts'o3839e651997-04-26 13:21:57 +000093 tab_base_high = int(table_number / mod_base)
94 tab_base_sign = 1;
95
96 # figure out: table_number_base=table_number*256
97 tab_base_low = tab_base_low * 256
98 tab_base_high = (tab_base_high * 256) + \
99 int(tab_base_low / mod_base)
100 tab_base_low = tab_base_low % mod_base
Theodore Ts'ob6627cd1998-06-27 05:23:55 +0000101 if (tab_base_low < 0) {
102 # Work around stupid bug in the ARM libm
103 tab_base_low = tab_base_low + mod_base
104 }
Theodore Ts'o3839e651997-04-26 13:21:57 +0000105
106 if (table_number > 128*256*256) {
107 # figure out: table_number_base -= 256*256*256*256
108 # sub_high, sub_low is 256*256*256*256
109 sub_low = 256*256*256 % mod_base
110 sub_high = int(256*256*256 / mod_base)
111
112 sub_low = sub_low * 256
113 sub_high = (sub_high * 256) + int(sub_low / mod_base)
114 sub_low = sub_low % mod_base
115
116 tab_base_low = sub_low - tab_base_low;
117 tab_base_high = sub_high - tab_base_high;
118 tab_base_sign = -1;
119 if (tab_base_low < 0) {
120 tab_base_low = tab_base_low + mod_base
121 tab_base_high--
122 }
123 }
124 print "/*" > outfile
Theodore Ts'o153b4492005-05-06 09:42:34 -0400125 print " * " outfn ":" > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000126 print " * This file is automatically generated; please do not edit it." > outfile
127 print " */" > outfile
128
Theodore Ts'o3839e651997-04-26 13:21:57 +0000129 print "" > outfile
Theodore Ts'od0355092003-05-05 23:07:32 -0400130 print "#include <stdlib.h>" > outfile
131 print "" > outfile
Theodore Ts'oda5a6b42011-10-05 00:39:40 -0400132 print "#define N_(a) a" > outfile
133 print "" > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000134 print "static const char * const text[] = {" > outfile
135 table_item_count = 0
136}
137
Theodore Ts'ob16fb622003-05-05 20:02:39 -0400138(continuation == 1) && ($0 ~ /\\[ \t]*$/) {
139 text=substr($0,1,length($0)-1);
140# printf "\t\t\"%s\"\n", text > outfile
141 cont_buf=cont_buf text;
142}
143
144(continuation == 1) && ($0 ~ /"[ \t]*$/) {
145# printf "\t\t\"%s,\n", $0 > outfile
Theodore Ts'oda5a6b42011-10-05 00:39:40 -0400146 printf "\tN_(%s),\n", cont_buf $0 > outfile
Theodore Ts'ob16fb622003-05-05 20:02:39 -0400147 continuation = 0;
148}
149
Theodore Ts'o44104b22003-08-01 08:59:40 -0400150/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[^ \t]/ {
151 # Be tolerant to missing whitespace after `,' ...
152 sub(/,/, ", ")
153}
154
Theodore Ts'o3839e651997-04-26 13:21:57 +0000155/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*$/ {
Theodore Ts'ob16fb622003-05-05 20:02:39 -0400156 table_item_count++
Theodore Ts'o3839e651997-04-26 13:21:57 +0000157 skipone=1
158 next
159}
160
161/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*"[ \t]*$/ {
162 text=""
163 for (i=3; i<=NF; i++) {
164 text = text FS $i
165 }
166 text=substr(text,2,length(text)-1);
Theodore Ts'oda5a6b42011-10-05 00:39:40 -0400167 printf "\tN_(%s),\n", text > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000168 table_item_count++
169}
170
Theodore Ts'ob16fb622003-05-05 20:02:39 -0400171/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*\\[ \t]*$/ {
172 text=""
173 for (i=3; i<=NF; i++) {
174 text = text FS $i
175 }
176 text=substr(text,2,length(text)-2);
177# printf "\t%s\"\n", text > outfile
178 cont_buf=text
Theodore Ts'o5bf9b4c2005-07-19 08:24:59 -0500179 table_item_count++
Theodore Ts'ob16fb622003-05-05 20:02:39 -0400180 continuation++;
181}
182
183/^[ \t]*".*\\[ \t]*$/ {
184 if (skipone) {
185 text=substr($0,1,length($0)-1);
186# printf "\t%s\"\n", text > outfile
187 cont_buf=text
188 continuation++;
189 }
190 skipone=0
191}
192
Theodore Ts'o3839e651997-04-26 13:21:57 +0000193{
194 if (skipone) {
Theodore Ts'oda5a6b42011-10-05 00:39:40 -0400195 printf "\tN_(%s),\n", $0 > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000196 }
197 skipone=0
198}
Theodore Ts'od0355092003-05-05 23:07:32 -0400199
Theodore Ts'o44104b22003-08-01 08:59:40 -0400200/^[ \t]*(prefix)$/ {
201 prefix_str = ""
202}
203
Theodore Ts'od0355092003-05-05 23:07:32 -0400204/^[ \t]*(prefix)[ \t]+[A-Z_0-9]+/ {
205 prefix_str = $2 "_"
206}
207
208/^[ \t]*(index)[ \t]+[A-Z_0-9]+/ {
209 new_idx = $2
210 for (i = table_item_count ; i < new_idx; i++) {
Theodore Ts'oda5a6b42011-10-05 00:39:40 -0400211 printf "\tN_(\"Reserved %s error (%d)\"),\n", \
Theodore Ts'od0355092003-05-05 23:07:32 -0400212 table_name, table_item_count++ > outfile
213 }
214}
215
Theodore Ts'o3839e651997-04-26 13:21:57 +0000216END {
Theodore Ts'o3839e651997-04-26 13:21:57 +0000217 print " 0" > outfile
218 print "};" > outfile
219 print "" > outfile
220 print "struct error_table {" > outfile
221 print " char const * const * msgs;" > outfile
222 print " long base;" > outfile
223 print " int n_msgs;" > outfile
224 print "};" > outfile
225 print "struct et_list {" > outfile
226 print " struct et_list *next;" > outfile
227 print " const struct error_table * table;" > outfile
228 print "};" > outfile
229 print "extern struct et_list *_et_list;" > outfile
230 print "" > outfile
231 if (tab_base_high == 0) {
Theodore Ts'o00aba962003-03-19 19:46:02 -0500232 print "const struct error_table et_" table_name "_error_table = { text, " \
Theodore Ts'o3839e651997-04-26 13:21:57 +0000233 sprintf("%dL, %d };", tab_base_sign*tab_base_low, \
234 table_item_count) > outfile
235 } else {
Theodore Ts'o00aba962003-03-19 19:46:02 -0500236 print "const struct error_table et_" table_name "_error_table = { text, " \
Theodore Ts'o3839e651997-04-26 13:21:57 +0000237 sprintf("%d%06dL, %d };", tab_base_sign*tab_base_high, \
238 tab_base_low, table_item_count) > outfile
239 }
240 print "" > outfile
241 print "static struct et_list link = { 0, 0 };" > outfile
242 print "" > outfile
Theodore Ts'oe7d32fc2005-06-20 16:24:04 -0400243 print "void initialize_" table_name "_error_table_r(struct et_list **list);" > outfile
Theodore Ts'o291c9041997-10-31 06:17:08 +0000244 print "void initialize_" table_name "_error_table(void);" > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000245 print "" > outfile
Theodore Ts'o291c9041997-10-31 06:17:08 +0000246 print "void initialize_" table_name "_error_table(void) {" > outfile
Theodore Ts'oe7d32fc2005-06-20 16:24:04 -0400247 print " initialize_" table_name "_error_table_r(&_et_list);" > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000248 print "}" > outfile
Theodore Ts'od0355092003-05-05 23:07:32 -0400249 print "" > outfile
Theodore Ts'o44104b22003-08-01 08:59:40 -0400250 print "/* For Heimdal compatibility */" > outfile
Theodore Ts'od0355092003-05-05 23:07:32 -0400251 print "void initialize_" table_name "_error_table_r(struct et_list **list)" > outfile
252 print "{" > outfile
253 print " struct et_list *et, **end;" > outfile
254 print "" > outfile
255 print " for (end = list, et = *list; et; end = &et->next, et = et->next)" > outfile
256 print " if (et->table->msgs == text)" > outfile
257 print " return;" > outfile
258 print " et = malloc(sizeof(struct et_list));" > outfile
Theodore Ts'oe7d32fc2005-06-20 16:24:04 -0400259 print " if (et == 0) {" > outfile
260 print " if (!link.table)" > outfile
261 print " et = &link;" > outfile
262 print " else" > outfile
263 print " return;" > outfile
264 print " }" > outfile
Theodore Ts'od0355092003-05-05 23:07:32 -0400265 print " et->table = &et_" table_name "_error_table;" > outfile
266 print " et->next = 0;" > outfile
267 print " *end = et;" > outfile
268 print "}" > outfile
Theodore Ts'o3839e651997-04-26 13:21:57 +0000269}