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

  1. ############################################################################
  2. #
  3. #    File:     patfetch.icn
  4. #
  5. #    Subject:  Program to extract patterns from a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     July 22, 1993
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program accepts a list of integer specifications for patterns
  18. #  as the appear in order in a file of patterns.  The selected patterns
  19. #  are written to standard output, but not until the end of the input
  20. #  specifications.  The name of the pattern file is specified on the
  21. #  command line.
  22. #
  23. #  Each line of input can be a comma-separated string of either integers
  24. #  or integer ranges.  Blanks after commas are tolerated.  An example of
  25. #  input is:
  26. #
  27. #    1-3, 5
  28. #    10
  29. #    13-17
  30. #    8
  31. #
  32. #  which specifies the patterns 1, 2, 3, 5, 8, 10, 13, 14, 15, 16, and 17.
  33. #
  34. #  Note that the integers need not be in order, although within a range,
  35. #  the lower bound must precede the upper bound.
  36. #
  37. ############################################################################
  38. #
  39. #  Links:  patutils
  40. #
  41. ############################################################################
  42.  
  43. link patutils
  44.  
  45. procedure main(args)
  46.    local file, input, i, hitlist, patlist, spec, lo, hi, subspec
  47.  
  48.    file := args[1] | stop("*** no pattern list specified")
  49.  
  50.    input := open(file) | stop(" *** cannot open input file")
  51.  
  52.    hitlist := set()            # construct set of indices to remove
  53.  
  54.    while spec := read() do {
  55.       spec ? {
  56.          while subspec := tab(upto(',') | 0) do {
  57.             if insert(hitlist, integer(subspec)) then {        # integer
  58.                move(1) | break
  59.                tab(many(' '))
  60.                }
  61.             else {
  62.                subspec ? {
  63.                   lo := tab(many(&digits)) &
  64.                   ="-" &
  65.                   hi := tab(many(&digits)) &
  66.                   lo <= hi &
  67.                   pos(0) | write(&errout, "*** bad specification")
  68.                   every insert(hitlist, 0 < integer(lo to hi))
  69.                   }
  70.                move(1) | break
  71.                tab(many(' '))
  72.                }
  73.             }
  74.          }
  75.       }
  76.  
  77.    patlist := []            # read in list of patterns
  78.  
  79.    while put(patlist, readpatt(input))
  80.    
  81.    every i := !sort(hitlist) do {        # write out selected patterns
  82.       write(patlist[i]) | write(&errout, "*** ", i, " out of bounds")
  83.       }
  84.  
  85. end
  86.