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

  1. ############################################################################
  2. #
  3. #    File:     filtskel.icn
  4. #
  5. #    Subject:  Program skeleton for generic filter
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     July 16, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Generic filter skeleton in Icon.
  18. #
  19. #  This program is not intended to be used as is -- it serves as a
  20. #  starting point for creation of filter programs.  Command line
  21. #  options, file names, and tabbing are handled by the skeleton.  You
  22. #  need only provide the filtering code.
  23. #
  24. #  As it stands, filter.icn simply copies the input file(s) to
  25. #  standard output.
  26. #
  27. #  Multiple files can be specified as arguments, and will be processed
  28. #  in sequence.  A file name of "-" represents the standard input file.
  29. #  If there are no arguments, standard input is processed.
  30. #
  31. ############################################################################
  32. #
  33. #  Links: options
  34. #
  35. ############################################################################
  36.  
  37. link options
  38.  
  39. procedure main(arg)
  40.    local opt, tabs, Detab, fn, f, line
  41.    #
  42.    #  Process command line options and file names.
  43.    #
  44.    opt := options(arg,"t+")      # e.g. "fs:i+r." (flag, string, integer, real)
  45.    if *arg = 0 then arg := ["-"] # if no arguments, standard input
  46.    tabs := (\opt["t"] | 8) + 1   # tabs default to 8
  47.    Detab := tabs = 1 | detab     # if -t 0, no detabbing
  48.    #
  49.    #  Loop to process files.
  50.    #
  51.    every fn := !arg do {
  52.       f := if fn == "-" then &input else
  53.         open(fn) | stop("Can't open input file \"",fn,"\"")
  54.       #
  55.       #  Loop to process lines of file (in string scanning mode).
  56.       #
  57.       while line := Detab(read(f)) do line ? {
  58.      write(line)       # copy line to standard output
  59.      }
  60.       #
  61.       #  Close this file.
  62.       #
  63.       close(f)
  64.       }
  65.    #
  66.    #  End of program.
  67.    #
  68. end
  69.