	.TITLE	RUNOFF
/
/  16 MAY 78 (005; PDH) MAKE SIMPLE I/O CHANGES FOR MULTIACCESS
/  10 FEB 77 (004; PDH) DEBUG THE PROGRAM
/   9 FEB 77 - PAUL HENDERSON
/
/  A PROGRAM TO ALLOW ONE TO LIST SEVERAL COPIES OF THE SAME FILE, WITH
/  THE OPTION OF INSERTING FORM FEEDS BEFORE '.TITLE', AFTER '.EJECT',
/  AND/OR EVERY 57 LINES.
/
/  INVOCATION SEQUENCE:		$REQ RUNOFF
/				OPT_NAME[ EXT]
/
/  WHERE OPT = N TO INHIBIT FORM FEEDS
/	 OPT = DECIMAL NUMBER OF COPIES
/
/	 ALL CHARACTERS OTHER THAN 'N' AND '0-9' ARE IGNORED
/
/  DEFAULTS ARE 1 COPY WITH FORM FEEDS; EXTENSION 'SRC'
/
/  1)	'9_LETTER'  PRODUCES 9 COPIES WITH FORM FEEDS OF FILE 'LETTER SRC'
/  2)	'N_GRAPH LST' PRODUCES 1 COPY, NO FORM FEEDS, OF FILE 'GRAPH LST'
/  3)	'N15_A'  PRODUCES 15 COPIES, NO FORM FEEDS, OF FILE 'A SRC'
/  4)	'_BB'   PRODUCES 1 COPY WITH FORM FEEDS OF FILE 'BB SRC'
/  5)	'11N8_C' PRODUCES 118 COPIES, NO FORM FEEDS, OF FILE 'C SRC'
/
/  A FORM FEED IS OUTPUT BEFORE THE FIRST FILE, BETWEEN FILES, AND
/  AFTER THE LAST FILE.
/
	.EJECT
	.DEC
RK=17
LP=6		/ LP ALWAYS ON LUN 6 WITH MULTIACC3ESS		/(005)
TTO=13
TTI=12
MCR=4		/ CHANGE TO 4 FOR INTERACTIVE USERS		/(005)
PAGESZ=57		/ 57 LINES PER PAGE
	.OCT
OLMQ=642000		/ MQ=AC!MQ
IDX=ISZ		/ INDEX A PPOINTER, SKIP NOT EXPECTED
SET=ISZ			/ SET A FLAG NON-ZERO
X14=14
/
ILD=713000	/ SINGLE INTEGER LOAD
IMP=711400	/ INTEGER MULTIPLY
IAD=716000	/ INTEGER ADD
IST=713600	/ SINGLE INTEGER STORE
/
	.GLOBL	UNPACK
