jpayne@68: BEGIN { jpayne@68: char_shift=64 jpayne@68: ## "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; jpayne@68: c2n["A"]=1 jpayne@68: c2n["B"]=2 jpayne@68: c2n["C"]=3 jpayne@68: c2n["D"]=4 jpayne@68: c2n["E"]=5 jpayne@68: c2n["F"]=6 jpayne@68: c2n["G"]=7 jpayne@68: c2n["H"]=8 jpayne@68: c2n["I"]=9 jpayne@68: c2n["J"]=10 jpayne@68: c2n["K"]=11 jpayne@68: c2n["L"]=12 jpayne@68: c2n["M"]=13 jpayne@68: c2n["N"]=14 jpayne@68: c2n["O"]=15 jpayne@68: c2n["P"]=16 jpayne@68: c2n["Q"]=17 jpayne@68: c2n["R"]=18 jpayne@68: c2n["S"]=19 jpayne@68: c2n["T"]=20 jpayne@68: c2n["U"]=21 jpayne@68: c2n["V"]=22 jpayne@68: c2n["W"]=23 jpayne@68: c2n["X"]=24 jpayne@68: c2n["Y"]=25 jpayne@68: c2n["Z"]=26 jpayne@68: c2n["a"]=27 jpayne@68: c2n["b"]=28 jpayne@68: c2n["c"]=29 jpayne@68: c2n["d"]=30 jpayne@68: c2n["e"]=31 jpayne@68: c2n["f"]=32 jpayne@68: c2n["g"]=33 jpayne@68: c2n["h"]=34 jpayne@68: c2n["i"]=35 jpayne@68: c2n["j"]=36 jpayne@68: c2n["k"]=37 jpayne@68: c2n["l"]=38 jpayne@68: c2n["m"]=39 jpayne@68: c2n["n"]=40 jpayne@68: c2n["o"]=41 jpayne@68: c2n["p"]=42 jpayne@68: c2n["q"]=43 jpayne@68: c2n["r"]=44 jpayne@68: c2n["s"]=45 jpayne@68: c2n["t"]=46 jpayne@68: c2n["u"]=47 jpayne@68: c2n["v"]=48 jpayne@68: c2n["w"]=49 jpayne@68: c2n["x"]=50 jpayne@68: c2n["y"]=51 jpayne@68: c2n["z"]=52 jpayne@68: c2n["0"]=53 jpayne@68: c2n["1"]=54 jpayne@68: c2n["2"]=55 jpayne@68: c2n["3"]=56 jpayne@68: c2n["4"]=57 jpayne@68: c2n["5"]=58 jpayne@68: c2n["6"]=59 jpayne@68: c2n["7"]=60 jpayne@68: c2n["8"]=61 jpayne@68: c2n["9"]=62 jpayne@68: c2n["_"]=63 jpayne@68: } jpayne@68: /^#/ { next } jpayne@68: /^[ \t]*(error_table|et)[ \t]+[a-zA-Z][a-zA-Z0-9_]+/ { jpayne@68: table_number = 0 jpayne@68: table_name = $2 jpayne@68: mod_base = 1000000 jpayne@68: for(i=1; i<=length(table_name); i++) { jpayne@68: table_number=(table_number*char_shift)+c2n[substr(table_name,i,1)] jpayne@68: } jpayne@68: jpayne@68: # We start playing *_high, *low games here because the some jpayne@68: # awk programs do not have the necessary precision (sigh) jpayne@68: tab_base_low = table_number % mod_base jpayne@68: tab_base_high = int(table_number / mod_base) jpayne@68: tab_base_sign = 1; jpayne@68: jpayne@68: # figure out: table_number_base=table_number*256 jpayne@68: tab_base_low = tab_base_low * 256 jpayne@68: tab_base_high = (tab_base_high * 256) + \ jpayne@68: int(tab_base_low / mod_base) jpayne@68: tab_base_low = tab_base_low % mod_base jpayne@68: jpayne@68: if (table_number > 128*256*256) { jpayne@68: # figure out: table_number_base -= 256*256*256*256 jpayne@68: # sub_high, sub_low is 256*256*256*256 jpayne@68: sub_low = 256*256*256 % mod_base jpayne@68: sub_high = int(256*256*256 / mod_base) jpayne@68: jpayne@68: sub_low = sub_low * 256 jpayne@68: sub_high = (sub_high * 256) + int(sub_low / mod_base) jpayne@68: sub_low = sub_low % mod_base jpayne@68: jpayne@68: tab_base_low = sub_low - tab_base_low; jpayne@68: tab_base_high = sub_high - tab_base_high; jpayne@68: tab_base_sign = -1; jpayne@68: if (tab_base_low < 0) { jpayne@68: tab_base_low = tab_base_low + mod_base jpayne@68: tab_base_high-- jpayne@68: } jpayne@68: } jpayne@68: print "/*" > outfile jpayne@68: print " * " outfile ":" > outfile jpayne@68: print " * This file is automatically generated; please do not edit it." > outfile jpayne@68: print " */" > outfile jpayne@68: jpayne@68: print "#if defined(_WIN32)" > outfile jpayne@68: print "# include \"win-mac.h\"" > outfile jpayne@68: print "#endif" > outfile jpayne@68: print "" > outfile jpayne@68: print "#if !defined(_WIN32)" > outfile jpayne@68: print "extern void initialize_" table_name "_error_table (void);" > outfile jpayne@68: print "#endif" > outfile jpayne@68: print "" > outfile jpayne@68: print "#define N_(x) (x)" > outfile jpayne@68: print "" > outfile jpayne@68: print "/* Lclint doesn't handle null annotations on arrays" > outfile jpayne@68: print " properly, so we need this typedef in each" > outfile jpayne@68: print " generated .c file. */" > outfile jpayne@68: print "/*@-redef@*/" > outfile jpayne@68: print "typedef /*@null@*/ const char *ncptr;" > outfile jpayne@68: print "/*@=redef@*/" > outfile jpayne@68: print "" > outfile jpayne@68: print "static ncptr const text[] = {" > outfile jpayne@68: table_item_count = 0 jpayne@68: } jpayne@68: jpayne@68: (continuation == 1) && ($0 ~ /\\[ \t]*$/) { jpayne@68: text=substr($0,1,length($0)-1); jpayne@68: # printf "\t\t\"%s\"\n", text > outfile jpayne@68: cont_buf=cont_buf text; jpayne@68: } jpayne@68: jpayne@68: (continuation == 1) && ($0 ~ /"[ \t]*$/) { jpayne@68: # printf "\t\t\"%s,\n", $0 > outfile jpayne@68: printf "\tN_(%s),\n", cont_buf $0 > outfile jpayne@68: continuation = 0; jpayne@68: } jpayne@68: jpayne@68: /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*$/ { jpayne@68: table_item_count++ jpayne@68: skipone=1 jpayne@68: next jpayne@68: } jpayne@68: jpayne@68: /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*"[ \t]*$/ { jpayne@68: text="" jpayne@68: for (i=3; i<=NF; i++) { jpayne@68: text = text FS $i jpayne@68: } jpayne@68: text=substr(text,2,length(text)-1); jpayne@68: printf "\tN_(%s),\n", text > outfile jpayne@68: table_item_count++ jpayne@68: } jpayne@68: jpayne@68: /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*\\[ \t]*$/ { jpayne@68: text="" jpayne@68: for (i=3; i<=NF; i++) { jpayne@68: text = text FS $i jpayne@68: } jpayne@68: text=substr(text,2,length(text)-2); jpayne@68: # printf "\t%s\"\n", text > outfile jpayne@68: cont_buf=text jpayne@68: continuation++; jpayne@68: } jpayne@68: jpayne@68: /^[ \t]*".*\\[ \t]*$/ { jpayne@68: if (skipone) { jpayne@68: text=substr($0,1,length($0)-1); jpayne@68: # printf "\t%s\"\n", text > outfile jpayne@68: cont_buf=text jpayne@68: continuation++; jpayne@68: } jpayne@68: skipone=0 jpayne@68: } jpayne@68: jpayne@68: { jpayne@68: if (skipone) { jpayne@68: printf "\tN_(%s),\n", $0 > outfile jpayne@68: } jpayne@68: skipone=0 jpayne@68: } jpayne@68: END { jpayne@68: if (table_item_count > 256) { jpayne@68: print "Error table too large!" | "cat 1>&2" jpayne@68: exit 1 jpayne@68: } jpayne@68: # Put text domain and/or localedir at the end of the list. jpayne@68: if (textdomain) { jpayne@68: printf " \"%s\", /* Text domain */\n", textdomain > outfile jpayne@68: if (localedir) { jpayne@68: printf " \"%s\", /* Locale dir */\n", localedir > outfile jpayne@68: } jpayne@68: } jpayne@68: print " 0" > outfile jpayne@68: print "};" > outfile jpayne@68: print "" > outfile jpayne@68: print "#include " > outfile jpayne@68: print "" > outfile jpayne@68: if (tab_base_high == 0) { jpayne@68: print "const struct error_table et_" table_name "_error_table = { text, " \ jpayne@68: sprintf("%dL, %d };", tab_base_sign*tab_base_low, \ jpayne@68: table_item_count) > outfile jpayne@68: } else { jpayne@68: print "const struct error_table et_" table_name "_error_table = { text, " \ jpayne@68: sprintf("%d%06dL, %d };", tab_base_sign*tab_base_high, \ jpayne@68: tab_base_low, table_item_count) > outfile jpayne@68: } jpayne@68: print "" > outfile jpayne@68: print "#if !defined(_WIN32)" > outfile jpayne@68: print "void initialize_" table_name "_error_table (void)" > outfile jpayne@68: print " /*@modifies internalState@*/" > outfile jpayne@68: print "{" > outfile jpayne@68: print " (void) add_error_table (&et_" table_name "_error_table);" > outfile jpayne@68: print "}" > outfile jpayne@68: print "#endif" > outfile jpayne@68: }