/********************* rexx ****************************************/ /* (c) Copyright Roger Lacroix 1992 | | | | Designed, developed and programmed by Roger Lacroix | +-------------------------------------------------------------------+ | | | PRT.CMD V1.00 | | | | This program will print a file in portrait or landscape mode. | | You can also print the file in double-sided mode (Your printer | | must support it). This program has only been tested with | | HP LaserJet printers. | | | | Requirements: | | This programs requires any version of rexx. | | | | Restrictions: | | None | | | | Useability: | | This programs can be run from any of the following locations: | | - Floppy drive "A:" | | - Hard drive "C:" | | - LAN drive "Y:" | | | +------------------------------------------------------------------*/ Trace o PARSE ARG cmd_parameters '@echo off' /*-----------------------------------------+ | First we must initialize all constants. | +-----------------------------------------*/ CALL INIT_VARIABLES /*-----------------------------------+ | Validate command line parameters. | +-----------------------------------*/ CALL PARSE_PARAMETERS 'CMD',cmd_parameters IF exit_pgm = 'NO' THEN DO /*+-----------------+ | Load REXXUTIL | +-----------------+*/ IF RxFuncQuery("sysloadfuncs") THEN DO CALL RxFuncAdd sysloadfuncs, rexxutil, sysloadfuncs END ELSE NOP CALL SysLoadFuncs CALL GET_FILE_LIST /*----------------------+ | Mainline | +----------------------*/ DO df=1 to dirfile.0 oldinput. = '' in_file = SUBSTR(dirfile.df,38,) SAY in_file CALL GET_FILE IF file_ok = 'Y' THEN DO CALL PRINT_FILE END ELSE DO SAY '*** File 'in_file' does NOT exist!!' END END SAY ' 'dirfile.0' file(s) printed.' END ELSE NOP RETURN /* exit the program */ /*---------------------------------+ | Valid the inputted parameters. | +---------------------------------*/ PARSE_PARAMETERS: PARSE ARG type,parameters parameters = TRANSLATE(parameters) SELECT WHEN parameters = '' THEN DO CALL WARN_USER END WHEN POS('?',parameters) <> 0 THEN DO CALL WARN_USER END WHEN POS('/',parameters) = 0 THEN DO in_file = STRIP(parameters) END OTHERWISE DO continue = 'YES' /* must be more than 1 word and last word must not contain any slashes '/' */ IF WORDS(parameters) = 1 | POS('/',WORD(parameters,WORDS(parameters))) <> 0 THEN DO CALL WARN_USER continue = 'NO' END ELSE DO in_file = STRIP(WORD(parameters,WORDS(parameters))) /* last word is in_file */ END nx = 1 DO WHILE continue = 'YES' nn = POS('/',parameters,nx) SELECT WHEN nn = 0 THEN DO continue = 'NO' END WHEN SUBSTR(parameters,nn,2) ='/D' THEN DO nx = VERIFY(parameters,'/ ',M,nn+2) double_sided = 'YES' END WHEN SUBSTR(parameters,nn,3) ='/C:' THEN DO nx = VERIFY(parameters,'/ ',M,nn+3) col_page = STRIP(SUBSTR(parameters,nn+3,nx-nn-3)) style = 'NONE' END WHEN SUBSTR(parameters,nn,3) ='/L:' THEN DO nx = VERIFY(parameters,'/ ',M,nn+3) lines_page = STRIP(SUBSTR(parameters,nn+3,nx-nn-3)) style = 'NONE' END WHEN SUBSTR(parameters,nn,3) ='/P:' THEN DO nx = VERIFY(parameters,'/ ',M,nn+3) printer = STRIP(SUBSTR(parameters,nn+3,nx-nn-3)) END WHEN SUBSTR(parameters,nn,3) ='/S:' THEN DO nx = VERIFY(parameters,'/ ',M,nn+3) style = STRIP(SUBSTR(parameters,nn+3,nx-nn-3)) END OTHERWISE DO CALL WARN_USER continue = 'NO' END END /* select */ END END END /* select */ IF POS(printer,prt_sel) = 0 | DATATYPE(lines_page) <> 'NUM' | DATATYPE(col_page) <> 'NUM' | POS(style,sty_sel) = 0 THEN DO CALL WARN_USER END ELSE NOP RETURN /*+-----------------------------------+ | Tell user about input parameters | +-----------------------------------+*/ WARN_USER: SAY "Use the PRT command to send a file to a printer." SAY " " SAY "SYNTAX:" SAY "PRT [/P:printer] [/D] [/L:ll] [/C:cc] [/S:style] [drive:][path]filename" SAY " " SAY "Where:" SAY " /D Output will be printed double sided." SAY " /C:columns Specifies the number of columns per page, i.e. /C:80 " SAY " /L:lines Specifies the number of lines per page, i.e. /L:66 " SAY " /P:printer Specifies a print device, i.e. /P:LPT1." SAY " /S:style Specifies a style, i.e. /S:P12" SAY " Portait style printing:" SAY " P10 is 80*60 (column * row)" SAY " P12 is 96*60" SAY " P16 is 134*66" SAY " Landscape style printing:" SAY " L10 is 106*45 (column * row)" SAY " L12 is 128*45" SAY " L16 is 177*45" exit_pgm = 'YES' RETURN /*+-------------------------------------------+ | get a file list of the requested type | | i.e. *.* or *.cmd or gdm*.* | +-------------------------------------------+*/ GET_FILE_LIST: CALL SysFileTree in_file, 'dirfile', 'F' RETURN /*+-----------------------------------+ | read file | +-----------------------------------+*/ GET_FILE: IF STREAM(in_file,'C','QUERY EXIST') <> ' ' THEN DO file_ok = 'Y' i = 1 DO UNTIL LINES(in_file) = 0 /* read the user's data file */ oldinput.i = LINEIN(in_file) i = i +1 END nothing = STREAM(in_file,'C','CLOSE') /* close the file */ oldinput.0 = i - 1 END ELSE DO file_ok = 'N' END RETURN /*-----------------------------+ | Write data to the printer. | +-----------------------------*/ PRINT_FILE: IF double_sided ='YES' THEN DO CALL CHAROUT printer,font.d_sided END ELSE NOP CALL CHAROUT printer,font.style CALL SET_PAGE_SIZE page = (oldinput.0 % (lines_page - header.0)) + 1 /* number of pages */ r_lines = oldinput.0 // (lines_page - header.0) /* remaining lines on last page */ header.0 = 4 header.1 = '+'COPIES('-',col_page-2)'+' header.2 = '|'in_file' 'SUBSTR(dirfile.df,1,16) header.2 = OVERLAY('|',header.2,col_page) header.3 = '+'COPIES('-',col_page-2)'+' header.4 = '+'COPIES('-',col_page-2)'+' ii=1 DO i=1 to page -1 header.2 = OVERLAY(' Page 'i' of 'page,header.2,col_page-LENGTH(' Page 'i' of 'page)) DO j=1 to header.0 -1 CALL LINEOUT printer,header.j END DO j=1 to lines_page - header.0 nothing = LINEOUT(printer,'|'SUBSTR(oldinput.ii,1,col_page-2)'|') ii=ii+1 END /* print last line on page AND add page eject, carridge return */ CALL CHAROUT printer,header.4''page_eject_CR END IF r_lines <> 0 THEN DO header.2 = OVERLAY(' Page 'page' of 'page,header.2,col_page-LENGTH(' Page 'page' of 'page)) DO j=1 to header.0 -1 CALL LINEOUT printer,header.j END DO j=1 to r_lines nothing = LINEOUT(printer,'|'SUBSTR(oldinput.ii,1,col_page-2)'|') ii=ii+1 END /* print last line on page AND add page eject, carridge return */ CALL CHAROUT printer,header.4''page_eject_CR END ELSE NOP nothing = STREAM(printer,'C','CLOSE') /* close the file */ RETURN 0 /*----------------------------+ | Set lines and columns size | +----------------------------*/ SET_PAGE_SIZE: SELECT WHEN style = 'P10' THEN DO lines_page = 60 col_page = 80 END WHEN style = 'P12' THEN DO lines_page = 60 col_page = 96 END WHEN style = 'P16' THEN DO lines_page = 66 col_page = 134 END WHEN style = 'L10' THEN DO lines_page = 45 col_page = 106 END WHEN style = 'L12' THEN DO lines_page = 45 col_page = 128 END WHEN style = 'L16' THEN DO lines_page = 45 col_page = 177 END OTHERWISE NOP END /* select */ RETURN 0 /*----------------------------+ | Initialize all constants. | +----------------------------*/ INIT_VARIABLES: exit_pgm = 'NO' yesno = 'YyNn' numbers = '0123456789' seperators = ';:.,/\' /* valid seperators for os/2 environment variable */ upper_alpha='ABCDEFGHIJKLMNOPQRSTUVWXYZ' lower_alpha='abcdefghijklmnopqrstuvwxyz' hex_code='0001020304050607080910111213141516171819'X under_fix =D2C(27)''D2C(38)''D2C(100)''D2C(48)''D2C(68) under_float=D2C(27)''D2C(38)''D2C(100)''D2C(51)''D2C(68) /* this is the good one */ under_off =D2C(27)''D2C(38)''D2C(100)''D2C(64) page_eject_CR = '0C0D'X printer='LPT1' col_page = 80 lines_page = 66 style = 'P10' prt_sel = 'PRN LPT1 LPT2 LPT3' sty_sel = 'NONE P10 P12 P16 L10 L12 L16' font.default = '' font.L10 = '1B401B28733130481B266C36441B266C314F'X font.L12 = '1B401B28733132481B266C36441B266C314F'X font.L16 = '1B401B28733136481B266C38441B266C314F'X font.P10 = '1B401B28733130481B266C36441B266C304F'X font.P12 = '1B401B28733132481B266C36441B266C304F'X font.P16 = '1B401B28733136481B266C304F1B266C304F'X double_sided = 'NO' font.d_sided = '1B451B266C6C3173'X header.0 = 4 RETURN