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 / icontent.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  76 lines

  1. ############################################################################
  2. #
  3. #    File:     icontent.icn
  4. #
  5. #    Subject:  Program to list Icon procedures
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     August 17, 1990
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Builds a list, in Icon comment format, of procedures and records
  18. #  in an Icon source file.
  19. #
  20. #  Multiple files can be specified as arguments, and will be processed
  21. #  in sequence.  A file name of "-" represents the standard input file.
  22. #  If there are no arguments, standard input is processed.
  23. #
  24. #  usage: icontent <options> <Icon source file>...
  25. #    options:    -s    sort names alphabetically (default is in
  26. #                order of occurrence)
  27. #            -l    list in single column (default is to list
  28. #                in multiple columns)
  29. #
  30.  
  31. link options,colmize
  32.  
  33. procedure main(arg)
  34.    local opt,linear,Colmize,Sort,namechar,fn,f,names,line,name,type
  35.    #
  36.    #  Process command line options and file names.
  37.    #
  38.    opt := options(arg,"sl")
  39.    linear := opt["l"]
  40.    Colmize := if \opt["l"] then proc("!",1) else colmize
  41.    Sort := if \opt["s"] then sort else 1
  42.    if *arg = 0 then arg := ["-"] # if no arguments, standard input
  43.    namechar := &letters ++ &digits ++ "_"
  44.    #
  45.    #  Loop to process files.
  46.    #
  47.    every fn := !arg do {
  48.       f := if fn == "-" then &input else {
  49.      if not (fn[-4:0] == ".icn") then fn ||:= ".icn"
  50.      open(fn) | stop("Can't open input file \"",fn,"\"")
  51.          }
  52.       names := []
  53.       write("#  Procedures and Records",
  54.       if f === &input then "" else " in " || fn,":")
  55.       #
  56.       #  Loop to process lines of file (in string scanning mode).
  57.       #
  58.       while line := read(f) do line ? {
  59.      if    (tab(many(' \t')) | "")\1 &
  60.            type := (=("procedure" | "record"))\1 &
  61.            (tab(many(' \t')) | "")\1 & name := tab(many(namechar)) &
  62.            (tab(many(' \t')) | "")\1 & ="(" then {
  63.         put(names,name || if type == "procedure" then "()" else ".")
  64.         }
  65.      }
  66.       #
  67.       #  Close this file.
  68.       #
  69.       close(&input ~=== f)
  70.       every write("#    ",Colmize(Sort(names),71))
  71.       }
  72.    #
  73.    #  End of program.
  74.    #
  75. end
  76.