/
RUNOFF	CAL	WRITEC		/ 'RUNOFF>'
	SET	FFLAG		/ SET FORM FEED SWITCH
	DZM	NUMBER		/ INITIALIZE LOCATION WHERE WE BUILD # COPIES
	LAW	-1
	DAC	COPIES		/ DEFAULTS TO 1 COPY
	JMS	WTFOR		/ WAIT FOR PROMPT TO FINISH
	CAL	READCM		/ READ COMMAND
	JMS	WTFOR
	LAC	(LINE+2
	DAC	UNPCKC+1
	LAC	(IMAGE-1
	DAC*	(X14
	IAC
	DAC	UNPCKC+2
UNPCKC	JMS*	UNPACK		/ UNPACK COMMAND LINE
	0; 0
	SMA
	JMP	UNPCKC
/
	.EJECT
GETOPT	JMS	GETCHR		/ GET NEXT OPTION CHARACTER
	JMP	CMDERR		/ LINE TERMINATOR ILLEGAL NOW
	SAD	(137		/ '_' OPTION TERMINATOR?
	JMP	GETNAME		/ YES.  GET THE NAME NOW
	SAD	(116		/ 'N'
	DZM	FFLAG		/ CLEAR FORM FEED SWITCH
	AAC	-60
	SPA
	JMP	GETOPT		/ CHAR .LT. '0'; IGNORE IT
	AAC	60-71
	SMA!SZA
	JMP	GETOPT		/ CHAR .GT. '9'; IGNORE IT
	AAC	11		/ CONVERT DIGIT TO OCTAL REPRESENTATION
	DAC	GETC		/ HANDY PLACE FOR TEMPORARY STORAGE
	ILD;	NUMBER
	IMP;	TEN
	IAD;	GETC
	IST;	NUMBER		/ NUMBER = NUMBER*10 + GETC
	IST+3;	COPIES		/ COPIES = -NUMBER
	JMP	GETOPT
/
	.EJECT
GETNAME	CLX
	DZM	SEEK+4		/ IN CASE OF SHORT FILE NAME
	LAC	SRC
	DAC	SEEK+5		/ DEFAULT EXTENSION IS 'SRC'
	JMS	GETCHR		/ GET 1ST CHARACTER
	JMP	CMDERR		/ LINE TERMINATOR ILLEGAL HERE
	SAD	(40
	JMP	CMDERR		/ ALSO SPACE
	CLQ!LRS	6
	LAC	(GETEXT		/ GET EXTENSION IF SPACE ENCOUNTERED
	DAC	SPEXIT
	JMS	GETC		/ 2ND CHAR
	ALSS	6
	OLMQ
	JMS	GETC		/ 3RD CHAR
	OLMQ			/ 3 CHARACTERS MUST BE IN MQ
	LACQ			/ IN CASE 4TH CHAR IS LINE TERMINATOR
	DAC	SEEK+3,X
	JMS	GETC		/ 4TH CHAR
	AXR	1
	CLQ!LRS	6
	JMS	GETC		/ 5TH CHAR
	ALSS	6
	OLMQ
	JMS	GETC		/ 6TH CHAR
	OLMQ
	JMS	GETC		/ SHOULD BE SPACE OR TERMINATOR
	JMP	CMDERR		/ OTHERWISE FILE NAME TOO LONG
/
GETEXT	LACQ
	DAC	SEEK+3,X	/ PUT AWAY FILE NAME
	LAC	(2
	PAX
	LAC	(CMDERR		/ NO SPACE ALLOWED IN EXTENSION
	DAC	SPEXIT
	JMS	GETC		/ 7TH CHAR
	CLQ!LRS	6
	JMS	GETC		/ 8TH CHAR
	ALSS	6
	OLMQ
	JMS	GETC		/ 9TH (AND LAST) CHAR
	OLMQ
/
GOTNAME	LACQ
	DAC	SEEK+3,X	/ PUT AWAY FILE NAME OR EXTENSION
/
	.EJECT
LOOPA	CAL	SEEK
	LAW	-1		/ IGNORE '.TITLE' WHEN IN
	DAC	TITLSW		/ FIRST LINE OF FILE
	LAW	-PAGESZ
	DAC	FFCNT		/ RESET LINES PER PAGE COUNTER
	LAC	FFLAG
	SNA
	DZM	FFCNT		/ COUNT NEVER EXPIRES IF NO FORM FEEDS
	JMS	WTFOR
	CAL	WRFF		/ BEGIN WITH FORM FEED
/
LOOPB	CAL	READ		/ READ A LINE OF THE INPUT FILE
	JMS	WTFOR
	LAC	LINE
	AND	(7
	SAD	(2
	SKP
	JMP	ENDFIL		/ END OF FILE ENCOUNTERED
	LAC	FFLAG
	SNA
	JMP	PRINT		/ NO CHECKING OF NO FORM FEEDS
	LAW	774000
	AND	LINE+2
	SAD	FORMFD+2	/ CHECK FOR FORM FEED
	JMP	TIRSET		/ RESET LINES PER PAGE COUNTER IF YES
	LAC	(LINE+2
	DAC	UNPCKL+1
	LAC	(IMAGE-1
	DAC*	(X14
	IAC
	DAC	UNPCKL+2
UNPCKL	JMS*	UNPACK		/ UNPACK LINE OF FILE
	0; 0
	SMA
	JMP	UNPCKL
/
LOOK	JMS	CHEKSP		/ FETCH CHARACTER & CHECK FOR SPACE, ETC
	SAD	(11		/ DO WE HAVE A TAB?
	JMP	CHECK
	JMP	LOOK		/ NOT FOUND.  TRY AGAIN
/
	.EJECT
CHECK	JMS	CHEKSP
	SAD	(56		/ '.'
	SKP
	JMP	PRINT		/ COMPARISON FAILS
	CLX
	LAC	(4		/ WE MAY HAVE A MATCH.
	PAL			/ PREPARE TO COMPARE FURTHER
	LAC*	X14
	SAD	(105		/ 'E'
	JMP	EJCHEK
	SAD	(124		/ 'T'
	SKP
	JMP	PRINT		/ DIDN'T MAKE IT
/
TICHEK	LAC*	X14
	SAD	TILINE,X	/ COMPARE AGAINST 'ITLE'
	SKP
	JMP	PRINT		/ COMPARISON FAILS
	AXS	1
	JMP	TICHEK
	ISZ	TITLSW		/ SKIPS ONLY IF THIS IS 1ST LINE OF FILE
	CAL	WRFF		/ FORM FEED PRECEEDS '.TITLE'
TIRSET	LAW	-PAGESZ
	DAC	FFCNT		/ RESET LINES PER PAGE COUNTER
	JMP	PRINT
/
EJCHEK	LAC*	X14
	SAD	EJLINE,X	/ COMPARE AGAINS 'JECT'
	SKP!CLC
	JMP	PRINT
	AXS	1
	JMP	EJCHEK
	DAC	FFCNT		/ FORCES EXPIRY AFTER '.EJECT'
/
	.EJECT
PRINT	CAL	WRITEL		/ OUTPUT THE LINE
	DZM	TITLSW		/ CLEAR THE 'IGNORE TITLE 1ST TIME' SWITCH
	JMS	WTFOR
	ISZ	FFCNT
	JMP	LOOPB
	CAL	WRFF		/ FORM FEED WHEN PAGE FULL
	LAW	-PAGESZ
	DAC	FFCNT		/ RESET LINES PER PAGE COUNTER
	JMP	LOOPB
/
ENDFIL	CAL	CLOSE		/ CLOSE INPUT FILE ON DISK
	JMS	WTFOR
	ISZ	COPIES
	JMP	LOOPA		/ ANOTHER COPY YET TO PRINT
	CAL	WREND		/ OUTPUT FINAL MESSAGE TO PRINTER
EXIT	JMS	WTFOR
	CAL	(10		/ THEN EXIT
/
CMDERR	CAL	WRCMER		/ 'ERROR IN COMMAND STRING'
	JMP	EXIT
/
	.EJECT
/  SUBROUTINE TO FETCH THE NEXT CHARACTER FROM THE IMAGE LINE
/
/  CALLING SEQUENCE:
/
/	JMS	GETCHR
/	(RETURN IF LINE TERMINATOR FOUND)
/	(NORMAL RETURN)
/
GETCHR	XX
	LAC*	X14		/ GET NEXT CHARACTER
	SAD	(15		/ IS IT CARRIAGE RETURN
	SKP
	SAD	(175		/ OR ALT MODE?
	SKP
	IDX	GETCHR		/ INDEX RETURN ADDRESS OF NOT
	JMP*	GETCHR
/
/  SUBROUTINE TO RETURN THE NEXT CHARACTER IN .SIXBT FROM THE IMAGE
/  LINE.  IF A TERMINATOR IS FOUND, CONTROL BRANCHES TO 'GOTNAME'.
/  IF A SPACE IS ENCOUNTERED, CONTROL IS TRANSFERRED VIA THE ADDRESS
/  CONTAINED IN 'SPEXIT'
/
/  CALLING SEQUENCE:
/
/	JMS	GETC
/	(RETURNIF CHAR NOT SPACE, CR, ALTMODE)
/
GETC	XX
	JMS	GETCHR
	JMP	GOTNAME		/ LINE TERMINATOR ENCOUNTERED
	SAD	(40
	JMP*	SPEXIT		/ SPACE ENCOUNTERED
	AND	(77
	JMP*	GETC
/
	.EJECT
/  SUBROUTINE TO FETCH THE NEXT CHARACTER FROM THE IMAGE LINE.  IF A
/  SPACE IS ENCOUNTERED, CONTROLIS TRANSFERRED TO 'CHECK'.  IF A
/  LINE TERMINATOR IS ENCOUNTERED, CONTROL TRANSFERS TO 'PRINT'.
/  THE PURPOSE OF THIS SUBROUTINE IS TO BYPASS SPACES.
/
CHEKSP	XX
	LAC*	X14		/ GET NEXT CHARACTER
	SAD	(40
	JMP	CHECK
	SAD	(15
	SKP
	SAD	(175
	JMP	PRINT		/ LINE TERMINATOR MEANS PRINT THE LINE
	JMP*	CHEKSP
/
/  SUBROUTINE TO WAIT FOR AN EVENT VARIABLE, AND ISSUE AN ERROR MESSAGE
/  IF THE EVENT VARIABLE IS NOT ACCEPTABLE.
/
WTFOR	XX
	CAL	WAITFR
	LAC	EV
	SMA!TCA
	JMP*	WTFOR		/ GOOD EV.  RETURN
	CLQ!LRS	11		/ SHIFT BAD EV TO UPPER HALF OF MQ
	LAC	(6		/ OCTAL TO ASCII CONVERSION
	LLSS	3		/ SHIFT IN FIRST DIGIT
	ALSS	4
	XOR	(6		/ CONVERSION FOR 2ND DIGIT
	LLSS	3
	ALSS	4
	XOR	(6		/ CONVERSION FOR 3RD DIGIT
	DAC	ERRB		/ PUT IN LINE BUFFER
	LACQ
	XOR	CR		/ APPEND CARRIAGE RETURN
	DAC	ERRB+1
	CAL	WRERR
	CAL	WAITFR		/ DON'T CARE ABOUT EV
	CAL	(10		/ EXIT AFTER ANNOUNCEMENT
/
	.EJECT
/  LINE BUFFERS AND ASCII MESSAGES
/
TEN	12
SRC	.SIXBT	'SRC'
LINE	.BLOCK	64
	.ASCII	<15>		/ IN CASE OF LINE BUFFER OVERFLOW
COPIES=.-1
IMAGE	.BLOCK	200
PROMPT	PR-.*400+2;FFLAG;	.ASCII	'RUNOFF>'<175> ;PR=.
FORMFD	2002;TITLSW	;	.ASCII	<14><0><0><0><15>
CR=.-1;EV
END	ED-.*400+2;FFCNT;	.ASCII	<14>'END OF RUNOFF'<15> ;ED=.
ERRCMD	EC-.*400+2;NUMBER;	.ASCII	'ERROR IN COMMAND STRING'<15> ;EC=.
ERRL	EL-.*400+2;SPEXIT;	.ASCII	'RUNOFF I/O ERROR '
ERRB	.BLOCK	2 ;EL=.
EJLINE	112; 105; 103; 124	/ (.E)'JECT'
TILINE	111; 124; 114; 105	/ (.T)'ITLE'
	.EJECT
/  CAL PARAMETER BLOCKS
/
WRITEC	2700;	EV;	TTO; 2; PROMPT
READCM	2600;	EV;	TTI; 2; LINE; 42
SEEK	3200;	EV;	 RK; .BLOCK 3
WAITFR	  20;	EV
READ	2600;	EV;	 RK; 2; LINE; 64
WRFF	2700;	 0;	 LP; 2; FORMFD
WRITEL	2700;	EV;	 LP; 2; LINE
CLOSE	3400;	EV;	 RK
WRCMER	2700;	EV;	TTO; 2; ERRCMD
WRERR	2700;	EV;	MCR; 2; ERRL
WREND	2700;	EV;	 LP; 2; END
	.END	RUNOFF
