home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / icont / mkkwd.icn < prev    next >
Text File  |  2000-07-29  |  1KB  |  53 lines

  1. #  mkkwd.icn
  2. #
  3. #  reads:   standard input  (typically ../runtime/keywords.r) 
  4. #
  5. #  writes:  keyword.c
  6. #        keyword.h
  7. #        kdefs.h
  8.  
  9. procedure main()
  10.    local kywds, klist, line, f, k, i
  11.  
  12.    # load keywords
  13.    kywds := set()
  14.    while line := read() do {
  15.       line ? {
  16.      if ="keyword" then {
  17.         tab(find("}")+1)
  18.         tab(many(' \t'))
  19.         insert(kywds,tab(0))
  20.      }
  21.       }
  22.    }
  23.    klist := sort(kywds)
  24.  
  25.    # write defined constants to keyword.h
  26.    hfile := wopen("keyword.h", "Keyword manifest constants")
  27.    lfile := wopen("../h/kdefs.h", "Keyword list")
  28.    i := 0
  29.    every k := !klist do {
  30.       kname := "K_" || map(k,&lcase,&ucase)
  31.       write(hfile, "#define ", left(kname,13), right(i+:=1,3))
  32.       write(lfile, "KDef(", k, ",", kname, ")")
  33.       }
  34. end
  35.  
  36.  
  37. #  wopen(fname,comment) -- open file for writing
  38. #
  39. #  opens and returns file; writes header comment; writes message to stdout
  40.  
  41. procedure wopen(fname,comment)
  42.    local f
  43.    f := open(fname, "w") | stop ("can't open ", fname, " for writing")
  44.    write(f, "/*")
  45.    write(f, " * ", fname, " -- ", comment, ".")
  46.    write(f, " *")
  47.    write(f, " * Created mechanically by mkkwd.icn -- DO NOT EDIT.")
  48.    write(f, " */")
  49.    write(f)
  50.    write("  writing ", fname)
  51.    return f
  52. end
  53.