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 / ipl / progs / iplindex.icn < prev    next >
Text File  |  2000-07-29  |  4KB  |  132 lines

  1. ############################################################################
  2. #
  3. #    File:     iplindex.icn
  4. #
  5. #    Subject:  Program to produce indexed listing of the program library
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     March 3, 1996
  10. #
  11. ###########################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  The following options are supported:
  18. #
  19. #    -k i    width keyword field, default 16
  20. #    -p i    width of field for program name, default 12
  21. #
  22. #     Some noise words are omitted (see "exceptions" in the program text).
  23. #  If a file named except.wrd is open and readable in the current directory,
  24. #  the words in it are used instead.
  25. #
  26. #     This program is pretty simple.  Possible extensions include ways
  27. #  of specifying words to be omitted, more flexible output formatting, and
  28. #  so on.  Another "embellisher's delight".
  29. #
  30. #     This program was derived from kwic.icn by Steve Wampler.
  31. #
  32. #     The format of the output was suggested by Gregg Townsend.
  33. #
  34. ############################################################################
  35. #
  36. #  Links:  options
  37. #
  38. ############################################################################
  39.  
  40. link options
  41.  
  42. global line, loc, exceptions, key_width,  program_width, tag
  43.  
  44. record pair(name, line)
  45.  
  46. procedure main(args)
  47.    local exceptfile, opts
  48.  
  49.    opts := options(args, "k+p+")
  50.    key_width := \opts["k"] | 16
  51.    program_width := \opts["p"] | 12
  52.  
  53.    if exceptfile := open("except.wrd") then {
  54.       exceptions := set()
  55.       every insert(exceptions, lcword(exceptfile))
  56.       close(exceptfile)
  57.       }
  58.    else
  59.       exceptions := set(["and", "for", "into", "all", "from", "get", "put",
  60.          "compute", "perform", "apply", "model", "value", "model", "operator",
  61.          "out", "problem", "produce", "such", "use", "operation",
  62.          "between", "data", "different", "down", "miscellaneous", "non",
  63.          "obtaining", "using", "value", "values", "various", "with",
  64.          "begin", "end", "not", "way", "possible", "required", "until",
  65.          "that", "within", "once", "the"
  66.          ])
  67.  
  68.    write(left("keyword", key_width), left("location", program_width),
  69.       "description")
  70.    write()
  71.  
  72.    every write(filter(indexer(&input)))
  73.  
  74. end
  75.  
  76. procedure indexer(file)
  77.    local index, word
  78.  
  79. #  Each word, in lowercase form, is a key in the table "index".
  80. #  The corresponding values are lists of the lines for that word.
  81.  
  82.    index := table()
  83.  
  84.    every word := lcword(file) do {
  85.       if not member(exceptions,word) then {
  86.          /index[word] := []
  87.          index[word] := put(index[word],line)
  88.          }
  89.       }
  90.  
  91.    index := sort(index,3)
  92.  
  93. #  while get(index) do
  94. #     suspend !get(index)
  95.  
  96.    while name := get(index) do
  97.       suspend pair(name, !get(index))
  98.  
  99. end
  100.  
  101. procedure lcword(file)
  102.    local name, word
  103.    static chars
  104.  
  105.    initial {
  106.       chars := &letters ++ &digits
  107.       tag := table()
  108.       }
  109.  
  110.    every line := !file do {
  111.       line ?:= {
  112.          name := tab(find(": "))    # program name
  113.          move(2)            # skip trash
  114.          tab(0)                # rest is now line
  115.          }
  116.       tag[line] := name            # name for the line
  117.       line ? {
  118.          while tab(loc := upto(chars)) do {
  119.             word := map(tab(many(chars)))
  120.             if *word > 2 & not(any('(')) then suspend word
  121.             }
  122.           }
  123.       }
  124. end
  125.  
  126. procedure filter(result)
  127.  
  128.    return left(result.name, key_width) ||
  129.       left(tag[result.line], program_width) || result.line
  130.  
  131. end
  132.