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 / filesect.icn < prev    next >
Text File  |  2002-03-26  |  1KB  |  52 lines

  1. ############################################################################
  2. #
  3. #    File:     filesect.icn
  4. #
  5. #    Subject:  Program to produce section of a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     March 26, 2002
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program writes the section of the input file starting at a
  18. #  specified line number and extending a specified number of lines.
  19. #
  20. #  The specifications are given as integer command-line arguments; the
  21. #  first is the starting line, the second is the number of lines.  For
  22. #  example,
  23. #
  24. #    filesect 20 100 <input >output
  25. #
  26. #  copies 100 lines from input to output, starting at line 20 of input.
  27. #
  28. #  If the specifications are out of range, the file written is truncated
  29. #  without comment.
  30. #
  31. #
  32. ############################################################################
  33.  
  34. procedure main(argl)
  35.    local start, count
  36.  
  37.    start := argl[1] | stop("*** starting value missing")
  38.    count := argl[2] | stop("*** count missing")
  39.  
  40.    if not (start := integer(start) & start > 0) then
  41.       stop("starting value not positive integer")
  42.    if not (count := integer(count) & count >= 0) then
  43.       stop("starting value not non-negative integer")
  44.  
  45.    every 1 to start - 1 do
  46.       read() | exit()
  47.  
  48.    every 1 to count do
  49.       write(read()) | exit()
  50.  
  51. end
  52.