summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGravatar Craig Fields <cfields@mit.edu>1994-10-08 01:31:05 +0000
committerGravatar Craig Fields <cfields@mit.edu>1994-10-08 01:31:05 +0000
commit08be7e2f80ccdfff742ce30c924c71ddc9ed8702 (patch)
treed8581f662cfbad4b241d3ecffc0ffdfcbfc428e5 /util
parent5178e0e7099df426b5b939b9501bece9a56492a0 (diff)
Initial revision
Diffstat (limited to 'util')
-rw-r--r--util/et/et_c.awk183
-rw-r--r--util/et/et_h.awk150
-rw-r--r--util/ss/ct_c.awk77
-rw-r--r--util/ss/ct_c.sed161
4 files changed, 571 insertions, 0 deletions
diff --git a/util/et/et_c.awk b/util/et/et_c.awk
new file mode 100644
index 0000000..4f53fc3
--- /dev/null
+++ b/util/et/et_c.awk
@@ -0,0 +1,183 @@
+BEGIN {
+char_shift=64
+## "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
+c2n["A"]=1
+c2n["B"]=2
+c2n["C"]=3
+c2n["D"]=4
+c2n["E"]=5
+c2n["F"]=6
+c2n["G"]=7
+c2n["H"]=8
+c2n["I"]=9
+c2n["J"]=10
+c2n["K"]=11
+c2n["L"]=12
+c2n["M"]=13
+c2n["N"]=14
+c2n["O"]=15
+c2n["P"]=16
+c2n["Q"]=17
+c2n["R"]=18
+c2n["S"]=19
+c2n["T"]=20
+c2n["U"]=21
+c2n["V"]=22
+c2n["W"]=23
+c2n["X"]=24
+c2n["Y"]=25
+c2n["Z"]=26
+c2n["a"]=27
+c2n["b"]=28
+c2n["c"]=29
+c2n["d"]=30
+c2n["e"]=31
+c2n["f"]=32
+c2n["g"]=33
+c2n["h"]=34
+c2n["i"]=35
+c2n["j"]=36
+c2n["k"]=37
+c2n["l"]=38
+c2n["m"]=39
+c2n["n"]=40
+c2n["o"]=41
+c2n["p"]=42
+c2n["q"]=43
+c2n["r"]=44
+c2n["s"]=45
+c2n["t"]=46
+c2n["u"]=47
+c2n["v"]=48
+c2n["w"]=49
+c2n["x"]=50
+c2n["y"]=51
+c2n["z"]=52
+c2n["0"]=53
+c2n["1"]=54
+c2n["2"]=55
+c2n["3"]=56
+c2n["4"]=57
+c2n["5"]=58
+c2n["6"]=59
+c2n["7"]=60
+c2n["8"]=61
+c2n["9"]=62
+c2n["_"]=63
+}
+/^#/ { next }
+/^[ \t]*(error_table|et)[ \t]+[a-zA-Z][a-zA-Z0-9_]+/ {
+ table_number = 0
+ table_name = $2
+ mod_base = 1000000
+ for(i=1; i<=length(table_name); i++) {
+ table_number=(table_number*char_shift)+c2n[substr(table_name,i,1)]
+ }
+
+ # We start playing *_high, *low games here because the some
+ # awk programs do not have the necessary precision (sigh)
+ tab_base_low = table_number % mod_base
+ tab_base_high = int(table_number / mod_base)
+ tab_base_sign = 1;
+
+ # figure out: table_number_base=table_number*256
+ tab_base_low = tab_base_low * 256
+ tab_base_high = (tab_base_high * 256) + \
+ int(tab_base_low / mod_base)
+ tab_base_low = tab_base_low % mod_base
+
+ if (table_number > 128*256*256) {
+ # figure out: table_number_base -= 256*256*256*256
+ # sub_high, sub_low is 256*256*256*256
+ sub_low = 256*256*256 % mod_base
+ sub_high = int(256*256*256 / mod_base)
+
+ sub_low = sub_low * 256
+ sub_high = (sub_high * 256) + int(sub_low / mod_base)
+ sub_low = sub_low % mod_base
+
+ tab_base_low = sub_low - tab_base_low;
+ tab_base_high = sub_high - tab_base_high;
+ tab_base_sign = -1;
+ if (tab_base_low < 0) {
+ tab_base_low = tab_base_low + mod_base
+ tab_base_high--
+ }
+ }
+ print "/*" > outfile
+ print " * " outfile ":" > outfile
+ print " * This file is automatically generated; please do not edit it." > outfile
+ print " */" > outfile
+
+ print "#ifdef __STDC__" > outfile
+ print "#define NOARGS void" > outfile
+ print "#else" > outfile
+ print "#define NOARGS" > outfile
+ print "#define const" > outfile
+ print "#endif" > outfile
+ print "" > outfile
+ print "static const char * const text[] = {" > outfile
+ table_item_count = 0
+}
+
+/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*$/ {
+ skipone=1
+ next
+}
+
+/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,[ \t]*".*"[ \t]*$/ {
+ text=""
+ for (i=3; i<=NF; i++) {
+ text = text FS $i
+ }
+ text=substr(text,2,length(text)-1);
+ printf "\t%s,\n", text > outfile
+ table_item_count++
+}
+
+{
+ if (skipone) {
+ printf "\t%s,\n", $0 > outfile
+ table_item_count++
+ }
+ skipone=0
+}
+END {
+
+
+ print " 0" > outfile
+ print "};" > outfile
+ print "" > outfile
+ print "struct error_table {" > outfile
+ print " char const * const * msgs;" > outfile
+ print " long base;" > outfile
+ print " int n_msgs;" > outfile
+ print "};" > outfile
+ print "struct et_list {" > outfile
+ print " struct et_list *next;" > outfile
+ print " const struct error_table * table;" > outfile
+ print "};" > outfile
+ print "extern struct et_list *_et_list;" > outfile
+ print "" > outfile
+ if (tab_base_high == 0) {
+ print "static const struct error_table et = { text, " \
+ sprintf("%dL, %d };", tab_base_sign*tab_base_low, \
+ table_item_count) > outfile
+ } else {
+ print "static const struct error_table et = { text, " \
+ sprintf("%d%06dL, %d };", tab_base_sign*tab_base_high, \
+ tab_base_low, table_item_count) > outfile
+ }
+ print "" > outfile
+ print "static struct et_list link = { 0, 0 };" > outfile
+ print "" > outfile
+ print "void initialize_" table_name "_error_table (NOARGS) {" > outfile
+ print " if (!link.table) {" > outfile
+ print " link.next = _et_list;" > outfile
+ print " link.table = &et;" > outfile
+ print " _et_list = &link;" > outfile
+ print " }" > outfile
+ print "}" > outfile
+
+
+}
diff --git a/util/et/et_h.awk b/util/et/et_h.awk
new file mode 100644
index 0000000..5851dd8
--- /dev/null
+++ b/util/et/et_h.awk
@@ -0,0 +1,150 @@
+BEGIN {
+char_shift=64
+## "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
+c2n["A"]=1
+c2n["B"]=2
+c2n["C"]=3
+c2n["D"]=4
+c2n["E"]=5
+c2n["F"]=6
+c2n["G"]=7
+c2n["H"]=8
+c2n["I"]=9
+c2n["J"]=10
+c2n["K"]=11
+c2n["L"]=12
+c2n["M"]=13
+c2n["N"]=14
+c2n["O"]=15
+c2n["P"]=16
+c2n["Q"]=17
+c2n["R"]=18
+c2n["S"]=19
+c2n["T"]=20
+c2n["U"]=21
+c2n["V"]=22
+c2n["W"]=23
+c2n["X"]=24
+c2n["Y"]=25
+c2n["Z"]=26
+c2n["a"]=27
+c2n["b"]=28
+c2n["c"]=29
+c2n["d"]=30
+c2n["e"]=31
+c2n["f"]=32
+c2n["g"]=33
+c2n["h"]=34
+c2n["i"]=35
+c2n["j"]=36
+c2n["k"]=37
+c2n["l"]=38
+c2n["m"]=39
+c2n["n"]=40
+c2n["o"]=41
+c2n["p"]=42
+c2n["q"]=43
+c2n["r"]=44
+c2n["s"]=45
+c2n["t"]=46
+c2n["u"]=47
+c2n["v"]=48
+c2n["w"]=49
+c2n["x"]=50
+c2n["y"]=51
+c2n["z"]=52
+c2n["0"]=53
+c2n["1"]=54
+c2n["2"]=55
+c2n["3"]=56
+c2n["4"]=57
+c2n["5"]=58
+c2n["6"]=59
+c2n["7"]=60
+c2n["8"]=61
+c2n["9"]=62
+c2n["_"]=63
+}
+/^#/ { next }
+/^[ \t]*(error_table|et)[ \t]+[a-zA-Z][a-zA-Z0-9_]+/ {
+ table_number = 0
+ table_name = $2
+ mod_base = 1000000
+ for(i=1; i<=length(table_name); i++) {
+ table_number=(table_number*char_shift)+c2n[substr(table_name,i,1)]
+ }
+ # We start playing *_high, *low games here because the some
+ # awk programs do not have the necessary precision (sigh)
+ tab_base_low = table_number % mod_base
+ tab_base_high = int(table_number / mod_base)
+ tab_base_sign = 1;
+
+ # figure out: table_number_base=table_number*256
+ tab_base_low = tab_base_low * 256
+ tab_base_high = (tab_base_high * 256) + \
+ int(tab_base_low / mod_base)
+ tab_base_low = tab_base_low % mod_base
+
+ if (table_number > 128*256*256) {
+ # figure out: table_number_base -= 256*256*256*256
+ # sub_high, sub_low is 256*256*256*256
+ sub_low = 256*256*256 % mod_base
+ sub_high = int(256*256*256 / mod_base)
+
+ sub_low = sub_low * 256
+ sub_high = (sub_high * 256) + int(sub_low / mod_base)
+ sub_low = sub_low % mod_base
+
+ tab_base_low = sub_low - tab_base_low;
+ tab_base_high = sub_high - tab_base_high;
+ tab_base_sign = -1;
+ if (tab_base_low < 0) {
+ tab_base_low = tab_base_low + mod_base
+ tab_base_high--
+ }
+ }
+ curr_low = tab_base_low
+ curr_high = tab_base_high
+ curr_sign = tab_base_sign
+ print "/*" > outfile
+ print " * " outfile ":" > outfile
+ print " * This file is automatically generated; please do not edit it." > outfile
+ print " */" > outfile
+}
+
+/^[ \t]*(error_code|ec)[ \t]+[A-Z_0-9]+,/ {
+ tag=substr($2,1,length($2)-1)
+ if (curr_high == 0) {
+ printf "#define %-40s (%dL)\n", tag, \
+ curr_sign*curr_low > outfile
+ } else {
+ printf "#define %-40s (%d%06dL)\n", tag, curr_high*curr_sign, \
+ curr_low > outfile
+ }
+ curr_low += curr_sign;
+ if (curr_low >= mod_base) {
+ curr_low -= mod_base;
+ curr_high++
+ }
+ if (curr_low < 0) {
+ cur_low += mod_base
+ cur_high--
+ }
+}
+
+END {
+ print "extern void initialize_" table_name "_error_table ();" > outfile
+ if (tab_base_high == 0) {
+ print "#define ERROR_TABLE_BASE_" table_name " (" \
+ sprintf("%d", tab_base_sign*tab_base_low) \
+ "L)" > outfile
+ } else {
+ print "#define ERROR_TABLE_BASE_" table_name " (" \
+ sprintf("%d%06d", tab_base_sign*tab_base_high, \
+ tab_base_low) "L)" > outfile
+ }
+ print "" > outfile
+ print "/* for compatibility with older versions... */" > outfile
+ print "#define init_" table_name "_err_tbl initialize_" table_name "_error_table" > outfile
+ print "#define " table_name "_err_base ERROR_TABLE_BASE_" table_name > outfile
+}
diff --git a/util/ss/ct_c.awk b/util/ss/ct_c.awk
new file mode 100644
index 0000000..872f6e0
--- /dev/null
+++ b/util/ss/ct_c.awk
@@ -0,0 +1,77 @@
+/^command_table / {
+ cmdtbl = $2;
+ printf "/* %s.c - automatically generated from %s.ct */\n", \
+ rootname, rootname > outfile
+ print "#include <ss/ss.h>" > outfile
+ print "" >outfile
+ print "#ifndef __STDC__" > outfile
+ print "#define const" > outfile
+ print "#endif" > outfile
+ print "" > outfile
+}
+
+/^BOR$/ {
+ cmdnum++
+ options = 0
+ cmdtab = ""
+ printf "static char const * const ssu%05d[] = {\n", cmdnum > outfile
+}
+
+/^sub/ {
+ subr = substr($0, 6, length($0)-5)
+}
+
+/^hlp/ {
+ help = substr($0, 6, length($0)-5)
+}
+
+/^cmd/ {
+ cmd = substr($0, 6, length($0)-5)
+ printf "%s\"%s\",\n", cmdtab, cmd > outfile
+ cmdtab = " "
+}
+
+/^opt/ {
+ opt = substr($0, 6, length($0)-5)
+ if (opt == "dont_list") {
+ options += 1
+ }
+ if (opt == "dont_summarize") {
+ options += 2
+ }
+}
+
+/^EOR/ {
+ print " (char const *)0" > outfile
+ print "};" > outfile
+ printf "extern void %s __SS_PROTO;\n", subr > outfile
+ subr_tab[cmdnum] = subr
+ options_tab[cmdnum] = options
+ help_tab[cmdnum] = help
+}
+
+/^[0-9]/ {
+ linenum = $1;
+}
+
+/^ERROR/ {
+ error = substr($0, 8, length($0)-7)
+ printf "Error in line %d: %s\n", linenum, error
+ print "#__ERROR_IN_FILE__" > outfile
+}
+
+END {
+ printf "static ss_request_entry ssu%05d[] = {\n", cmdnum+1 > outfile
+ for (i=1; i <= cmdnum; i++) {
+ printf " { ssu%05d,\n", i > outfile
+ printf " %s,\n", subr_tab[i] > outfile
+ printf " \"%s\",\n", help_tab[i] > outfile
+ printf " %d },\n", options_tab[i] > outfile
+ }
+ print " { 0, 0, 0, 0 }" > outfile
+ print "};" > outfile
+ print "" > outfile
+ printf "ss_request_table %s = { 2, ssu%05d };\n", \
+ cmdtbl, cmdnum+1 > outfile
+}
+
diff --git a/util/ss/ct_c.sed b/util/ss/ct_c.sed
new file mode 100644
index 0000000..f99cd7f
--- /dev/null
+++ b/util/ss/ct_c.sed
@@ -0,0 +1,161 @@
+#
+# This script parses a command_table file into something which is a bit
+# easier for an awk script to understand.
+#
+# Input syntax: a .ct file
+#
+# Output syntax:
+# (for the command_table line)
+# command_table <command_table>
+#
+#(for each request definition)
+# BOR
+# sub: <subroutine name>
+# hlp: <help text>
+# cmd: <command>
+# opt: <option>
+# EOR
+# (there may be more than one 'cmd' or 'opt' line
+#
+# A number sent to the output represents a parse error --- it will be
+# followed by the next line which will have the form:
+# ERROR: <error text>
+#
+# The design of this output syntax is such that it should be easy for
+# an awk script to parse.
+
+#
+# The first section of this script is just to cannoicalize the file.
+# It removes comments, and puts each command_table request onto a single
+# line
+#
+:FIRST
+y/ / /
+s/^ *//
+s/#.*$//
+/; *$/!{
+N
+y/ / /
+s/\n */ /
+bFIRST
+}
+s/, */, /g
+/^$/d
+#
+# Now we take care of some syntatic sugar.....
+#
+/^unimplemented/ {
+ s/^unimplemented [A-Za-z_0-9]*/request ss_unimplemented/
+ s/;/, (dont_list, dont_summarize);/
+}
+/^unknown/ {
+ s/^unknown /request ss_unknown, "", /
+}
+#
+# Dispatch based on the keyword.... illegal keywords are prefixed by ERROR:
+# and are handled by the awk script.
+#
+/^command_table /bCMD
+/^request /bREQUEST
+/^end;/bEND
+s/ .*//
+s/^/ERROR: unknown keyword: /
+=
+b
+#
+# Handle the command_table keyword
+#
+:CMD
+s/;$//
+p
+d
+b
+#
+# Handle the request keyword --- this is the heart of the sed script.
+#
+:REQUEST
+s/^request *//
+h
+i\
+BOR
+# First, parse out the subroutine name
+s/^/sub: /
+s/,.*//
+p
+# Next, parse out the help message, being careful to handle a quoted string
+g
+s/^[^,]*, *//
+h
+/^"/ {
+ s/^"//
+ s/".*//
+ x
+ s/^"[^"]*", *//
+ x
+ b EMITHLP
+}
+s/[^a-zA-Z0-9].*//
+x
+s/[a-zA-Z0-9]*, *//
+x
+:EMITHLP
+s/^/hlp: /
+p
+# Next take care of the command names
+:CMDLIST
+g
+/^(/b OPTIONS
+/^;/b EOR
+/^"/ {
+ s/^"//
+ s/".*//
+ x
+ s/^"[^"]*"//
+ s/, *//
+ x
+ b EMITREQ
+}
+s/[^A-Za-z_0-9].*//
+x
+s/[A-Za-z_0-9]*//
+s/, *//
+x
+:EMITREQ
+s/^/cmd: /
+p
+b CMDLIST
+#
+# Here we parse the list of options.
+#
+: OPTIONS
+g
+s/^(//
+h
+: OPTLIST
+/^)/ b EOR
+/^[^A-Za-z_0-9]/ {
+ =
+ c\
+ERROR: parse error in options list
+}
+s/[^A-Za-z_0-9].*//
+x
+s/[A-Za-z_0-9]*//
+s/, *//
+x
+s/^/opt: /
+p
+g
+b OPTLIST
+: EOR
+c\
+EOR\
+
+d
+b
+#
+# Handle the end keyword --- it's basically ignored.
+#
+:END
+d
+b