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 / indxcomp.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  104 lines

  1. ############################################################################
  2. #
  3. #    File:     indxcomp.icn
  4. #
  5. #    Subject:  Program to assist in index compilation
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 23, 2000
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program is designed to assist in the compilation of indexes.
  18. #
  19. #  It takes input from standard input and expects lines that either consist
  20. #  of an integer (taken to be a page number) or text (to be indexed on
  21. #  page of the last page number.
  22. #
  23. #  The idea is to go through the work to be indexed and create a file
  24. #  in which the page number is entered followed by items to be indexed
  25. #  on that page.  Page numbers (which need not be numeric) are prefixed
  26. #  by "=".  For example, the file might consist of
  27. #
  28. #    =1
  29. #    warts
  30. #    moles
  31. #    scratches
  32. #    =2
  33. #    scratches
  34. #    dents
  35. #    bumps
  36. #    =3
  37. #    hickies
  38. #
  39. #  The output of this program for that input is:
  40. #
  41. #    bumps, 2
  42. #    dents, 2
  43. #    hickies, 3
  44. #    moles, 1
  45. #    scratches, 1, 2
  46. #    warts, 1
  47. #
  48. #  Leading blanks are stripped from index items.  Therefore to enter
  49. #  an index item that begins with "=" start with " =" instead.
  50. #
  51. #  This program is unsophisticated.  It contains no provisions for
  52. #  formatting index entries nor any way to indicated inclusive page
  53. #  ranges.  Such things have to be done in post-processing.
  54. #
  55. #  non-numeric page "numbers" appear before numeric ones.
  56. #
  57. #  Obviously, there is room for improvement, embellishment, and creeping
  58. #  featurism.
  59. #
  60. ############################################################################
  61.  
  62. procedure main()
  63.    local index, page, line, lines, temp1, temp2, x, xcase
  64.    local lline
  65.  
  66.    index := table()
  67.    xcase := table(" *** empty line")
  68.    page := "<no page number>"  # in case file doesn't start with a page number
  69.  
  70.    while line := read() do {
  71.       line ? {
  72.          if ="=" then {
  73.             page := tab(0)
  74.             page := integer(page)    # for sorting; may fail
  75.             if page === "" then page := "<empty page number>"
  76.             next
  77.             }
  78.          }
  79.       line ?:= (tab(many(' ')), tab(0))    # trim leading blanks
  80.       if *line = 0 then next
  81.       lline := map(line)
  82.       xcase[lline] := line
  83.       if lline == "" then lline := " *** empty line"
  84.       /index[lline] := set()
  85.       insert(index[lline], page)
  86.       }
  87.  
  88.    index := sort(index, 3)
  89.  
  90.    while writes(xcase[get(index)]) do {
  91.       lines := sort(get(index))
  92.       temp1 := []
  93.       temp2 := []
  94.       while x := get(lines) do {
  95.          if type(x) == "string" then put(temp1, x)
  96.          else put(temp2, x)
  97.          }
  98.       lines := temp1 ||| temp2
  99.       while writes(", ", get(lines))
  100.       write()
  101.       }
  102.  
  103. end
  104.