4.3BSD/usr/contrib/icon/tran/mkkeytab.icn

# mkkeytab - builds keyword.c, which is structure of keywords and
#  their identification numbers. also builds keyword.h, which has
#  defined constants giving keyword identification numbers.
#  input is list of keyword/identfication number pairs, (alphabetic
#  order-one pair per line) in file 'keywords', elements of a pair
#  are separated by one or more blanks or tabs.

procedure main(args)
local df, f, input, word, atab

   input := open("keywords") | stop("unable to open 'keywords'")
   f := open("keyword.c","w")
   df := open("../h/keyword.h","w")
   write(df,"/*")
   write(df," * Keyword definitions.")
   write(df," */\n")

   write(f, "#include \"../h/keyword.h\"")   # put out table header
   write(f, "#include \"sym.h\"")
   write(f, "")
   write(f, "/*")
   write(f, " * Keyword table.")
   write(f, " */")
   write(f, "")
   write(f, "struct keyent keytab[] = {")

   every                               # put out table body
      trim(!input) ?
         if word := tab(upto(' \t')) then {
            tab(many(' \t'))
            if *word < 6 then atab := "\t\t" else atab := "\t"
            write(df, "#define K_",ucase(word),atab,right(tab(0),2)) 
            write(f,"   \"",word,"\",\tK_",ucase(word),",")
            }
         else
            write(&errout, "bad input: ", &subject)

   write(f,"   \"\"\t\t-1")
   write(f, "   };")

end

procedure ucase(name)
   return map(name,&lcase,&ucase)
end