home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / propage4.0 / arexx / printpscollated.pprx < prev    next >
Encoding:
Text File  |  1994-10-10  |  7.2 KB  |  254 lines

  1. /* This genie will print out several copies of a document in collated order. Temporary files need quite a lot of RAM. If you are short of RAM, change all the references to "ram:" to "PPage:" to put these files on disk instead. 
  2. © Don Cox March 93. Not Public Domain but freely usable for non-commercial purposes.
  3. */
  4.  
  5. /* $VER: PrintPScollated March 93 */
  6.  
  7. signal on error
  8. signal on syntax
  9. address command
  10. call SafeEndEdit.rexx()
  11. call ppm_AutoUpdate(0)
  12. cr="0a"x
  13.  
  14. oldoutput = ppm_GetPSOutput()
  15. dest="ser"
  16. if oldoutput = "par:" then dest = "par"
  17. last = ppm_DocLastPage()
  18. first = ppm_DocFirstPage()
  19. cpage = ppm_CurrentPage()
  20. totalpages = ppm_NumPages()
  21. if totalpages = 0 then exit_msg("No pages")
  22.  
  23. /* Set up a text file in ram: and later send it to a temporary command window */
  24. conwindow = "CON:40/40/500/200/NewWindow"
  25. call open out, "ram:temp", write  /* This wipes out any existing ram:temp  */
  26. call writeln out, "delete ram:temp.ps"
  27. call writeln out, "delete ram:prolog.ps" 
  28. call writeln out, "delete ram:black.ps" 
  29. call writeln out, "delete ram:odd.ps" 
  30. call writeln out, "delete ram:even.ps" 
  31. call writeln out, "delete ram:fonts.used"
  32. call writeln out, "delete ram:trailer.ps" 
  33. call writeln out, "endcli" 
  34. call close out
  35.  
  36.  
  37. form = "From:"first'0a'x"To:"last'0a'x"Number of copies:"2||'0a'x"Split Odd/Even?(Y/N) :N"||'0a'x"Destination :"dest
  38. form = ppm_GetForm("Enter Range Of Pages", 28, form)
  39. if form = '' then call exit_msg("Aborted by User")
  40. parse var form frompage '0a'x topage '0a'x numcopies '0a'x OddEven '0a'x destination
  41.  
  42. if destination= "ram:temp.ps" then exit_msg("Invalid Destination: ram:temp.ps")
  43. if destination = "" then destination = "ser:"
  44. if upper(destination) = "SER" then destination = "ser:"
  45. if upper(destination) = "PAR" then destination = "par:"
  46.  
  47. if ~(datatype(frompage, n) & datatype(topage, n) & datatype(numcopies, n)) then exit_msg('Invalid Input')
  48.  
  49. if frompage < first | frompage > last | topage < first | topage > last then exit_msg('Invalid Input for Page Range')
  50.  
  51. OddEven = pos("Y",upper(OddEven)) /* zero if no split */
  52.  
  53. call ppm_SetPSFontDownload(0)
  54. call ppm_SetPSPrintMode(1) /* Black & white only */
  55.  
  56. call ppm_SetPSOutput("ram:temp.ps")
  57. success = ppm_PrintDocPS(1,1)
  58. trace n
  59. if success ~=1 then exit_msg("Failed saving temporary Postscript file.")
  60.  
  61. call ppm_ShowStatus(" Printing...")
  62.  
  63. call open("all","ram:temp.ps","read")
  64. call open("prolog", "ram:prolog.ps", "write")  /* This wipes out any existing ram:temp1.ps  */
  65. call open("fonts", "ram:fonts.used", "write")
  66. call open("black", "ram:black.ps", "write")
  67. call open("odd", "ram:odd.ps", "write")
  68. call open("even", "ram:even.ps", "write")
  69. call open("trailer", "ram:trailer.ps", "write")
  70.  
  71. prologtext = ""
  72. instring = ""
  73. do until eof("all")
  74.     instring = readln("all")
  75.     if word(instring,1) = "%%DocumentFonts:" then do /* make a list of fonts */
  76.         prologtext = prologtext||instring
  77.         fileposition = seek("all",0,"C")
  78.         do until eof("all")
  79.             instring = readln("all")
  80.             if instring = "" then break
  81.             call writeln("fonts",word(instring,2))
  82.             end
  83.         call seek("all",fileposition,"B")
  84.         
  85.         end
  86.  
  87.     prologtext = prologtext||instring||"0a"x
  88.     if instring = "%%EndProlog" then break
  89.     end
  90.  
  91. call writech("prolog",prologtext)
  92. prologtext = ""  /* clear RAM */
  93. call close("prolog")
  94. call close("fonts")
  95. do until eof("all")
  96.     instring = readln("all")
  97.     instring = instring||"0a"x
  98.     if word(instring,1)= "%%BeginProcessColor:" then break
  99.     end
  100.  
  101. blacktext = instring
  102. do until eof("all")
  103.     instring = readln("all")
  104.     if word(instring,1)= "%%Page:" then break
  105.     blacktext = blacktext||instring||"0a"x
  106.     end
  107. call writech("black",blacktext)
  108. call close("black")
  109.  
  110. trace n
  111. oe="odd"
  112.  
  113. if OddEven = 0 then do /* odd/even pages not split */
  114.     do until eof("all")
  115.         if word(instring,1) = "%%Page:" & word(instring,2) >= frompage then break
  116.         instring = readln("all")
  117.         end
  118.  
  119.     pagetext = instring
  120.     do until eof("all")
  121.         instring = readln("all")
  122.         if instring = "%%EndProcessColor" then break
  123.         if word(instring,1) = "%%Page:" & word(instring,2) >= topage+1 then break
  124.         pagetext = pagetext||instring||"0a"x
  125.         if length(pagetext)>30000 then do
  126.             call writech("odd",pagetext)
  127.             pagetext = ""
  128.             end
  129.         end
  130.     call writech("odd",pagetext)
  131.     pagetext = ""
  132.     call close("odd")
  133.  
  134.     end  /* odd/even pages not split */
  135.  
  136.  
  137. else do /* odd/even pages split */
  138.     do until eof("all")
  139.         if word(instring,1)= "%%Page:" then do
  140.             outpage = word(instring,2)
  141.             oe="odd"
  142.             if outpage//2 = 0 then oe="even"
  143.             end
  144.         if word(instring,1) = "%%Page:" & outpage >= frompage then break
  145.         instring = readln("all")
  146.         end
  147.  
  148.     if oe = "even" then do
  149.         Epagetext = "%%Page: "frompage" "frompage
  150.         Opagetext = ""
  151.         end
  152.     else do
  153.         Opagetext = "%%Page: "frompage" "frompage
  154.         Epagetext = ""
  155.         end
  156.  
  157.     do until eof("all")
  158.         instring = readln("all")
  159.         if instring = "%%EndProcessColor" then break
  160.         if word(instring,1)= "%%Page:" then do
  161.             outpage = word(instring,2)
  162.             oe="odd"
  163.             if outpage//2 = 0 then oe="even"
  164.             end
  165.         if word(instring,1) = "%%Page:" & outpage >= topage+1 then break
  166.         if oe = "even" then do
  167.             Epagetext = Epagetext||instring||"0a"x
  168.             if length(Epagetext)>30000 then do
  169.                 call writech("odd",Epagetext)
  170.                 Epagetext = ""
  171.                 end
  172.             end
  173.         else do
  174.             Opagetext = Opagetext||instring||"0a"x
  175.             if length(Opagetext)>30000 then do
  176.                 call writech("odd",Opagetext)
  177.                 Opagetext = ""
  178.                 end 
  179.             end
  180.         end
  181.     call writech("odd",Opagetext)
  182.     Opagetext = ""
  183.     call close("odd")
  184.     call writech("even",Epagetext)  
  185.     Epagetext = ""
  186.     call close("even")
  187.  
  188.     end /* odd/even pages split */
  189.  
  190.  
  191. if instring~="%%EndProcessColor" then do until eof("all")
  192.     instring = readln("all")
  193.     if instring = "%%EndProcessColor" then break
  194.     end
  195.  
  196. trailertext = instring
  197. do until eof("all")
  198.     instring = readln("all")
  199.     trailertext = trailertext||instring||"0a"x
  200.     end
  201. call writech("trailer",trailertext)
  202. call close("trailer")
  203. call close("all")
  204.  
  205. trace n
  206.  
  207. call open("fonts", "ram:fonts.used", "read")
  208. fontstring = ""
  209. do until eof("fonts")
  210.     nextfont = readln("fonts")
  211.     nextfont = "cgfonts:ps/"nextfont".psfont"
  212.     if exists(nextfont) then fontstring = fontstring||" "nextfont
  213.     end
  214. call close("fonts")
  215.  
  216. oddstring = " "
  217. do i = 1 to numcopies
  218.     oddstring = oddstring||" ram:odd.ps"
  219.     end
  220. if OddEven~=0 then do
  221.     do i = 1 to numcopies
  222.         oddstring = oddstring||" ram:even.ps"
  223.         end
  224.     end
  225.  
  226. "join ram:prolog.ps "fontstring" ram:black.ps"oddstring" ram:trailer.ps as "destination
  227.  
  228. "newcli" conwindow "ram:temp" /* open a CLI and use ram:temp as a set of commands to delete temporary files */
  229.  
  230. call ppm_SetPSOutput(oldoutput)
  231. call exit_msg("Done")
  232.  
  233. end
  234.  
  235. error:
  236. syntax:
  237.     do
  238.     exit_msg("Genie failed due to error: "errortext(rc))
  239.     end
  240.  
  241. exit_msg:
  242.     do
  243.     parse arg message
  244.     if message ~= "" then
  245.     call ppm_Inform(1,message,"Resume")
  246.     call ppm_ClearStatus()
  247.     call ppm_PPageToFront()
  248.     call ppm_AutoUpdate(1)
  249.     exit
  250.     end
  251.  
  252.  
  253.  
  254.