home *** CD-ROM | disk | FTP | other *** search
Wrap
/* 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. © Don Cox March 93. Not Public Domain but freely usable for non-commercial purposes. */ /* $VER: PrintPScollated March 93 */ signal on error signal on syntax address command call SafeEndEdit.rexx() call ppm_AutoUpdate(0) cr="0a"x oldoutput = ppm_GetPSOutput() dest="ser" if oldoutput = "par:" then dest = "par" last = ppm_DocLastPage() first = ppm_DocFirstPage() cpage = ppm_CurrentPage() totalpages = ppm_NumPages() if totalpages = 0 then exit_msg("No pages") /* Set up a text file in ram: and later send it to a temporary command window */ conwindow = "CON:40/40/500/200/NewWindow" call open out, "ram:temp", write /* This wipes out any existing ram:temp */ call writeln out, "delete ram:temp.ps" call writeln out, "delete ram:prolog.ps" call writeln out, "delete ram:black.ps" call writeln out, "delete ram:odd.ps" call writeln out, "delete ram:even.ps" call writeln out, "delete ram:fonts.used" call writeln out, "delete ram:trailer.ps" call writeln out, "endcli" call close out 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 form = ppm_GetForm("Enter Range Of Pages", 28, form) if form = '' then call exit_msg("Aborted by User") parse var form frompage '0a'x topage '0a'x numcopies '0a'x OddEven '0a'x destination if destination= "ram:temp.ps" then exit_msg("Invalid Destination: ram:temp.ps") if destination = "" then destination = "ser:" if upper(destination) = "SER" then destination = "ser:" if upper(destination) = "PAR" then destination = "par:" if ~(datatype(frompage, n) & datatype(topage, n) & datatype(numcopies, n)) then exit_msg('Invalid Input') if frompage < first | frompage > last | topage < first | topage > last then exit_msg('Invalid Input for Page Range') OddEven = pos("Y",upper(OddEven)) /* zero if no split */ call ppm_SetPSFontDownload(0) call ppm_SetPSPrintMode(1) /* Black & white only */ call ppm_SetPSOutput("ram:temp.ps") success = ppm_PrintDocPS(1,1) trace n if success ~=1 then exit_msg("Failed saving temporary Postscript file.") call ppm_ShowStatus(" Printing...") call open("all","ram:temp.ps","read") call open("prolog", "ram:prolog.ps", "write") /* This wipes out any existing ram:temp1.ps */ call open("fonts", "ram:fonts.used", "write") call open("black", "ram:black.ps", "write") call open("odd", "ram:odd.ps", "write") call open("even", "ram:even.ps", "write") call open("trailer", "ram:trailer.ps", "write") prologtext = "" instring = "" do until eof("all") instring = readln("all") if word(instring,1) = "%%DocumentFonts:" then do /* make a list of fonts */ prologtext = prologtext||instring fileposition = seek("all",0,"C") do until eof("all") instring = readln("all") if instring = "" then break call writeln("fonts",word(instring,2)) end call seek("all",fileposition,"B") end prologtext = prologtext||instring||"0a"x if instring = "%%EndProlog" then break end call writech("prolog",prologtext) prologtext = "" /* clear RAM */ call close("prolog") call close("fonts") do until eof("all") instring = readln("all") instring = instring||"0a"x if word(instring,1)= "%%BeginProcessColor:" then break end blacktext = instring do until eof("all") instring = readln("all") if word(instring,1)= "%%Page:" then break blacktext = blacktext||instring||"0a"x end call writech("black",blacktext) call close("black") trace n oe="odd" if OddEven = 0 then do /* odd/even pages not split */ do until eof("all") if word(instring,1) = "%%Page:" & word(instring,2) >= frompage then break instring = readln("all") end pagetext = instring do until eof("all") instring = readln("all") if instring = "%%EndProcessColor" then break if word(instring,1) = "%%Page:" & word(instring,2) >= topage+1 then break pagetext = pagetext||instring||"0a"x if length(pagetext)>30000 then do call writech("odd",pagetext) pagetext = "" end end call writech("odd",pagetext) pagetext = "" call close("odd") end /* odd/even pages not split */ else do /* odd/even pages split */ do until eof("all") if word(instring,1)= "%%Page:" then do outpage = word(instring,2) oe="odd" if outpage//2 = 0 then oe="even" end if word(instring,1) = "%%Page:" & outpage >= frompage then break instring = readln("all") end if oe = "even" then do Epagetext = "%%Page: "frompage" "frompage Opagetext = "" end else do Opagetext = "%%Page: "frompage" "frompage Epagetext = "" end do until eof("all") instring = readln("all") if instring = "%%EndProcessColor" then break if word(instring,1)= "%%Page:" then do outpage = word(instring,2) oe="odd" if outpage//2 = 0 then oe="even" end if word(instring,1) = "%%Page:" & outpage >= topage+1 then break if oe = "even" then do Epagetext = Epagetext||instring||"0a"x if length(Epagetext)>30000 then do call writech("odd",Epagetext) Epagetext = "" end end else do Opagetext = Opagetext||instring||"0a"x if length(Opagetext)>30000 then do call writech("odd",Opagetext) Opagetext = "" end end end call writech("odd",Opagetext) Opagetext = "" call close("odd") call writech("even",Epagetext) Epagetext = "" call close("even") end /* odd/even pages split */ if instring~="%%EndProcessColor" then do until eof("all") instring = readln("all") if instring = "%%EndProcessColor" then break end trailertext = instring do until eof("all") instring = readln("all") trailertext = trailertext||instring||"0a"x end call writech("trailer",trailertext) call close("trailer") call close("all") trace n call open("fonts", "ram:fonts.used", "read") fontstring = "" do until eof("fonts") nextfont = readln("fonts") nextfont = "cgfonts:ps/"nextfont".psfont" if exists(nextfont) then fontstring = fontstring||" "nextfont end call close("fonts") oddstring = " " do i = 1 to numcopies oddstring = oddstring||" ram:odd.ps" end if OddEven~=0 then do do i = 1 to numcopies oddstring = oddstring||" ram:even.ps" end end "join ram:prolog.ps "fontstring" ram:black.ps"oddstring" ram:trailer.ps as "destination "newcli" conwindow "ram:temp" /* open a CLI and use ram:temp as a set of commands to delete temporary files */ call ppm_SetPSOutput(oldoutput) call exit_msg("Done") end error: syntax: do exit_msg("Genie failed due to error: "errortext(rc)) end exit_msg: do parse arg message if message ~= "" then call ppm_Inform(1,message,"Resume") call ppm_ClearStatus() call ppm_PPageToFront() call ppm_AutoUpdate(1) exit end