1BEGIN { 2char_shift=64 3## "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; 4c2n["A"]=1 5c2n["B"]=2 6c2n["C"]=3 7c2n["D"]=4 8c2n["E"]=5 9c2n["F"]=6 10c2n["G"]=7 11c2n["H"]=8 12c2n["I"]=9 13c2n["J"]=10 14c2n["K"]=11 15c2n["L"]=12 16c2n["M"]=13 17c2n["N"]=14 18c2n["O"]=15 19c2n["P"]=16 20c2n["Q"]=17 21c2n["R"]=18 22c2n["S"]=19 23c2n["T"]=20 24c2n["U"]=21 25c2n["V"]=22 26c2n["W"]=23 27c2n["X"]=24 28c2n["Y"]=25 29c2n["Z"]=26 30c2n["a"]=27 31c2n["b"]=28 32c2n["c"]=29 33c2n["d"]=30 34c2n["e"]=31 35c2n["f"]=32 36c2n["g"]=33 37c2n["h"]=34 38c2n["i"]=35 39c2n["j"]=36 40c2n["k"]=37 41c2n["l"]=38 42c2n["m"]=39 43c2n["n"]=40 44c2n["o"]=41 45c2n["p"]=42 46c2n["q"]=43 47c2n["r"]=44 48c2n["s"]=45 49c2n["t"]=46 50c2n["u"]=47 51c2n["v"]=48 52c2n["w"]=49 53c2n["x"]=50 54c2n["y"]=51 55c2n["z"]=52 56c2n["0"]=53 57c2n["1"]=54 58c2n["2"]=55 59c2n["3"]=56 60c2n["4"]=57 61c2n["5"]=58 62c2n["6"]=59 63c2n["7"]=60 64c2n["8"]=61 65c2n["9"]=62 66c2n["_"]=63 67} 68/^#/ { next } 69/^[ \t]*(error_table|et)[ \t]+[a-zA-Z][a-zA-Z0-9_]+/ { 70 table_number = 0 71 table_name = $2 72 mod_base = 1000000 73 for(i=1; i<=length(table_name); i++) { 74 table_number=(table_number*char_shift)+c2n[substr(table_name,i,1)] 75 } 76 77 # We start playing *_high, *low games here because the some 78 # awk programs do not have the necessary precision (sigh) 79 tab_base_low = table_number % mod_base 80 tab_base_high = int(table_number / mod_base) 81 tab_base_sign = 1; 82 83 # figure out: table_number_base=table_number*256 84 tab_base_low = tab_base_low * 256 85 tab_base_high = (tab_base_high * 256) + int(tab_base_low / mod_base) 86 tab_base_low = tab_base_low % mod_base 87 88 if (table_number > 128*256*256) { 89 # figure out: table_number_base -= 256*256*256*256 90 # sub_high, sub_low is 256*256*256*256 91 sub_low = 256*256*256 % mod_base 92 sub_high = int(256*256*256 / mod_base) 93 94 sub_low = sub_low * 256 95 sub_high = (sub_high * 256) + int(sub_low / mod_base) 96 sub_low = sub_low % mod_base 97 98 tab_base_low = sub_low - tab_base_low; 99 tab_base_high = sub_high - tab_base_high; 100 tab_base_sign = -1; 101 if (tab_base_low < 0) { 102 tab_base_low = tab_base_low + mod_base 103 tab_base_high-- 104 } 105 } 106 print "/*" > outfile 107 print " * " outfile ":" > outfile 108 print " * This file is automatically generated; please do not edit it." > outfile 109 print " */" > outfile 110 111 print "#if defined(_WIN32)" > outfile 112 print "# include \"win-mac.h\"" > outfile 113 print "#endif" > outfile 114 print "" > outfile 115 print "#if !defined(_WIN32)" > outfile 116 print "extern void initialize_" table_name "_error_table (void);" > outfile 117 print "#endif" > outfile 118 print "" > outfile 119 print "#define N_(x) (x)" > outfile 120 print "" > outfile 121 print "/* Lclint doesn't handle null annotations on arrays" > outfile 122 print " properly, so we need this typedef in each" > outfile 123 print " generated .c file. */" > outfile 124 print "/*@-redef@*/" > outfile 125 print "typedef /*@null@*/ const char *ncptr;" > outfile 126 print "/*@=redef@*/" > outfile 127 print "" > outfile 128 print "static ncptr const text[] = {" > outfile 129 table_item_count = 0 130} 131 132(continuation == 1) && ($0 ~ /\\[ \t]*$/) { 133 text=substr($0,1,length($0)-1); 134# printf "\t\t\"%s\"\n", text > outfile 135 cont_buf=cont_buf text; 136} 137 138(continuation == 1) && ($0 ~ /"[ \t]*$/) { 139# printf "\t\t\"%s,\n", $0 > outfile 140 printf "\tN_(%s),\n", cont_buf $0 > outfile 141 continuation = 0; 142} 143 144/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*$/ { 145 table_item_count++ 146 skipone=1 147 next 148} 149 150/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*"[ \t]*$/ { 151 text="" 152 for (i=3; i<=NF; i++) { 153 text = text FS $i 154 } 155 text=substr(text,2,length(text)-1); 156 printf "\tN_(%s),\n", text > outfile 157 table_item_count++ 158} 159 160/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*\\[ \t]*$/ { 161 text="" 162 for (i=3; i<=NF; i++) { 163 text = text FS $i 164 } 165 text=substr(text,2,length(text)-2); 166# printf "\t%s\"\n", text > outfile 167 cont_buf=text 168 continuation++; 169} 170 171/^[ \t]*".*\\[ \t]*$/ { 172 if (skipone) { 173 text=substr($0,1,length($0)-1); 174# printf "\t%s\"\n", text > outfile 175 cont_buf=text 176 continuation++; 177 } 178 skipone=0 179} 180 181{ 182 if (skipone) { 183 printf "\tN_(%s),\n", $0 > outfile 184 } 185 skipone=0 186} 187END { 188 if (table_item_count > 256) { 189 print "Error table too large!" | "cat 1>&2" 190 exit 1 191 } 192 # Put text domain and/or localedir at the end of the list. 193 if (textdomain) { 194 printf " \"%s\", /* Text domain */\n", textdomain > outfile 195 if (localedir) { 196 printf " \"%s\", /* Locale dir */\n", localedir > outfile 197 } 198 } 199 print " 0" > outfile 200 print "};" > outfile 201 print "" > outfile 202 print "#include <com_err.h>" > outfile 203 print "" > outfile 204 if (tab_base_high == 0) { 205 base = sprintf("%dL", tab_base_sign * tab_base_low) 206 } else { 207 base = sprintf("%d%06dL", tab_base_sign * tab_base_high, tab_base_low) 208 } 209 ints = sprintf("%s, %d", base, table_item_count) 210 print "const struct error_table et_" table_name "_error_table = { text, " ints " };" > outfile 211 print "" > outfile 212 print "#if !defined(_WIN32)" > outfile 213 print "void initialize_" table_name "_error_table (void)" > outfile 214 print " /*@modifies internalState@*/" > outfile 215 print "{" > outfile 216 print " (void) add_error_table (&et_" table_name "_error_table);" > outfile 217 print "}" > outfile 218 print "#endif" > outfile 219} 220