annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/share/et/et_c.awk @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
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
jpayne@68 77 # We start playing *_high, *low games here because the some
jpayne@68 78 # awk programs do not have the necessary precision (sigh)
jpayne@68 79 tab_base_low = table_number % mod_base
jpayne@68 80 tab_base_high = int(table_number / mod_base)
jpayne@68 81 tab_base_sign = 1;
jpayne@68 82
jpayne@68 83 # figure out: table_number_base=table_number*256
jpayne@68 84 tab_base_low = tab_base_low * 256
jpayne@68 85 tab_base_high = (tab_base_high * 256) + \
jpayne@68 86 int(tab_base_low / mod_base)
jpayne@68 87 tab_base_low = tab_base_low % mod_base
jpayne@68 88
jpayne@68 89 if (table_number > 128*256*256) {
jpayne@68 90 # figure out: table_number_base -= 256*256*256*256
jpayne@68 91 # sub_high, sub_low is 256*256*256*256
jpayne@68 92 sub_low = 256*256*256 % mod_base
jpayne@68 93 sub_high = int(256*256*256 / mod_base)
jpayne@68 94
jpayne@68 95 sub_low = sub_low * 256
jpayne@68 96 sub_high = (sub_high * 256) + int(sub_low / mod_base)
jpayne@68 97 sub_low = sub_low % mod_base
jpayne@68 98
jpayne@68 99 tab_base_low = sub_low - tab_base_low;
jpayne@68 100 tab_base_high = sub_high - tab_base_high;
jpayne@68 101 tab_base_sign = -1;
jpayne@68 102 if (tab_base_low < 0) {
jpayne@68 103 tab_base_low = tab_base_low + mod_base
jpayne@68 104 tab_base_high--
jpayne@68 105 }
jpayne@68 106 }
jpayne@68 107 print "/*" > outfile
jpayne@68 108 print " * " outfile ":" > outfile
jpayne@68 109 print " * This file is automatically generated; please do not edit it." > outfile
jpayne@68 110 print " */" > outfile
jpayne@68 111
jpayne@68 112 print "#if defined(_WIN32)" > outfile
jpayne@68 113 print "# include \"win-mac.h\"" > outfile
jpayne@68 114 print "#endif" > outfile
jpayne@68 115 print "" > outfile
jpayne@68 116 print "#if !defined(_WIN32)" > outfile
jpayne@68 117 print "extern void initialize_" table_name "_error_table (void);" > outfile
jpayne@68 118 print "#endif" > outfile
jpayne@68 119 print "" > outfile
jpayne@68 120 print "#define N_(x) (x)" > outfile
jpayne@68 121 print "" > outfile
jpayne@68 122 print "/* Lclint doesn't handle null annotations on arrays" > outfile
jpayne@68 123 print " properly, so we need this typedef in each" > outfile
jpayne@68 124 print " generated .c file. */" > outfile
jpayne@68 125 print "/*@-redef@*/" > outfile
jpayne@68 126 print "typedef /*@null@*/ const char *ncptr;" > outfile
jpayne@68 127 print "/*@=redef@*/" > outfile
jpayne@68 128 print "" > outfile
jpayne@68 129 print "static ncptr const text[] = {" > outfile
jpayne@68 130 table_item_count = 0
jpayne@68 131 }
jpayne@68 132
jpayne@68 133 (continuation == 1) && ($0 ~ /\\[ \t]*$/) {
jpayne@68 134 text=substr($0,1,length($0)-1);
jpayne@68 135 # printf "\t\t\"%s\"\n", text > outfile
jpayne@68 136 cont_buf=cont_buf text;
jpayne@68 137 }
jpayne@68 138
jpayne@68 139 (continuation == 1) && ($0 ~ /"[ \t]*$/) {
jpayne@68 140 # printf "\t\t\"%s,\n", $0 > outfile
jpayne@68 141 printf "\tN_(%s),\n", cont_buf $0 > outfile
jpayne@68 142 continuation = 0;
jpayne@68 143 }
jpayne@68 144
jpayne@68 145 /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*$/ {
jpayne@68 146 table_item_count++
jpayne@68 147 skipone=1
jpayne@68 148 next
jpayne@68 149 }
jpayne@68 150
jpayne@68 151 /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*"[ \t]*$/ {
jpayne@68 152 text=""
jpayne@68 153 for (i=3; i<=NF; i++) {
jpayne@68 154 text = text FS $i
jpayne@68 155 }
jpayne@68 156 text=substr(text,2,length(text)-1);
jpayne@68 157 printf "\tN_(%s),\n", text > outfile
jpayne@68 158 table_item_count++
jpayne@68 159 }
jpayne@68 160
jpayne@68 161 /^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*\\[ \t]*$/ {
jpayne@68 162 text=""
jpayne@68 163 for (i=3; i<=NF; i++) {
jpayne@68 164 text = text FS $i
jpayne@68 165 }
jpayne@68 166 text=substr(text,2,length(text)-2);
jpayne@68 167 # printf "\t%s\"\n", text > outfile
jpayne@68 168 cont_buf=text
jpayne@68 169 continuation++;
jpayne@68 170 }
jpayne@68 171
jpayne@68 172 /^[ \t]*".*\\[ \t]*$/ {
jpayne@68 173 if (skipone) {
jpayne@68 174 text=substr($0,1,length($0)-1);
jpayne@68 175 # printf "\t%s\"\n", text > outfile
jpayne@68 176 cont_buf=text
jpayne@68 177 continuation++;
jpayne@68 178 }
jpayne@68 179 skipone=0
jpayne@68 180 }
jpayne@68 181
jpayne@68 182 {
jpayne@68 183 if (skipone) {
jpayne@68 184 printf "\tN_(%s),\n", $0 > outfile
jpayne@68 185 }
jpayne@68 186 skipone=0
jpayne@68 187 }
jpayne@68 188 END {
jpayne@68 189 if (table_item_count > 256) {
jpayne@68 190 print "Error table too large!" | "cat 1>&2"
jpayne@68 191 exit 1
jpayne@68 192 }
jpayne@68 193 # Put text domain and/or localedir at the end of the list.
jpayne@68 194 if (textdomain) {
jpayne@68 195 printf " \"%s\", /* Text domain */\n", textdomain > outfile
jpayne@68 196 if (localedir) {
jpayne@68 197 printf " \"%s\", /* Locale dir */\n", localedir > outfile
jpayne@68 198 }
jpayne@68 199 }
jpayne@68 200 print " 0" > outfile
jpayne@68 201 print "};" > outfile
jpayne@68 202 print "" > outfile
jpayne@68 203 print "#include <com_err.h>" > outfile
jpayne@68 204 print "" > outfile
jpayne@68 205 if (tab_base_high == 0) {
jpayne@68 206 print "const struct error_table et_" table_name "_error_table = { text, " \
jpayne@68 207 sprintf("%dL, %d };", tab_base_sign*tab_base_low, \
jpayne@68 208 table_item_count) > outfile
jpayne@68 209 } else {
jpayne@68 210 print "const struct error_table et_" table_name "_error_table = { text, " \
jpayne@68 211 sprintf("%d%06dL, %d };", tab_base_sign*tab_base_high, \
jpayne@68 212 tab_base_low, table_item_count) > outfile
jpayne@68 213 }
jpayne@68 214 print "" > outfile
jpayne@68 215 print "#if !defined(_WIN32)" > outfile
jpayne@68 216 print "void initialize_" table_name "_error_table (void)" > outfile
jpayne@68 217 print " /*@modifies internalState@*/" > outfile
jpayne@68 218 print "{" > outfile
jpayne@68 219 print " (void) add_error_table (&et_" table_name "_error_table);" > outfile
jpayne@68 220 print "}" > outfile
jpayne@68 221 print "#endif" > outfile
jpayne@68 222 }