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

  1. ############################################################################
  2. #
  3. #    File:     ihelp.icn
  4. #
  5. #    Subject:  Program to give on-line help for Icon
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     December 5, 1989
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  ihelp -- Program to display "help" information
  18. #
  19. #       ihelp [-f helpfile] [item] [keyword ...]
  20. #
  21. #  The optional item name specifies the section of the help file which
  22. #  is to be displayed.  If no item name is specified a default section
  23. #  will be displayed, which usually lists the help items that are
  24. #  available.  An initial substring of the item name that differentiates
  25. #  it from other items is sufficient.
  26. #
  27. #  If keyword(s) are specified, then only lines that contain all of the
  28. #  keywords, in any order, are displayed.  The keywords do not have to
  29. #  correspond to whole words in the help text; only to text fragments.
  30. #
  31. #  All item name and keyword matches are case independent.
  32. #
  33. #  The help file name is taken from environment variable "HELPFILE".  If
  34. #  HELPFILE is not in the environment, file "help" in the current
  35. #  directory is used.  A help file name specified in the -f option
  36. #  overrides.
  37. #
  38. #  The help files are formatted as follows:
  39. #
  40. #       default text lines
  41. #       -
  42. #       one
  43. #       item "one" text lines
  44. #       -
  45. #       two
  46. #       item "two" text lines
  47. #       ...
  48. #
  49. #  Sections are separated by lines containing a single "-".  Item names
  50. #  are the first line following a separator line.
  51. #
  52. ############################################################################
  53. #
  54. #  Links: options
  55. #
  56. ############################################################################
  57.  
  58.  
  59. link options
  60.  
  61.  
  62. procedure main(arg)
  63.    local defaultHelpFile, opts, fn, f, item, line, keywords, i, lline, k
  64.  
  65.    #
  66.    #  Initialize.
  67.    #
  68.    defaultHelpFile := "ihelp.dat"
  69.    opts := options(arg,"f:")
  70.    fn := \opts["f"] | "" ~== getenv("HELPFILE") | defaultHelpFile
  71.    f := open(fn) | stop("Can't open help file \"",fn,"\"")
  72.    #
  73.    #  Look for the specified section, if one was.
  74.    #
  75.    if item := map(arg[1]) then {
  76.       line := ""
  77.       until item == map(line[1:*item + 1]) do {
  78.      while read(f) ~== "-"
  79.      line := read(f) | stop("No help for ",item)
  80.      }
  81.       }
  82.    #
  83.    #  Output the section lines that contain the keywords.
  84.    #
  85.    write(line)
  86.    keywords := arg[2:0] | []
  87.    every i := 1 to *keywords do keywords[i] := map(keywords[i])
  88.    while "-" ~== (line := read(f)) do {
  89.       lline := map(line)
  90.       if not (every k := !keywords do if not find(k,lline) then break) then
  91.         write(line)
  92.       }
  93. end
  94.  
  95.