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

  1. ############################################################################
  2. #
  3. #    File:     psrsplit.icn
  4. #
  5. #    Subject:  Program to separate psrecord.icn output pages
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     September 21, 1999
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  usage:  psrsplit file
  18. #
  19. #     If a file produced by the procedures in psrecord.icn contains multiple
  20. #  pages, it cannot be easily incorporated into another document.  psrsplit
  21. #  reads such a file and breaks it into individual pages.  The algorithm
  22. #  is frugal of memory and file descriptors at the expense of reading the
  23. #  input file multiple times.
  24. #
  25. #     For an input file is named xxxx or xxxx.yyy, the output files are
  26. #  named xxxx.p01, xxxx.p02, etc. for as many pages as are available.
  27. #  It is assumed that the input file was written by psrecord.icn; the
  28. #  likelihood of correctly processing anything else is small.
  29. #
  30. ############################################################################
  31.  
  32. procedure main(args)
  33.    local ifile, ofile, iname, basename, oname, pageno, line, n
  34.  
  35.    iname := args[1]            | stop("usage: ", &progname, " file")
  36.    ifile := open(iname)            | stop("can't open ", iname)
  37.    basename := (iname ? tab(upto('.') | 0))
  38.  
  39.    every pageno := seq() do {        # read file once for each page
  40.       if pageno < 10 then
  41.          oname := basename || ".p0" || pageno
  42.       else
  43.          oname := basename || ".p" || pageno
  44.       ofile := open(oname, "w")        | stop("can't open ", oname)
  45.  
  46.       seek(ifile, 1)            | stop("can't rewind ", iname)
  47.       line := read(ifile)        | stop(iname, ": empty file")
  48.       line ? ="%!"            | stop(iname, ": not a PostScript file")
  49.       write(&errout, "   writing ", oname)
  50.       write(ofile, "%!PS-Adobe-3.0 EPSF-3.0")
  51.  
  52.       n := 0
  53.       while n < pageno do {        # copy to nth "copypage"
  54.          line := read(ifile) | break break
  55.          if line ? ="copypage" then
  56.             n +:= 1
  57.          else
  58.             write(ofile, line)
  59.          }
  60.       write(ofile, "showpage")
  61.       write(ofile, "%%EOF")
  62.       close(ofile)
  63.       }
  64. end
  65.