home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 19 Printer
/
19-Printer.zip
/
psc1.zip
/
PSC.CMD
Wrap
OS/2 REXX Batch file
|
1991-01-03
|
9KB
|
177 lines
/* --------------------------------------------------------------- */
/* -- PSC .CMD (PrintSourceCode) -- */
/* --------------------------------------------------------------- */
/* -- Prints a text file on the default printer with a header -- */
/* -- showing filename, date, time, page- and line-numbers. -- */
/* -- -- */
/* -- The file is printed in NLQ, 15 cpi, 58 lines per page, -- */
/* -- and with 1" margin (using a Panasonic/Epson printer). -- */
/* -- -- */
/* -- Embedded page breaks are handled, as well as the page- -- */
/* -- break comment string 'c1 <f> c2', where c1 and c2 are -- */
/* -- beginning and ending comment delimiters respectivly. -- */
/* -- These can be: -- */
/* -- c1='/*' c2='*/' for SAS and REXX programs -- */
/* -- c1='(*' c2='*)' for Modula-2 programs -- */
/* -- (This is a leftover from source code prepared for use -- */
/* -- with SourcePrint, an old PC-DOS program I have used.) -- */
/* -- -- */
/* --------------------------------------------------------------- */
/* -- This program comes with no guarantees of any kind. It -- */
/* -- was developed for my own use, and as an illustration of -- */
/* -- what is possible to with REXX under OS/2. -- */
/* -- -- */
/* -- If you have any comments, you can reach me with e-mail -- */
/* -- at the following addresses: -- */
/* -- BitNet: berglano@orstvm.ucs.orst.edu -- */
/* -- BIX: obergland -- */
/* -- -- */
/* --------------------------------------------------------------- */
/* -- History: -- */
/* -- -- */
/* -- 02.09.90 Olvar Bergland REXX/2 -- */
/* --------------------------------------------------------------- */
/* --- check for correct syntax */
IF ARG() = 0 THEN SIGNAL syntax
/* --- initalize variables */
esc = "1B"x /* -- ESC character */
ff = "0C"x /* -- page break char */
cr = "0D"x /* -- carriage return */
zero = "00"x /* -- zero character */
linesize = 112 /* -- length of a line */
pagesize = 58 /* -- length of a page */
pageno = 1 /* -- page number */
sourceno = 1 /* -- source line number */
lineno = 1 /* -- page line number */
newpage = "<f>" /* -- page break string */
pbrk1 = "/* "||newpage||" */" /* -- page break comment */
pbrk2 = "(* "||newpage||" *)" /* -- page break comment */
topline = COPIES('─', linesize)
contline = OVERLAY(' continued ' , '─', linesize - 25, 26, '─')
eofline = OVERLAY(' end-of-file ', '─', linesize - 26, 27, '─')
dateline = STRIP(CENTER(DATE() TIME('C'),linesize),"t")
/* --- check for command line options */
ARG fileid /* get filename from cmdline */
/* <f> */
/* --- does the file exist ? */
CALL STREAM fileid, C, "query exists" /* check for existence */
IF RESULT = "" /* check the result */
THEN DO
SAY ""
SAY "Couldn't find the specified file:" fileid
EXIT
END
filename = RESULT /* full filename */
SAY "File found:" filename " (FileSize:" ,
STREAM(fileid,C,'query size') "bytes.)"
/* --- check the file name size */
IF LENGTH(filename) + 3 > (linesize - LENGTH(STRIP(dateline)))/2
THEN DO
/* the filename is a little bit too long */
indx = POS('\',filename)
filename = DELSTR(filename,indx+1,LASTPOS('\',filename)-indx-1)
filename = INSERT('..',filename,indx)
END
/* --- set printer options (for Panasonic) */
CALL CHAROUT prn,esc||'m'||'02'x /* set IBM graphics I */
CALL CHAROUT prn,esc||"n" /* set NLQ */
CALL CHAROUT prn,esc||"w"||'02'x /* set 15 cpi */
CALL CHAROUT prn,esc||"l"||'08'x /* set margin */
/* could use cmdline switches for these and other options */
/* <f> */
CALL newpage /* write first header */
/* --- start main program loop */
DO WHILE LINES(fileid) > 0 /* repeat until eof */
IF lineno > pagesize /* at bottom of page */
THEN DO
CALL newpage
END
nextline = STRIP(LINEIN(fileid),"t") /* read next line */
/* --- check for embedded page breaks */
IF (POS(pbrk1,nextline) <> 0) |, /* page break comment */
(POS(pbrk2,nextline) <> 0) /* page break comment */
THEN DO
sourceno = sourceno + 1
CALL newpage
END
ELSE DO
/* --- make sure there are no hidden page breaks */
IF SUBSTR(nextline,1,1) = ff /* page break char */
THEN DO
CALL newpage
nextline = SUBSTR(nextline,2,LENGTH(nextline)-1)
END
CALL LINEOUT prn, RIGHT(sourceno,6) ": " nextline /* print */
sourceno = sourceno + 1
lineno = lineno + 1
END
END /* end of WHILE loop */
/* --- write end of file comments to printer */
CALL LINEOUT prn,"" /* extra line */
DO WHILE lineno <= pagesize
CALL LINEOUT prn,"" /* extra line */
lineno = lineno + 1
END
CALL LINEOUT prn, eofline /* continuation line */
/* --- clean up & reset the printer */
CALL CHAROUT prn,esc||"l"||zero /* reset margin */
CALL CHAROUT prn,esc||"P" /* select draft mode */
CALL CHAROUT prn,esc||"w"||zero /* select 10 cpi */
CALL CHAROUT prn,esc||'m'||zero /* select standard mode*/
CALL CHAROUT prn,ff /* top of next page */
CALL CHAROUT prn,cr /* empty print buffer */
CALL LINEOUT fileid /* close input file */
CALL LINEOUT prn /* close printer */
EXIT /* -- end of main -- */
/* <f> */
/* --- subroutine for newpage -- */
newpage:
/* -- use ANSI sequence to stay at the same location */
CALL CHAROUT con, esc||'[s' /* report progress */
CALL CHAROUT con, "Printing Page" pageno /* */
CALL CHAROUT con, esc||'[u'
IF pageno \= 1
THEN DO
CALL LINEOUT prn,"" /* extra line */
DO WHILE lineno <= pagesize
CALL LINEOUT prn,"" /* extra line */
lineno = lineno + 1
END
CALL LINEOUT prn, contline /* continuation line */
CALL CHAROUT prn,ff /* form-feed char */
END
CALL LINEOUT prn,"" /* extra line */
pageline = RIGHT("Page" FORMAT(pageno,3),linesize)
finalline = OVERLAY(filename,OVERLAY(dateline,pageline))
CALL LINEOUT prn,finalline
CALL LINEOUT prn,topline
CALL LINEOUT prn,""
pageno = pageno + 1
lineno = 1
RETURN /* -- end of subroutine -- */
/* --- incorrect syntax -- */
syntax:
SAY ""
SAY "Usage: PSC filename"
EXIT
END /* -- end of subroutine -- */