/* REXX | | Name: LANPRT | | Author: David Alcock :: dave@planetmvs.com | | Purpose: LANPRT is an ISPF edit macro that prints the file | being edited (or only the lines selected with the | S/SS range) on the LAN printer of your choice. | | Limitations: Many, to wit: | o Does not handle Machine printer control chars. | o Only supports HP PCL, for postscript see Lionel | Dyck's PRINT package for his LPRPRINT command at | http://www.geocitites.com/dbdyck/ | o The current PCL support prints LANDSCAPE only. | | LANPRT does everything that I wrote it for: printing | listings on my nice HP LAN printer. | | Syntax: | o LANPRT | > Send print to printer taking all defaults | o LANPRT HOST 192.168.1.20 | > Send output to host at IP address 192.198.1.20 | o LANPRT HOST HP4050 | > Send output to host at host name HP4050 | o LANPRT TRIMASM | > Trim the HLASM headings off. This is good like when you are | > printing DSECTs and want to cut down on the output. | o LANPRT NOASA | > Don't look for ASA control characters for special processing | o LANPRT SAVE | > Don't delete the output ASCII print file | o LANPRT NOPRT | > Don't print - (when you just want to see what's generated). | > Use Greg Price's REVIEW command to view with the ASCII option. | o LANPRT DSN 'IBMUSER.OUTPUT.HPPCL' | > Put the generated PC print file in this file name. | o LANPRT REPLACE | > Don't delete the work file | o LANPRT NODELETE | > Don't delete the work file | o LANPRT HOST HP4050 TRIMASM SAVE | > example of many options on one command | | Disclaimer: This REXX exec is FREEWARE. Use at your own risk. It | is provided for your enjoyment and neither David | Alcock or his employer provides any warranty for it's | use. I'd like to hear how it works on your system. | | This software is not in the public domain but is | available free of charge and with source code | provided. It is copyright 2000 by David Alcock | All rights reserved. */ daver = "1.1" /* ================================================================= * | | M o d i f i c a t i o n H i s t o r y | | Person Date Ver Description | ---------- ---------- --- ---------------------------------------- | DGAlcock 2000-07-20 1.1 Added option TRIMASM that trims all | of the headings off a HLASM listing; | DGAlcock 2000-07-02 1.0 Initial exec written; * ================================================================= */ /*--------------------------------------------------------------------- | Set user defaults ------------------------------------------------------------------- */ o_ptype = "PCL" o_workunit = "SYSDA" o_host = "161.235.6.108" /* or set to null if to be always req. */ o_prtname = "printer" o_temphlq = sysvar(sysuid)".SPFTEMP9" /* HLQ for user temp ds */ o_cctype = "A" /* Control Character is ASA */ o_scrape = "" /* Doing any "screen scraping" along the way? */ o_save = 0 /* Save output dataset? */ o_dsn = "" /* Use another dataset name? */ o_delwrk = 1 /* Delete work dataset and allocate new one */ o_noprt = 0 /* Don't print? */ /*--------------------------------------------------------------------- | Initialiation for this environment ------------------------------------------------------------------- */ if sysvar("SYSISPF") <> "ACTIVE" then do say "The LANPRT exec is an ISPF edit macro, terminating" end address ISREDIT "MACRO (PARMS) NOPROCESS" if rc <> 0 then do say "The LANPRT command is only to be used as an Edit Macro," , "terminating..." exit 12 end "(OVDSN) = DATASET" "(MEMBER) = MEMBER" if member <> '' then ovdsn = "'"ovdsn||"("||member||")'" else ovdsn = "'"ovdsn"'" if ovdsn == "''" then do ovdsn = "" end /*--------------------------------------------------------------------- | Process the whole dataset or just the lines selected ------------------------------------------------------------------- */ address ISREDIT 'PROCESS RANGE S' select when rc = 0 then do '(CMD) = RANGE_CMD' /* Get the command */ '(LINE1) = LINENUM .ZFRANGE' /* Get first in range */ '(LINE2) = LINENUM .ZLRANGE' /* Get last in range */ end when rc <= 4 then do /* No S or SS entered, use entire file */ '(CMD) = RANGE_CMD' /* Get the command */ '(LINE1) = LINENUM .ZFIRST' /* Get first in range */ '(LINE2) = LINENUM .ZLAST' /* Get last in range */ end otherwise /* Line command conflict - Edit will create message */ exit 12 end /* of "select" */ /*--------------------------------------------------------------------- | Process parms ------------------------------------------------------------------- */ do i = 1 to words(parms) this = translate(strip(word(parms,i))) /* uppercase option */ that = translate(strip(word(parms,i+1))) /* uppercase option */ select when this == "TRIMASM" then o_scrape = "TH" /* Trim HLASM */ when this == "NOASA" then o_cctype = "" when this == "SAVE" then o_save = 1 when this == "NOPRT" then o_noprt = 1 when this == "DSN" then do if that == "" then do say "Missing dataset name, terminating" exit 12 end o_dsn = that i = i + 1 end when this == "HOST" then do if that == "" then do say "Missing host name, using default of" o_host end else o_host = that i = i + 1 end when this == "REPLACE" then o_delwrk = 0 when this == "NODELETE" then o_delwrk = 0 otherwise say "Ignoring Invalid option:" this end end /*--------------------------------------------------------------------- | Did everything parse out ok? ------------------------------------------------------------------- */ if strip(o_host) == "" then do say "Missing host name, syntax is: LANPRT HOST ip.address" say " or: LANPRT HOST host-name" exit 12 end /*--------------------------------------------------------------------- | Allocate work file ------------------------------------------------------------------- */ lpfwrkf_ran = random() lpfwrkf_dd = "LPF"lpfwrkf_ran if o_dsn <> "" then lpfwrkf_dsn = o_dsn else lpfwrkf_dsn = "'"o_temphlq".LANPRT.#"lpfwrkf_ran"'" if o_delwrk == 1 then do address TSO x = outtrap("XMSG.","*") "DELETE "lpfwrkf_dsn x = outtrap("off") "ALLOCATE FILE("lpfwrkf_dd") DA("lpfwrkf_dsn")" , "UNIT("o_workunit") NEW REUSE SPACE(30 30) TRACKS" , "LRECL(255) BLKSIZE(32760) RECFM(V B)" arc = rc end else do "ALLOCATE FILE("lpfwrkf_dd") DA("lpfwrkf_dsn") SHR" arc = rc end if arc <> 0 then do say "Allocation of work dataset: "lpfwrkf_dsn "failed," , "terminating..." exit 12 end newstack /* | Set the ASCII variables as needed */ call set_ASCII_vars /* | Start this print datastream right by setting up the printer | with a good initialization string */ select when o_ptype = "PCL" then do h = '1B45'x /* Reset printer */ h = h||'1B266C316F32613844'x /* Lines per inch */ h = h||'1B2661354C'x h = h||'1B287330703134683354'x /* 12 CPI */ queue h||crlf end /* when o_ptype = "PS" then yada-yada-yada */ /* when o_ptype = "?" then yada-yada-yada */ otherwise nop end /*--------------------------------------------------------------------- | Process the lines ------------------------------------------------------------------- */ hlasm_drc = 0 hlasm_ingoodstuff = 0 asafound = 0 EOF = 0 num_lines = 0 address ISREDIT do i = line1 to line2 '(LINEVAL) = LINE' i skipline = 0 newpage = 0 if o_cctype == "A" then call Fix_ASA_CC if o_scrape == "TH" then call Trim_HLASM_Listing if EOF == 1 then leave if skipline = 1 then iterate if lineval = "" then iterate if asafound = 1 then lineval = substr(lineval,2,length(lineval)-1) lineval = translate(strip(lineval,'T'),toASCII,hextable) if newpage = 1 then lineval = '1b266c3148'x||lineval num_lines = num_lines + 1 queue lineval||crlf end queue '' /* indicate end of file */ address TSO "EXECIO * DISKW "lpfwrkf_dd" (FINIS" "delstack" /* At this point lpfwrkf_dsn has a complete ASCII print stream! */ say " " say num_lines "non-blank lines queued" say " " if o_save == 1 then say "DSN="lpfwrkf_dsn "has raw ASCII print file" if o_scrape == "TH" then do say " " say "Dropped "hlasm_drc" from HLASM listing" say " " end /*--------------------------------------------------------------------- | Print to LAN Printer via IBM's TCP/IP LPR command ------------------------------------------------------------------- */ if o_noprt == 0 then do address TSO c = "LPR "lpfwrkf_dsn" (Printer "o_prtname" Host "o_host" BINARY" "LPR "lpfwrkf_dsn" (Printer "o_prtname" Host "o_host" BINARY" lrc = rc if lrc <> 0 then do say " " say "Print had rc="lrc" from command:" say "> "c end else do address ISPEXEC zedsmsg = "Print Queued" zedlmsg = "Print Queued to host "o_host "SETMSG MSG(ISRZ001)" end end address TSO x = outtrap("XMSG.","*") "FREE FILE("lpfwrkf_dd")" if o_save == 0 then "DELETE" lpfwrkf_dsn x = outtrap("off") exit 0 /*--------------------------------------------------------------------- | Set ASCII translation variables ------------------------------------------------------------------- */ set_ASCII_vars: esc = '1b'x blank = '20'x crlf = '0d0a'x /* | ISO 8859-1 to CECP 1047 (Extended de-facto EBCDIC): */ toASCII = '00010203A609A77FA9B0B10B0C0D0E0F'x /* 00 */ toASCII = toASCII||'10111213B2B408B718191AB8BA1DBB1F'x /* 10 */ toASCII = toASCII||'BDC01CC1C20A171BC3C4C5C6C7050607'x /* 20 */ toASCII = toASCII||'C8C916CBCC1ECD04CED0D1D21415D3FC'x /* 30 */ toASCII = toASCII||'20D4838485A0D58687A4D62E3C282BD7'x /* 40 */ toASCII = toASCII||'268288898AA18C8B8DD821242A293B5E'x /* 50 */ toASCII = toASCII||'2D2FD98EDBDCDD8F80A57C2C255F3E3F'x /* 60 */ toASCII = toASCII||'DE90DFE0E2E3E4E5E6603A2340273D22'x /* 70 */ toASCII = toASCII||'E7616263646566676869AEAFE8E9EAEC'x /* 80 */ toASCII = toASCII||'F06A6B6C6D6E6F707172F1F291F392F4'x /* 90 */ toASCII = toASCII||'F57E737475767778797AADA8F65BF7F8'x /* A0 */ toASCII = toASCII||'9B9C9D9E9FB5B6ACABB9AAB3BC5DBEBF'x /* B0 */ toASCII = toASCII||'7B414243444546474849CA939495A2CF'x /* C0 */ toASCII = toASCII||'7D4A4B4C4D4E4F505152DA968197A398'x /* D0 */ toASCII = toASCII||'5CE1535455565758595AFDEB99EDEEEF'x /* E0 */ toASCII = toASCII||'30313233343536373839FEFB9AF9FAFF'x /* F0 */ hextable = '000102030405060708090A0B0C0D0E0F'x /* 00 */ hextable = hextable || '101112131415161718191A1B1C1D1E1F'x /* 10 */ hextable = hextable || '202122232425262728292A2B2C2D2E2F'x /* 20 */ hextable = hextable || '303132333435363738393A3B3C3D3E3F'x /* 30 */ hextable = hextable || '404142434445464748494A4B4C4D4E4F'x /* 40 */ hextable = hextable || '505152535455565758595A5B5C5D5E5F'x /* 50 */ hextable = hextable || '606162636465666768696A6B6C6D6E6F'x /* 60 */ hextable = hextable || '707172737475767778797A7B7C7D7E7F'x /* 70 */ hextable = hextable || '808182838485868788898A8B8C8D8E8F'x /* 80 */ hextable = hextable || '909192939495969798999A9B9C9D9E9F'x /* 90 */ hextable = hextable || 'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'x /* A0 */ hextable = hextable || 'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'x /* B0 */ hextable = hextable || 'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'x /* C0 */ hextable = hextable || 'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'x /* D0 */ hextable = hextable || 'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'x /* E0 */ hextable = hextable || 'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'x /* F0 */ return /*--------------------------------------------------------------------- | See if theres any ANSI stuff to fix ------------------------------------------------------------------- */ Fix_ASA_CC: if substr(lineval,1,1) == "0" then do asafound = 1 queue blank||crlf return end if substr(lineval,1,1) == "-" then do asafound = 1 queue blank||crlf queue blank||crlf return end if substr(lineval,1,1) == "+" then do asafound = 1 skipline = 1 return end if substr(lineval,1,1) == "1" then do asafound = 1 newpage = 1 return end return /*--------------------------------------------------------------------- | Read the HLASM SYSPRINT output and trim out ANSI bytes and titles | | Note: John Ehrman, the Father of the HLASM, says that all | screen scrappers (and this is one) are living in sin! ------------------------------------------------------------------- */ Trim_HLASM_Listing: if hlasm_ingoodstuff == 0 then do if substr(lineval,4,4) == "Loc " then , hlasm_ingoodstuff = 1 hlasm_drc = hlasm_drc + 1 skipline = 1 return end if substr(lineval,1,1) == "1" then do if word(lineval,2) == "Ordinary" then do EOF = 1 say "Found 'Ordinary' stopping" end if word(lineval,2) == "Diagnostic" then do EOF = 1 say "Found 'Diagnostic' stopping" end if word(lineval,2) == "Macro" then do EOF = 1 say "Found 'Macro' stopping" end hlasm_drc = hlasm_drc + 1 skipline = 1 return end if substr(lineval,4,6) == "Active" then do hlasm_drc = hlasm_drc + 1 skipline = 1 return end if substr(lineval,4,4) == "Loc " then do hlasm_drc = hlasm_drc + 1 skipline = 1 return end return