Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-10 - 43,50522/biblio.mac
There is 1 other file named biblio.mac in the archive. Click here to see a list.
Comment/
	BIBLIO is a program to create, maintain, search through, and
edit bibliographical entries.
It was written by Mike Rubin of the Wesleyan Computing Center in
June, 1979.
/
	TITLE BIBLIO
	TWOSEG				;MAKE BIBLIO SHARABLE
	SALL				;SUPPRESS TEXT EXPANSION OF MACROS

SUBTTL DEFINITIONS
;
F=0					;FLAG REGISTER
T1=1					;TEMPORARY REGISTER 1
T2=2					;TEMPORARY REGISTER 2
T3=3					;TEMPORARY REGISTER 3
T4=4					;TEMPORARY REGISTER 4
CT=5					;COUNTER
BK=6					;BLOCK OF FILE
OF=7					;ARGUMENT FLAG REGISTER
CH=10					;CHANNEL
C=11					;CHARACTER
I=12					;INSTRUCTION
A=16					;ARGUMENT REGISTER
P=17					;PUSHDOWN STACK
;
FLINFD==1				;LINE-FEED FLAG
FLFAIL==2				;LOOKUP-FAILURE FLAG
FDELIM==4				;DELIMITER FLAG
FMATCH==10				;CHARACTER MATCH MADE
FEOF==20				;EOF REACHED
;
;PARAMETERS
VERNUM==2				;VERSION NUMBER
STAKSZ==15				;PUSHDOWN STACK SIZE
WORDS==^D80/5+1				;SIZE OF SEARCH STRING (80 CHARS)
TTYSIZ==^D83				;TTY BUFFER SIZE (BYTES)
MAXCHN==5				;MAX NUMBER OF FILE CHANNELS
;
DATCHI==0				;DATA FILE INPUT CHANNEL
DATCHO==1				;DATA FILE OUTPUT CHANNEL
HLPI==2					;HELP FILE INPUT CHANNEL
LPTO==3					;LPT OUTPUT CHANNEL
EDITO==4				;TEMP EDIT FILE OUTPUT CHANNEL
;
HT==11
LF==12
VT==13
FF==14
CR==15
CONZ==32				;CONTROL-Z
ESC==33
SPACE==40
POINT==56
COLON==72
SUBTTL IMPURE AREA
;
	LOC 137
.JBVER:	BYTE (3)(9)VERNUM		;SET VERSION NUMBER
	RELOC
;
PDSTK:	BLOCK STAKSZ			;SUBROUTINE PUSHDOWN STACK
OBUF:
IBUF:	BLOCK MAXCHN*3			;INPUT OR OUTPUT BUFFER RING HEADERS
DFILE:	BLOCK 2				;LOOKUP BLOCK FOR DATA FILE
STRING:	BLOCK WORDS			;SEARCH STRING
BLTAC:	Z				;TEMP STORAGE FOR AC FOR BLT INSTRUC
OUTCHN:	Z				;OUTPUT CHANNEL FOR EDIT SUBROUTINES
ENBKFF:	Z				;BLOCK OF FF AT END OF ENTRY
BLOKC:	Z				;BLOCK OF LAST COLON SEEN
STBKFF:	Z				;BLOCK OF FF AT START OF ENTRY
STBFFF:	Z				;BUFFER POSITION OF FF AT START OF ENTRY
ENBFFF:	Z				;BUFFER POSITION OF FF AT END OF ENTRY
BUFRC:	Z				;BUFFER POSITION OF LAST COLON SEEN
STRPTR:	Z				;POINTER TO NEXT WORD OF SEARCH STRING
DISIND:	Z				;COMMAND DISPATCH INDEX
RETADR:	Z				;TEMP STORAGE FOR VARIABLE RET ADDRESS
TTYHDR:	BLOCK 2				;TTY BUFFER HEADER
TTYBUF:	BLOCK TTYSIZ/5+1		;TTY BUFFER (INTERNAL)
	SUBTTL INITIALIZE I/O
	RELOC 400000			;START CODE IN HIGH SEGMENT
START:	MOVE	P,STKSET		;SET UP PUSHDOWN STACK
;
COMMENT/
	Open channels for data file input, data file output, and help file
input.  Set up one buffer on each of these channels.
/
;
	RESET				;CLEAR ALL I/O FLAGS
	SETZB	T1,T2			;MODE ASCII
	TLO	T2,(SIXBIT/DSK/)	;DEVICE DSK
	MOVEI	CH,DATCHI		;DATA FILE INPUT CHANNEL
	MOVE	T3,CH			;COMPUTE INDEX OF BUFFER RING HEADER
	IMULI	T3,3
	HRRZI	T3,IBUF(T3)		;ADDRESS OF INPUT BUFFER RING HEADER
	PUSHJ	P,OPNCHN		;OPEN CHANNEL FOR INPUT TO DATA FILE
	INBUF	DATCHI,1		;SET UP 1 INPUT BUFFER FOR DATA FILE
	SETZB	T1,T2			;MODE ASCII
	TLO	T2,(SIXBIT/DSK/)	;DEVICE DSK
	MOVEI	CH,DATCHO		;DATA FILE OUTPUT CHANNEL
	MOVE	T3,CH			;COMPUTE INDEX
	IMULI	T3,3
	HRLZI	T3,OBUF(T3)		;ADDRESS OF OUTPUT BUFFER RING HEADER
	PUSHJ	P,OPNCHN		;OPEN CHANNEL FOR OUTPUT TO DATA FILE
	OUTBUF	DATCHO,1		;SET UP 1 OUTPUT BUFFER FOR DATA FILE
	SETZB	T1,T2			;MODE ASCII
	TLO	T2,(SIXBIT/HLP/)	;DEVICE HLP
	MOVEI	CH,HLPI			;HELP FILE INPUT CHANNEL
	MOVE	T3,CH			;COMPUTE INDEX
	IMULI	T3,3
	HRRZI	T3,IBUF(T3)		;ADDRESS OF INPUT BUFFER RING HEADER
	PUSHJ	P,OPNCHN		;OPEN CHANNEL FOR INPUT FROM HELP FILE
	INBUF	HLPI,1			;SET UP 1 INPUT BUFFER FOR HELP FILE
	SUBTTL INPUT DATA FILE NAME
;
COMMENT/
	Get a valid data file name, initialize all flags and pointers to
beginning of file, and LOOKUP the data file.  If the file is not found,
set LOOKUP fails flag; if found, check first character for validity (".").
/
INPNAM:	SETZB	F,OF			;ZERO OUT FLAG REGISTERS
	TRO	F,FEOF			;FLAG THAT NO STRING GIVEN YET
	MOVE	T1,TTYPTR		;BYTE POINTER TO TTY BUFFER
	MOVEM	T1,TTYHDR		;STORE IN FIRST WORD OF TTY HEADER
	MOVEI	T1,TTYSIZ		;SIZE OF TTY BUFFER
	MOVEM	T1,TTYHDR+1		;STORE IN SECOND WORD OF TTY HEADER
	SETOM	STBKFF			;FLAG THAT ON FIRST ENTRY
	SETZM	DFILE			;CLEAR FILE NAME
	SETZM	DFILE+1
	MOVEI	CT,6			;INITIALIZE CHAR COUNT FOR FILE NAME
	MOVE	T1,FILPTR		;GET POINTER TO FILE NAME
	OUTSTR[ASCIZ/
Data file name: /]
NXTNAM:	INCHWL	C			;GET A CHAR FROM TTY
	CAIN	C,POINT			;SEE IF A POINT
	  JRST	GETEXT			;YES. GO GET THE EXTENSION
	PUSHJ	P,EOLDEL		;SEE IF CHAR IS AN EOL DELIM
	  JRST	LOKDAT			;YES. GO LOOKUP FILE
	PUSHJ	P,ALPNUM		;IS CHAR ALPHANUMERIC?
	  JRST	ILNAME
	SOSGE	CT			;DECREMENT COUNT - CONT IF NOT 6 CHRS
	  JRST	ILNAME			;HERE IF >6 CHARS
	SUBI	C,40			;MAKE CHAR SIXBIT
	IDPB	C,T1			;AND DEPOSIT CHAR IN FILE NAME
	JRST	NXTNAM			;GO BACK FOR NEXT CHAR
GETEXT:	MOVEI	CT,3			;SET UP COUNTER FOR EXTENSION
	MOVE	T1,EXTPTR		;GET POINTER TO FILE EXTENSION
GETEX1:	INCHWL	C			;AND GET A CHAR
	PUSHJ	P,EOLDEL		;SEE IF CHAR IS AN EOL DELIM
	  JRST	LOKDAT			;YES. GO LOOKUP FILE
	PUSHJ	P,ALPNUM		;MAKE SURE ALPHANUMERIC
	  JRST	ILNAME			;NO. ILLEGAL FILE NAME
	SUBI	C,40			;MAKE CHAR SIXBIT
	IDPB	C,T1			;DEPOSIT CHAR IN EXTENSION
	SOJG	CT,GETEX1		;AND GO BACK FOR REST OF EXTENSION
	JRST	LOKDAT			;AND GO LOOKUP THE FILE
;CHECK IF CHAR IS ALPHANUMRIC. FIRST RETURN IF NO. SKIP RETURN IF YES.
ALPNUM:	PUSH	P,T1			;SAVE T1
	MOVE	T1,C			;SAVE C
	TRZ	C,40			;MAKE CHAR UC
	CAIL	C,"A"			;SEE IF CHAR IS ALPHA
	    CAILE	C,"Z"
	  SKIPA	C,T1			;NO. RESTORE CHAR AND SKIP
	    JRST	RESPOP		;YES. TAKE SKIP RETURN
	POP	P,T1			;RESTORE T1
	CAIL	C,"0"			;SEE IF CHAR IS NUMERIC
	  CAILE	C,"9"
	POPJ	P,			;NO. THEN ILLEGAL NAME
	  JRST	CPOPJ1			;YES. TAKE SKIP RETURN
RESPOP:	POP	P,T1			;RESTORE T1
	JRST	CPOPJ1			;AND TAKE SKIP RETURN
;CHECK IF CHAR IS EOL DELIM. NORMAL RETURN IF NO. SKIP RETURN IF YES.
EOLDEL:	PUSHJ	P,CHKDEL		;IS CHAR A DELIM?
	  JRST	CPOPJ1			;NO. TAKE SKIP RETURN
	CAILE	A,DELG			;IS CHAR AN EOL DELIM?
CPOPJ1:	  AOS	(P)			;NO. TAKE SKIP RETURN
	POPJ	P,			;YES. TAKE NORMAL RETURN
ILNAME:	OUTSTR[ASCIZ/Illegal file name
/]
	CLRBFI				;CLEAR THE TTY INPUT BUFFER
	JRST	INPNAM			;AND GO TRY AGAIN
;
LOKDAT:	CLRBFI				;EMPTY TTY INPUT BUFFER
	MOVEI	CH,DATCHI		;LOOKUP DATA FILE ON INPUT CHANNEL
	MOVE	T1,DFILE		;GET FILE NAME
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULT PPN, PROT, ETC. FIELDS
	PUSHJ	P,LOKFIL		;LOOKUP THE FILE
	    TROA	F,FLFAIL		;TURN ON LOOKUP FAILS FLAG
	  PUSHJ	P,CHKFOR		;CHECK FILE FORMAT IF THERE
	JRST	COMMND			;GO GET COMMAND
CHKFOR:	PUSHJ	P,CHRIN			;GET THE FIRST CHARACTER
	  JRST	ILFORM			;ILLEGAL FORMAT IF EOF
	CAIE	C,POINT			;MAKE SURE FIRST CHAR IS A POINT
	  JRST	ILFORM			;NO. ILLEGAL FORMAT
	PUSHJ	P,REWDAT		;REWIND THE DATA FILE
	POPJ	P,			;RETURN
;
;RESET THE STACK AFTER FATAL ERROR AND START AGAIN
RESSET:	MOVE	P,STKSET		;SET UP STACK
	PUSHJ	P,BRKTTY		;BREAK TTY OUTPUT
	JRST	COMMND			;GO GET NEXT COMMAND
SUBTTL COMMAND SCANNER
;
;GET THE INDEX OF ITEM IN TABLE <EXP>1 OF LENGTH <EXP>LG AND STORE IT IN T1.
DEFINE GETIND(EXP,ERRLBL)<
	MOVSI	T1,-EXP'LG			;GET LENGTH OF TABLE
	CAME	C,EXP'1(T1)			;LEGITIMATE MATCH?
	  AOBJN	T1,.-1				;NO. JUMP BACK IF MORE
	SKIPL	T1				;ILLEGAL COMMAND?
	  JRST	ERRLBL				;YES
>;END GETIND
;
COMMENT/
	Read command character, and store its dispatch index in DISIND.
	Read any options, and set flags occording to their indices in OF.
	Read search string, if one, and store in STRING.  One or more
successive delimiters are converted to a single ESCAPE character, and two
ESCAPE characters are stored at the end of the string.
/
COMMND:	INCHSL	C			;CLEAR CONTROL-O
	  JFCL
	OUTSTR	[ASCIZ/
Command (H for help): /]
	SETZ	T2,			;PUT OPTION FLAGS IN T2
COMD1:	INCHWL	C			;GET COMMAND
	PUSHJ	P,CHKDEL		;CHECK IF DELIMITER
	  JRST	COMDA			;COME HERE IF NOT A DELIM
	CAILE	A,DELG			;IS IT AN EOL DELIMITER?
	  JRST	COMD1			;NO. IGNORE IT.
	JRST	ERROR			;ERROR SINCE FIRST CHAR
COMDA:	TRZ	C,40			;MAKE CHARACTER UC
	GETIND	CMD,ERROR		;GET INDEX FOR DISPATCH
	MOVEM	T1,DISIND		;SAVE INDEX
COMD2:	INCHWL	C			;GET OPTION
	PUSHJ	P,CHKDEL		;GET AN ARGUMENT
	  JRST	COMDB			;NOT A DELIMITER
	CAILE	A,DELG			;IS IT AN EOL DELIM?
	  JRST	COMD2			;NO. IGNORE IT.
	JRST	CHKOPT			;GO CHECK FOR NEW OPTIONS
COMDB:	CAIN	C,COLON			;IS IT A COLON?
	  JRST	GETSTR			;YES. GO GET STRING
	TRZ	C,40			;FORCE ARGUMENT UC
	GETIND	OPT,ERROR		;GET THE FLAG FOR THE OPTION
	TRO	T2,@OPT2(T1)			;TURN ON THE FLAG
	JRST	COMD2				;AND GO GET THE NEXT ARG
;
GETSTR:	TRZ	F,FEOF			;TURN OFF EOF FLAG
	SETOM	ENBKFF			;FLAG THAT ON FIRST ENTRY
	MOVE	T1,BSTPTR		;SET UP POINTER TO STRING
	TRNE	F,FLFAIL			;SEE IF LOOKUP FAILED
	  JRST	NOTTHR				;YES. GO GET STRING
GETST1:	USETI	DATCHI,1			;POINT TO FIRST BLOCK OF FILE
	MOVEI	CH,DATCHI			;AND GET IT
	PUSHJ	P,GETBF
	  JRST	ILFORM				;SHOULD NEVER GET HERE (EOF)
	MOVEI	BK,1				;REINITIALIZE BLOCK COUNT
	INCHWL	C				;GET STRING CHARACTER
	PUSHJ	P,CHKDEL			;CHECK IF DELIMITER
	  JRST	STORE				;STORE IT IF NOT A DELIM
	CAILE	A,DELG				;IS IT AN EOL DELIMITER?
	  JRST	READ				;NO. IGNORE IT.
	JRST	ERROR				;ELSE, ILLEGAL COMMAND
STORE:	IDPB	C,T1				;WRITE THE CHAR TO STRING
	TRZ	F,FDELIM			;TURN OFF DELIM FLAG
READ:	INCHWL	C				;GET A CHAR OF STRING
	PUSHJ	P,CHKDEL			;CHECK IF A DELIMITER
	  JRST	STORE				;STORE IT IF NOT A DELIM
	MOVEI	C,ESC				;CHAR IS NOW AN ESCAPE
	TRNN	F,FDELIM			;DELIM LAST CHAR?
	  IDPB	C,T1				;NO. WRITE AN ESCAPE TO STING
	CAILE	A,DELG				;IS CHAR AN EOL DELIM?
	    TROA	F,FDELIM		;NO. TURN ON DEL FLAG AND SKIP
	  CAIA					;JUST SKIP
	    JRST	READ			;GO GET NEXT CHAR
	IDPB	C,T1				;WRITE ANOTHER ESCAPE
	MOVE	OF,T2			;LOAD OPTION FLAGS INTO REGISTER
	SKIPN	OF			;CHECK IF ANY OPTIONS GIVEN
	  SETO	OF,			;NO. SET ALL OPTION FLAGS
	JRST	EOCOM			;AND DISPATCH
;
;CHECK IF DELIMITER. STORE INDEX IN A. NORMAL RETURN IF NO. SKIP
;RETURN IF YES.
CHKDEL:	PUSH	P,T1				;SAVE T1
	GETIND	DEL,NOTDEL			;JUMP TO NOTDEL IF NOT DELIM
	HRRZ	A,T1				;GET INDEX OF DELIM
	POP	P,T1				;RESTORE T1
	JRST	CPOPJ1				;AND SKIP RETURN
NOTDEL:	POP	P,T1				;COME HERE IF NOT A DELIM
	POPJ	P,				;TAKE FIRST RETURN
;
ERROR:	OUTSTR[ASCIZ/ILLEGAL COMMAND
/]
	CLRBFI					;CLEAR TYPE-IN BUFFER
	JRST	COMMND				;AND GET NEXT COMMAND
;
CHKOPT:	SKIPE	T2				;NEW OPTIONS GIVEN?
	    SKIPA	OF,T2			;YES. STORE AS OPT FLAGS & SKIP
	  SKIPE	OF				;ANY OPTS GIVEN LAST TIME?
	    CAIA				;YES. USE SAME OPTIONS
	  SETO	OF,				;SET ALL OPTION FLAGS
EOCOM:	CLRBFI					;GET RID OF POSSIBLE LF
	MOVE	T1,DISIND			;GET DISPATCH INDEX
	JRST	@CMD2(T1)			;AND DISPATCH
;
;TELL USER FILE NOT THERE BEFORE RETURNING FOR NEXT COMMAND
;
NOTTHR:	PUSHJ	P,MAKNAM			;OUTPUT FILE NAME TO TTY
	PUSHJ	P,BRKTTY			;BREAK OUTPUT TO TTY
	OUTSTR	[ASCIZ/ does not exist.
/]						;TELL USER NOT THERE
	CLRBFI					;CLEAR TTY INPUT BUFFER
	CLOSE	DATCHI,				;CLOSE DATA FILE INPUT CHANNEL
	JRST	COMMND				;GO GET NEXT COMMAND
	SUBTTL	I/O ROUTINES
;
;OPEN A CHANNEL CONTAINED IN CH.  OPEN BLOCK IS IN T1, T2, AND T3
;
OPNCHN:	MOVEI	I,1			;Y FIELD IS AC 1
	DPB	CH,INSPTR		;DEPOSIT CHANNEL IN INSTRUCTION
	TLO	I,(OPEN)		;TEST ON OPEN INSTRUCTION
	XCT	I			;DO OPEN
	  CAIA				;SKIP IF FAILS
	POPJ	P,			;RETURN
	OUTSTR	[ASCIZ/Open fails/]
	EXIT	1,			;EXIT IF FAILS
	POPJ	P,			;ALLOW OPTION TO CONTINUE
;
;LOOKUP A FILE ON CHANNEL CONTAINED IN CH.  LOOKUP BLOCK IS IN T1, T2, T3,
;AND T4.  FIRST RETURN IF NOT FOUND. SKIP RETURN IF FOUND.
;
LOKFIL:	MOVEI	I,1			;Y FIELD IS AC 1
	DPB	CH,INSPTR		;DEPOSIT CHANNEL
	TLO	I,(LOOKUP)		;TEST ON INSTRUCTION
	XCT	I			;DO LOOKUP
	  CAIA				;SKIP IF FAILS
	JRST	CPOPJ1			;SKIP RETURN IF SUCCESSFUL
	TRNN	T2,777777		;TEST IF FILE NOT FOUND
	  POPJ	P,			;RETURN IF TRUE
	OUTSTR	[ASCIZ/Lookup fails. Error codes in rh of ac 2/]
	EXIT	1,			;EXIT IF ERROR
	POPJ	P,			;ALLOW OPTION TO CONTINUE
;
;ENTER A FILE ON CH.  ENTER BLOCK IS IN T1, T2, T3, AND T4
;
ENTFIL:	MOVEI	I,1			;Y FIELD IS AC 1
	DPB	CH,INSPTR		;DEPOSIT CHANNEL
	TLO	I,(ENTER)		;TEST ON ENTER INSTRUCTION
	XCT	I			;DO ENTER
	  CAIA				;SKIP IF ERROR
	POPJ	P,			;RETURN
	OUTSTR	[ASCIZ/Enter fails. Error codes in rh of ac 2/]
	EXIT	1,			;EXIT ON ERROR
	POPJ	P,			;OPTION TO CONTINUE
;
;RENAME A FILE ON CHANNEL CONTAINED IN CH.  RENAME BLOCK IS IN T1,T2, T3, AND T4
;
RENFIL:	MOVEI	I,1			;Y FIELD IS AC 1
	DPB	CH,INSPTR		;DEPOSIT CHANNEL
	TLO	I,(RENAME)		;TEST ON RENAME INSTRUCTION
	XCT	I			;DO RENAME
	  CAIA				;SKIP IF ERROR
	POPJ	P,			;RETURN
	OUTSTR	[ASCIZ/RENAME fails. Error codes in rh of ac 2/]
	EXIT	1,			;EXIT ON ERROR
	POPJ	P,			;OPTION TO CONTINUE
;
;READ A CHARACTER INTO C ON CHANNEL.
;FIRST RETURN IF EOF. SKIP RETURN IF SUCCESSFUL.
CHRIN:	PUSH	P,T1			;SAVE T1
	MOVE	T1,CH			;COMPUTE BUFFER INDEX
	IMULI	T1,3
GET:	SOSL	IBUF+2(T1)		;CHECK IF BUFFER EMPTY
	  JRST	GETC			;NO. GET CHARACTER
	PUSHJ	P,GETBF			;GET NEW BUFFER
	  JRST	EOFRET			;RETURN IF EOF
	JRST	GET			;START AGAIN WITH NEW BUFFER
GETC:	ILDB	C,IBUF+1(T1)		;GET CHARACTER
	JUMPE	C,GET			;LOOP BACK IF NULL
	POP	P,T1			;RESTORE T1
	JRST	CPOPJ1			;SKIP RETURN
;
;GET A NEW BUFFER ON CHANNEL CONTAINED IN CH.
;FIRST RETURN IF EOF. SKIP RETURN IF SUCCESSFUL.
;
GETBF:	CAIN	CH,DATCHI		;SEE IF DATA FILE INPUT
	  AOJ	BK,			;YES. INCREMENT BLOCK COUNT
	SETZ	I,			;LOAD IN HERE
	DPB	CH,INSPTR		;DEPOSIT CHANNEL
	TLO	I,(IN)			;TEST ON IN INSTRUCTION
	XCT	I			;DO IN
	  JRST	CPOPJ1			;SKIP RETURN IF SUCCESSFUL
	PUSH	P,T1			;SAVE T1
	AOJ	I,			;Y FIELD IS AC 1
	TLZ	I,777000		;ZERO OUT OP-CODE FIELD
	TLO	I,(GETSTS)		;TEST ON GETSTS INSTRUCTION
	XCT	I			;DO GETSTS
	TRNE	T1,1B22			;TEST FOR EOF
	  JRST	EOFRET			;GO RETURN IF EOF
	OUTSTR	[ASCIZ/In fails. Error codes in ac 1/]
	EXIT	1,			;EXIT IF ERROR
	TLZ	T1,74B23		;TURN OFF ERROR BITS
	TLZ	I,777000			;ZERO OUT OP-CODE
	TLO	I,(SETSTS)		;TEST ON SETSTS INSTRUCTION
	XCT	I			;DO SETSTS
EOFRET:	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;OUTPUT A CHARACTER IN C ON CHANNEL CONTAINED IN CH
;
CHROUT:	SKIPGE	CH			;SKIP IF NOT TTY (CH)=-1
	  JRST	TTYOUT			;GO DO TTY OUTPUT ROUTINE
	PUSH	P,T1			;SAVE T1
	MOVE	T1,CH			;COMPUTE BUFFER INDEX
	IMULI	T1,3
PUT:	SOSG	OBUF+2(T1)		;BUFFER FULL?
	  PUSHJ	P,PUTBF			;YES. GO OUTPUT IT
PUTC:	IDPB	C,OBUF+1(T1)		;DEPOSIT A CHAR IN BUFFER
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;OUTPUT A BUFFER ON CHANNEL CONTAINED IN CH.
PUTBF:	SETZ	I,			;PUT OUT INSTRUCTON HERE
	DPB	CH,INSPTR		;DEPOSIT CHANNEL NUMBER
	TLO	I,(OUT)			;TEST ON OUT INSTRUCTION
	XCT	I			;DO OUT
	  POPJ	P,			;RETURN IF SUCCESSFUL
	AOJ	I,			;Y FIELD IS AC 1
	TLZ	I,777000			;TEST OUT OP-CODE
	TLO	I,(GETSTS)		;TEST ON GETSTS INSTRUCTION
	XCT	I			;DO GETSTS
	OUTSTR	[ASCIZ/Out fails. Error codes in ac 1/]
	EXIT	1,			;EXIT ON ERROR
	TLZ	T1,74B23		;TURN OFF ERROR BITS
	TLZ	I,777000			;ZERO OP-CODE
	TLO	I,(SETSTS)		;TEST ON SETSTS INSTRUCTION
	XCT	I			;DO SETSTS
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;OUTPUT A CHARACTER TO TTY
;
TTYOUT:	SOSG	TTYHDR+1		;SEE IF TTY BUFFER FULL
	  PUSHJ	P,BRKTTY		;YES. GO OUTPUT IT
	IDPB	C,TTYHDR		;DEPOSIT A CHAR IN TTY BUFFER
	POPJ	P,			;RETURN
;
;BREAK OUTPUT TO TTY
;
BRKTTY:	PUSH	P,T1			;SAVE T1
	SETZ	T1,			;SET CHAR TO NULL
	IDPB	T1,TTYHDR		;DEPOSIT NULL IN TTY BUFFER
	OUTSTR	TTYBUF			;OUTSTR TTY BUFFER
	MOVE	T1,TTYPTR	;RESET TTY BUFFER POINTER
	MOVEM	T1,TTYHDR		;IN TTYHDR
	MOVEI	T1,TTYSIZ		;RESET BYTE COUNT FOR TTY BUFFER
	MOVEM	T1,TTYHDR+1		;IN TTYHDR+1
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;OUTPUT A PAGE ON CHANNEL CONTAINED IN A
;FIRST RETURN IF EOF. SKIP RETURN IF ENTRY OUTPUT.
;
SHOW:	MOVEI	CH,DATCHI		;SET DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET THE POINT
	  POPJ	P,			;FIRST RETURN IF EOF
SHOW1:	PUSHJ	P,CHRIN			;GET THE CODE
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	PUSHJ	P,CHRIN			;GET THE COLON
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	MOVE	CH,A			;GET OUTPUT CHANNEL
	MOVEI	C,CR			;OUTPUT A CR AND LF 
	PUSHJ	P,CHROUT
	MOVEI	C,LF
	PUSHJ	P,CHROUT
	MOVEI	CH,DATCHI		;RESET CHANNEL TO DATA FILE INPUT
GTNXT:	PUSHJ	P,CHRIN			;GET A CHARACTER
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
OUTIT:	MOVE	CH,A			;SET CHANNEL FOR OUTPUT
	PUSHJ	P,CHROUT		;OUTPUT CHARACTER
	MOVEI	CH,DATCHI		;RESET CHANNEL
	CAIE	C,LF			;CHECK IF CHAR IS LF
	  JRST	GTNXT			;NO. GO BACK FOR NEXT CHARACTER
	PUSHJ	P,CHRIN			;GET CHAR AFTER LF
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	CAIN	C,POINT			;SEE IF A POINT
	  JRST	SHOW1			;YES. GO OUTPUT NEXT FIELD
	CAIE	C,FF			;SEE IF A FF
	  JRST	OUTIT			;NO. CONTINUE OUTPUTTING FIELD
	MOVE	T1,ENBFFF		;SAVE BUFFER POSITION OF LAST FF
	MOVEM	T1,STBFFF
	MOVE	T1,ENBKFF		;SAVE BLOCK OF LAST FF
	MOVEM	T1,STBKFF
	MOVEI	T1,DATCHI		;COMPUTE BUFFER INDEX
	IMULI	T1,3
	MOVE	T1,IBUF+2(T1)		;SAVE BYTE COUNT AT FF
	MOVEM	T1,ENBFFF
	MOVEM	BK,ENBKFF		;SAVE BLOCK OF THIS FF
	JRST	CPOPJ1			;SKIP RETURN IF ENTRY OUTPUT
;
;TYPE OUT FILE NAME ON TERMINAL
MAKNAM:	PUSH	P,T1			;SAVE T1
	SETO	CH,			;CHANNEL -1 (TTY)
	MOVE	T1,FILPTR		;GET POINTER TO FILE NAME
	MOVEI	CT,6			;COUNT 6 CHARACTER NAME
	PUSHJ	P,NOFILE		;GET AND WRITE NAME
	MOVEI	C,POINT			;WRITE POINT
	PUSHJ	P,CHROUT
	MOVEI	CT,3			;COUNT 3 CHARACTER EXTENSION
	PUSHJ	P,NOFILE		;GET AND WRITE EXTENSION
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
NOFILE:	SOSGE	CT			;DECREMENT CHARACTER COUNT
	  POPJ	P,			;RETURN IF COVERED ALL CHARS
	ILDB	C,T1			;LOAD SIXBIT BYTE FROM FILE NAME
	JUMPE	C,NOFILE		;IGNORE IT IF NULL
	ADDI	C,40			;ELSE, MAKE IT UC ASCII
	PUSHJ	P,CHROUT		;OUTPUT IT TO TTY
	JRST	NOFILE			;GO BACK FOR NEXT CHAR
;
;SET UP TEMP EDIT FILE FOR WRITING
;
;OPEN AN OUTPUT CHANNEL AND ENTER A TEMPORARY EDIT FILE FILE.TEM
SETEDT:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	PUSH	P,T3			;SAVE T3
	PUSH	P,T4			;SAVE T4
	SETZB	T1,T2			;MODE ASCII
	TLO	T2,(SIXBIT/DSK/)	;DEVICE DSK
	MOVEI	T3,EDITO		;COMPUTE BUF INDEX OF EDIT OUT CHAN
	IMULI	T3,3
	HRLZI	T3,OBUF(T3)		;GET OUT BUFFER INDEX FOR EDIT CHAN
	MOVEI	CH,EDITO		;SET UP EDIT OUT CHANNEL
	PUSHJ	P,OPNCHN		;OPEN CHANNEL TO TEMP EDIT FILE
	MOVE	T1,DFILE		;LOAD FILE NAME
	HRLZI	T2,(SIXBIT/TEM/)	;GIVE IT TEMP EXTENSION
	SETZB	T3,T4			;DEFAULTS
	PUSHJ	P,ENTFIL		;ENTER TEMP EDIT FILE
	OUTBUF	EDITO,1			;1 OUTPUT BUFFER
	POP	P,T4			;RESTORE T4
	POP	P,T3			;RESTORE T3
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;COPY FILE TO FILE.TEM FROM BEGINNING TO FF AT START OF ENTRY
;
COPBEG:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	PUSH	P,T3			;SAVE T3
	PUSHJ	P,SETEDT		;SET UP TO WRITE TO TEMP EDIT FILE
	MOVEI	T2,DATCHI		;COMPUTE INDEX FOR DATA IN CHAN
	IMULI	T2,3
	MOVEI	T3,EDITO		;COMPUTE INDEX FOR EDIT OUT CHAN
	IMULI	T3,3
	MOVE	CT,STBKFF		;GET BLOCK AT WHICH TO STOP
	USETI	DATCHI,1		;START AT BEGINNING FOR INPUT
	USETO	EDITO,1			;AND OUTPUT
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,GETBF			;GET FIRST BLOCK
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
	MOVEI	CH,EDITO		;SET UP TEMP EDIT FILE
	PUSHJ	P,PUTBF			;DUMMY OUT TO SET UP BUF RING HDR
	HRRZ	T1,IBUF+1(T2)		;GET ADR OF INPUT BUFFER - 1
	MOVSI	T1,1(T1)		;LOAD ADR OF INPUT BUFFER
	HRR	T1,OBUF+1(T3)		;GET ADR OF OUTPUT BUFFER - 1
	AOJ	T1,			;MAKE IT ADR OF OUTPUT BUFFER
	MOVEM	T1,BLTAC		;STORE AC FOR BLT INSTRUCTION
BLTLOP:	SOJE	CT,ATFFBK		;TEST HERE SO DON'T COPY BLOCK W/ FF
	HRLZI	I,(BLT	T1,)		;LOAD BLT INSTRUCTION
	HRR	I,@IBUF+1(T2)		;GET WORD COUNT FROM INPUT BUFFER
	ADDI	I,-1(T1)		;COMPUTE ENDING ADR FOR BLT INSTRUCTION
	XCT	I			;DO BLT FROM INPUT TO OUTPUT BUFFERS
	HRRM	I,OBUF+1(T3)		;RESET OUT BUF RING HDR BYTE PTR
	MOVEI	CH,EDITO		;SET UP EDIT OUT CHANNEL
	PUSHJ	P,PUTBF			;OUTPUT THE BUFFER
	MOVE	T1,BLTAC		;RESTORE AC FOR BLT INSTRUCTION
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,GETBF			;GET THE NEXT BUFFER
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
	JRST	BLTLOP			;GO COPY NEXT BLOCK
ATFFBK:	MOVEI	T1,EDITO		;SET UP EDIT FILE OUTPUT CHANNEL
	MOVEM	T1,OUTCHN		;STORE AWAY FOR SUBROUTINES
	MOVE	A,STBFFF		;GET CHAR COUNT AT STARTING FF
	PUSHJ	P,COPBLK		;READ AND WRITE UP TO STARTING FF
	POP	P,T3			;RESTORE T3
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;READ AND WRITE THE CURRENT BLOCK UNTIL (A) BLOCKS LEFT (AT START OF ENTRY)
;OR EOF.  STORE CHARACTER COUNT ON RETURN IN CT.
;
COPBLK:	PUSH	P,T1			;SAVE T1
	MOVEI	T1,DATCHI		;COMPUTE BUF INDEX FOR DATA IN CHAN
	IMULI	T1,3
	SETZ	CT,			;INITIALIZE CHAR COUNT
COPLOP:	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET A CHARACTER
	  JRST	COPRET			;GO RETURN IF EOF
	AOJ	CT,			;INCREMENT CHAR COUNT
	MOVE	CH,OUTCHN		;GET OUTPUT CHANNEL
	PUSHJ	P,CHROUT		;OUTPUT THE CHAR
	CAME	A,IBUF+2(T1)		;CHECK IF (A) BYTES LEFT
	  JRST	COPLOP			;NO. LOOP FOR MORE CHARS
COPRET:	MOVEM	CT,STBFFF		;STORE CHAR COUNT
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;COPY REST OF FILE, RENAME TEMP EDIT FILE
;
EDTEND:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	PUSH	P,T3			;SAVE T3
	PUSH	P,T4			;SAVE T4
	MOVEI	T1,EDITO		;GET EDIT OUTPUT CHANNEL
	MOVEM	T1,OUTCHN		;STORE IT FOR SUBROUTINES
	PUSHJ	P,WRTEND		;WRITE REST OF FILE TO TEMP EDIT
	CLOSE	EDITO,			;CLOSE EDIT OUTPUT CHANNEL
	SETZ	T1,			;DELETE FILE (NULL NAME)
	MOVEI	CH,DATCHI		;ON DATA FILE INPUT CHA NNEL
	PUSHJ	P,RENFIL		;GO RENAME TO NULL
	MOVE	T1,DFILE		;LOAD FILE NAME
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULTS
	MOVEI	CH,EDITO		;RENAME TO ORIGINAL ON EDIT CHANNEL
	PUSHJ	P,RENFIL		;DO RENAME
	RELEAS	EDITO,			;RELEASE EDIT CHANNEL
	MOVE	T1,DFILE		;LOAD FILE NAME
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULTS
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,LOKFIL		;LOOKUP FILE AGAIN
	  JRST	ILFORM			;IMPOSSIBLE (NOT FOUND)
	POP	P,T4			;RESTORE T4
	POP	P,T3			;RESTORE T3
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
;COPY REST OF FILE TO OUTPUT FILE ON CHANNEL CONTAINED IN OUTCHN.
;
WRTEND:	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET A CHARACTER
	  POPJ	P,			;RETURN ON EOF
	MOVE	CH,OUTCHN		;GET OUTPUT CHANNEL
	PUSHJ	P,CHROUT		;WRITE A CHARACTER
	JRST	WRTEND			;LOOP BACK FOR MORE CHARACTERS
;
;REWIND THE DATA FILE ON INPUT CHANNEL
;
REWDAT:	USETI	DATCHI,1		;POINT TO FIRST BLOCK
	MOVEI	CH,DATCHI		;SET DATA FILE INPUT CHANNEL
	PUSHJ	P,GETBF		;GET FIRST BLOCK
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	MOVEI	BK,1			;RESET BLOCK COUNT
	SETOM	ENBKFF			;RESET BLOCK COUNT OF FF
	SETOM	STBKFF			;RESET OLD BLOCK COUNT OF FF
	POPJ	P,			;RETURN
;
;RESTORE POSITION OF FILE BEFORE EDITING. BLOCK IS IN BK; NUMBER OF CHARACTERS
;TO RESTORE AFTER IS IN STBFFF.
;
RESPOS:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	MOVE	CT,STBFFF		;GET CHARACTER COUNT INTO BUFFER
	MOVEI	CH,DATCHI		;SET DATA FILE INPUT CHANNEL
	USETI	DATCHI,(BK)		;POINT TO BLOCK WHERE EDIT STARTED
	PUSHJ	P,GETBF			;GET THAT BLOCK
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	SOJ	BK,			;RESTORE BLOCK COUNT
	MOVEI	T2,DATCHI		;COMPUTE INDEX OF INPUT BUFFER
	IMULI	T2,3
	MOVE	T1,IBUF+2(T2)		;GET NEW BUFFER SIZE
	SUB	T1,CT			;COMPUTE BYTE COUNT AFTER POSITIONING
	MOVEM	T1,IBUF+2(T2)		;SET BUFFER HEADER BYTE COUNT TO ANSWER
	IBP	IBUF+1(T2)		;INCREMENT BUF HDR BYTE POINTER
	SOJG	CT,.-1			;UNTIL PASSED NUMBER OF CHARS IN CT
	MOVE	T1,IBUF+2(T2)		;GET BYTES LEFT
	MOVEM	T1,STBFFF		;STORE AS STARTING FF BUFFER POSITION
	MOVEM	T1,ENBFFF		;AND AS NEW FF BUFFER POSITION
	MOVEM	BK,ENBKFF		;STORE BLOCK COUNT AS NEW FF BLOCK
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
SUBTTL FIND COMMAND
COMMENT/
	Find the next match of the search string, and type out the entry
in which it occurs on the terminal.
/
;
FIND:	TRNE	F,FLFAIL		;CHECK IF LOOKUP FAILED
	  JRST	NOTTHR			;YES. GO TELL NOT THERE
	TRNE	F,FEOF			;AT EOF?
	  JRST	ERROR			;YES. THEN ILLEGAL COMMAND
	PUSHJ	P,FINSEA		;GO FIND A MATCH
	  JRST	NOTFND			;EOF - GO TELL USER NOT FOUND
	SETO	A,			;SET TTY CHANNEL
	PUSHJ	P,SHOW			;DISPLAY PAGE
	  JRST	ILFORM			;ILLEGAL FORMAT OF FILE IF EOF
	PUSHJ	P,BRKTTY		;BREAK TTY OUTPUT
	JRST	COMMND			;GO GET NEXT COMMAND
;
NOTFND:	OUTSTR[ASCIZ/SEARCH FAILS.
/]
	TRO	F,FEOF			;TURN ON EOF FLAG
	JRST	COMMND			;GO GET NEXT COMMAND
;
SUBTTL COMMON ROUTINES FOR FIND AND SEARCH COMMANDS
COMMENT/
	The following algorithm is used for all search commands:

	  1. Get a character from the search string.
	  2. If it is an escape then
		Get another character from the search string.
		If this character is also an escape then
		  Rewind the file to the start of the current entry and return;
		  Else, rewind the file to the start of the current field.
	  3. Loop
		Get a character from the file
		If at the end of the current field then
		  Rewind the search string to before the first word.
		  Go to step 1.
		If characters match then go to step 1.
		If previous characters matched then rewind the search string
		  to the start of the current word.
	     End Loop

	First return if match not found. Skip return if match found.
/
;
FINSEA:	MOVEI	CH,DATCHI		;SET UP TO READ DATA FILE
	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	PUSH	P,T3			;SAVE T3
PTAFFF:	PUSHJ	P,CHRIN			;GET CHAR AFTER FF
	  JRST	ENDFIL			;FIRST RETURN IF EOF
	CAIE	C,POINT			;IS CHAR A POINT?
	  JRST	ILFORM			;NO. THEN ILLEGAL FILE FORMAT
NEWFLD:	PUSHJ	P,CHRIN			;GET A CODE FROM INPUT BUFFER
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	GETIND	OPT,ILFORM		;GET THE INDEX OF THE OPTION
	TRNE	OF,@OPT2(T1)		;SHOULD WE SEARCH THIS FIELD?
	  JRST	SCAN			;YES. GO SCAN IT
SCNNXT:	PUSHJ	P,CHRIN			;GET NEXT CHARACTER
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIE	C,LF			;IS CHAR A LF?
	  JRST	SCNNXT			;ELSE, LOOK AT NEXT CHARACTER
PTAFLF:	PUSHJ	P,CHRIN			;GET NEXT CHARACTER
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIN	C,POINT			;SEE IF A POINT
	  JRST	NEWFLD			;YES. START SCANNING NEXT FIELD
	CAIE	C,FF			;SEE IF CHAR IS A FF?
	  JRST	SCNNXT			;NO. LOOK AT NEXT CHARACTER
FFAFLF:	MOVEM	BK,ENBKFF		;STORE BLOCK OF THIS FF
	MOVEI	T1,DATCHI		;COMPUTE BUFFER INDEX
	IMULI	T1,3
	MOVE	T1,IBUF+2(T1)		;STORE POSITION OF FF
	MOVEM	T1,ENBFFF
	JRST	PTAFFF			;AND START SCANNING NEXT ENTRY
;
;SCAN A FIELD FOR A MATCH
SCAN:	PUSHJ	P,CHRIN			;GET CHARACTER AFTER CODE
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIE	C,COLON			;SEE IF CHAR IS A COLON
	  JRST	ILFORM			;NO. THEN ILLEGAL FILE FORMAT
	MOVEM	BK,BLOKC		;STORE BLOCK OF COLON
	MOVEI	T1,DATCHI	;COMPUTE BUFFER INDEX
	IMULI	T1,3
	MOVE	T1,IBUF+2(T1)	;GET # OF USED BYTES AFTER THIS POINT
	MOVEM	T1,BUFRC		;AND STORE IT AWAY
	MOVE	T1,BSTPTR		;LOAD POINTER TO SEARCH STRING
	MOVEM	T1,STRPTR		;STORE IT IN TEMPORARY POINTER LOC
SCNFIL:	PUSHJ	P,CHRIN			;GET NEXT FILE CHAR
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIE	C,LF			;SEE IF CHAR IS A LF
	  JRST	SCNSTR			;NO. GO GET STRING CHAR
	PUSHJ	P,CHRIN			;YES. GET NEXT CHAR
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIN	C,POINT			;IS IT A POINT?
	  JRST	NEWFLD			;YES. WE ARE AT NEW FIELD
	CAIN	C,FF			;IS IT A FF?
	  JRST	FFAFLF			;YES. GO CHECK FOR FOLLOWING POINT
SCNSTR:	ILDB	T3,T1			;GET A CHARACTER FROM STRING
	CAIE	T3,ESC			;IS IT AN ESCAPE?
	  JRST	LOOK			;NO. GO LOOK FOR MATCH
	MOVEM	T1,STRPTR		;STORE TEMP STRING POINTER
	ILDB	T3,T1			;GET ANOTHER CHAR
	CAIN	T3,ESC			;IS THIS CHAR ALSO AN ESCAPE?
	  JRST	ENDSEA			;YES. THEN WE HAVE A MATCH!
	MOVE	BK,BLOKC		;GET BLOCK OF LAST COLON
	MOVE	A,BUFRC			;GET POSITION OF LAST COLON SEEN
	PUSHJ	P,POSTN			;AND POSTION AFTER IT
	TRZ	F,FMATCH			;TURN OFF MATCH MADE FLAG
	PUSHJ	P,CHRIN			;AND GO GET FIRST CHARACTER AGAIN
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
LOOK:	MOVEI	T2,NXTCHR		;GET ADDRESS OF LOOP RETURN IF NO MATCH
	MOVEM	T2,RETADR		;STORE IT
	MOVE	T2,T3			;GET STRING CHARACTER
	TRZ	T2,40			;INDISCRIMINANTLY DROP UC/LC BIT
	CAIL	T2,"A"			;IS CHAR ALPHA?
	    CAILE	T2,"Z"
	  SKIPA	T2,T3		;NO. RESTORE STRING CHAR
	    CAIA				;YES. JUST SKIP
	  AOSA	RETADR			;INCREMENT LOOP RETURN ADDRESS
NXTCHR:	TRZ	C,40			;MAKE CHAR UC (NOOP IF MASK=0)
	CAMN	T2,C			;DO CHARACTERS MATCH?
	  JRST	MATCH			;YES. GO TO MATCH ROUTINE
	TRZN	F,FMATCH		;HAS A MATCH BEEN MADE?
	  JRST	RECYCL			;NO. SO GO GET NEXT FILE CHAR & RECYCLE
	MOVE	T1,STRPTR		;YES. SET STRING PTR TO START OF WORD
	JRST	SCNSTR			;AND GO GET FIRST STRING CHAR OF WORD
RECYCL:	PUSHJ	P,CHRIN			;GET ANOTHER FILE CHAR
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIE	C,LF			;SEE IF CHAR IS A LF?
	  JRST	@RETADR			;NO. JUST GO MAKE NEW COMPARE
	PUSHJ	P,CHRIN			;GET CHAR AFTER LF
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	CAIN	C,POINT			;IS CHAR A POINT?
	  JRST	NEWFLD			;YES. GO GET NEXT FIELD
	CAIN	C,FF			;IS CHAR A FF?
	  JRST	FFAFLF			;YES. GO CHECK FOR FOLLOWING POINT
	JRST	@RETADR			;ELSE, RECYCLE
MATCH:	TRO	F,FMATCH		;TURN ON MATCH MADE FLAG
	JRST	SCNFIL			;AND GO GET NEXT PAIR OF CHARS
;
POSTN:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	MOVEI	CH,DATCHI		;USE DATA FILE INPUT CHANNEL
	USETI	DATCHI,(BK)			;POSITION FILE AT BLOCK BK
	PUSHJ	P,GETBF			;AND GO GET BLOCK BK
	  JRST	ILFORM			;WE SHOULD NEVER GET HERE (EOF)
	SOJ	BK,			;RESTORE BLOCK COUNT
	MOVE	T2,CH			;COMPUTE BUFFER INDEX
	IMULI	T2,3
	MOVE	T1,IBUF+2(T2)		;GET USED BYTE COUNT FOR BLOCK
	MOVEM	A,IBUF+2(T2)		;SET BUFFER COUNT TO POS OF COLON
	SUB	T1,A			;COMPUTE # OF BYTES TO ADVANCE
	IBP	IBUF+1(T2)			;INCREMENT THE BUFFER BYTE POINTER
	SOJG	T1,.-1			;JUMP BACK IS NOT IN POSITION YET
	POP	P,T2			;ELSE, RESTORE T1
	POP	P,T1			;RESTORE T2
	POPJ	P,			;AND RETURN
;
ENDSEA:	SKIPGE	ENBKFF			;SKIP IF NOT FIRST ENTRY
	  JRST	FIRSTB			;ELSE, GO GET FIRST BLOCK
	MOVE	BK,ENBKFF		;GET BLOCK COUNT OF LAST FF
	MOVE	A,ENBFFF		;GET BYTE COUNT OF LAST FF
	PUSHJ	P,POSTN			;POSITION BUFFER AFTER LAST FF
	JRST	RETFS			;RETURN
FIRSTB:	USETI	DATCHI,1			;POINT TO FIRST BLOCK
	PUSHJ	P,GETBF			;GET IT (RESTORES BK TO 1)
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	MOVEI	BK,1			;RESET BLOCK COUNT TO FIRST BLOCK
RETFS:	TRZ	F,FMATCH		;TURN OFF MATCH MADE FLAG
	POP	P,T3			;RESTORE T3
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	JRST	CPOPJ1			;SKIP RETURN
;
ILFORM:	OUTSTR[ASCIZ/ILLEGAL FORMAT OF DATA FILE /]
	PUSHJ	P,MAKNAM		;GET NAME OF DATA FILE
	MOVEI	C,CR			;OUTPUT A CRILIF
	PUSHJ	P,CHROUT
	MOVEI	C,LF
	PUSHJ	P,CHROUT
	JRST	RESSET
;
ENDFIL:	POP	P,T3			;RESTORE T3
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;
	SUBTTL	HELP COMMAND
COMMENT/
	Open a channel to device HLP:, LOOKUP a help text, and type it on
the terminal.
/
;
HELP:	MOVEI	CH,HLPI			;GET HELP FILE INPUT CHANNEL
	MOVE	T1,[SIXBIT/BIBLIO/]	;LOAD NAME OF HELP FILE
	HRLZI	T2,(SIXBIT/HLP/)
	SETZB	T3,T4			;DEFAULT PPN, PROT, ETC. FIELDS
	PUSHJ	P,LOKFIL			;LOOKUP THE HELP FILE
	  JRST	NOHELP			;JUMP IF NOT FOUND
HLPLOP:	PUSHJ	P,CHRIN			;GET A CHARACTER
	  JRST	ENDHLP			;RETURN ON EOF
	SETO	CH,			;TTY CHANNEL
	PUSHJ	P,CHROUT			;OUTPUT CHAR TO TTY
	MOVEI	CH,HLPI			;RESET CHANNEL TO HELP FILE INPUT
	JRST	HLPLOP			;LOOP BACK
ENDHLP:	PUSHJ	P,BRKTTY		;BREAK OUTPUT TO TTY
	CLOSE	HLPI,			;CLOSE HELP FILE INPUT CHANNEL
	JRST	COMMND			;GO GET NEXT COMMAND
NOHELP:	OUTSTR	[ASCIZ/I'm sorry, but no help is available.
/]
	JRST	COMMND			;GO GET NEXT COMMAND
;
	SUBTTL DUMP DATA FILE
COMMENT/
	Write all entries to a .LPT file by setting up a null search
string.
/
;
DUMP:	TRNE	F,FLFAIL		;CHECK IF LOOKUP FAILED
	  JRST	NOTTHR			;YES. GO TELL NOT THERE
	TRNE	F,FLFAIL		;CHECK IF LOOKUP FAILED
	  JRST	NOTTHR			;YES. GO TELL NOT THERE
	HRLZI	T1,(BYTE (7)33,33)	;LOAD DOUBLE ESCAPE
	HLLZM	T1,STRING		;INTO STRING (NO STRING)
	SETO	OF,			;SET ALL OPTION FLAGS
	TRZ	F,FEOF			;TURN OFF EOF FLAG
	JRST	SEARCH			;AND GO DO A NORMAL SEARCH
SUBTTL SEARCH ROUTINE
COMMENT/
	Open a channel to device LPT:, and write all entries in which matches
occur to this device.
/
;
SEARCH:	TRNE	F,FLFAIL		;CHECK IF LOOKUP FAILED
	  JRST	NOTTHR			;YES. GO TELL NOT THERE
	TRNE	F,FEOF			;CHECK IF AT EOF
	  JRST	ERROR			;YES. ILLEGAL COMMAND
	SETOM	ENBKFF			;FLAG THAT ON FIRST ENTRY
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	USETI	DATCHI,1			;POINT TO FIRST BLOCK
	PUSHJ	P,GETBF			;GET IT
	  JRST	ILFORM			;SHOULD NEVER GET HERE (EOF)
	MOVEI	BK,1			;INITIALIZE BLOCK COUNT
	PUSHJ	P,FINSEA			;FIND A MATCH
	  JRST	NOTFND			;JUMP IF NOT FOUND
	SETZB	T1,T2			;MODE ASCII
	TLO	T2,(SIXBIT/LPT/)		;DEVICE LPT
	MOVEI	CH,LPTO			;SET UP LPT OUTPUT CHANNEL
	MOVE	T3,CH			;COMPUTE BUFFER INDEX
	IMULI	T3,3
	HRLZI	T3,OBUF(T3)		;LOAD ADDRESS OF BUFFER HEADER
	PUSHJ	P,OPNCHN			;OPEN OUTPUT CHANNEL TO LPT
	OUTBUF	LPTO,1			;SET UP 1 OUTPUT BUFFER TO LPT
SEARA:	MOVEI	A,LPTO			;WRITE PAGE TO LPT
	PUSHJ	P,SHOW			;WRITE PAGE TO LPT
	  JRST	ILFORM			;ILLEGAL FORMAT OF FILE IF EOF
	MOVEI	CH,DATCHI		;RESET CHANNEL TO DATA FILE INPUT
	PUSHJ	P,FINSEA			;SEARCH FOR MATCH
	  JRST	ENDFND			;RETURN IF NOT FOUND
	MOVEI	CH,LPTO			;RESET CHANNEL TO LPT OUTPUT
	MOVEI	C,CR			;WRITE A CR,CR,LF TO LPT
	PUSHJ	P,CHROUT
	MOVEI	C,LF
	PUSHJ	P,CHROUT
	MOVEI	C,LF
	PUSHJ	P,CHROUT
	JRST	SEARA			;LOOP BACK FOR MORE SEARCHING
ENDFND:	TRO	F,FEOF			;TURN ON EOF FLAG
	CLOSE	LPTO,			;CLOSE CHANNEL TO LPT
	RELEAS	LPTO,			;RELEASE CHANNEL TO LPT
	JRST	COMMND			;JUMP TO GET NEXT COMMAND
SUBTTL EXIT ROUTINE
;
LEAVE:	EXIT					;EXIT
SUBTTL COMMON ROUTINES FOR APPEND, INSERT, AND REPLACE COMMANDS
;ASK QUESTIONS AND WRITE FOUR FIELDS TO DATA FILE OUTPUT CHANNEL
;
INSENT:	MOVEI	CH,DATCHO		;SET UP DATA FILE OUTPUT CHANNEL
	MOVEI	A,CODES-1		;GET POINTER TO LIST OF FIELD CODES
	MOVEI	C,FF			;OUTPUT A FF TO TTY
	OUTCHR	C
	OUTSTR	[ASCIZ/
End each entry with a CONTROL-Z.

/]
	MOVNI	T1,4				;ASK FOR 4 FIELDS
REDFLD:	OUTSTR	@QUEST+4(T1)			;ASK FOR FIELD
	PUSHJ	P,FIELD				;GO GET FIELD
	AOJN	T1,REDFLD			;LOOP BACK IF MORE FIELDS
	MOVEI	C,FF				;WRITE A FF TO OUTPUT FILE
	PUSHJ	P,CHROUT
	POPJ	P,				;RETURN
;
;WRITE A SINGLE FIELD ON DATA FILE OUTPUT CHANNEL.
FIELD:	PUSH	P,T1			;SAVE T1
	AOJ	A,			;POINT TO NEXT FIELD CODE
	MOVEI	CT,3			;INITIALIZE COUNTER
	MOVE	T1,[POINT 7,(A)]	;GET NEXT CODE
CODELP:	ILDB	C,T1			;GET A CHARACTER FROM CODE
	PUSHJ	P,CHROUT		;WRITE CODE TO OUTPUT BUFFER
	SOJG	CT,CODELP		;LOADED 3 CHARACTERS?
	PUSHJ	P,NEXT			;GO READ AND WRITE FIELD TEXT
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
;READ AND WRITE ON CHANNEL SPECIFIED IN CH TEXT FOR A SINGLE FIELD.
;
	MOVEI	CH,EDITO		;SET UP OUTPUT TO EDIT FILE
NEXT:	INCHWL	C			;GET A CHAR FROM TTY BUFFER
	CAIN	C,CONZ			;CONTROL-Z?
	  JRST	CNTZ			;YES.
	TRZ	F,FLINFD		;TURN OFF LF FLAG IF ON
	PUSHJ	P,CHROUT		;WRITE CHAR TO OUTPUT BUFFER
	CAIN	C,LF			;LINE FEED?
	  TRO	F,FLINFD		;YES. TURN OF LF SEEN FLAG
	JRST	NEXT			;NO. GET NEXT CHAR.
CNTZ:	TRNE	F,FLINFD		;LINE FEED LAST CHAR ENTERED?
	  JRST	NXTRET			;YES. RETURN AND RESTORE T1
	MOVEI	C,CR			;WRITE A CR TO OUTPUT BUFFER
	PUSHJ	P,CHROUT
	MOVEI	C,LF			;WRITE A LF TO OUTPUT BUFFER
	PUSHJ	P,CHROUT
NXTRET:	TRZ	F,FLINFD		;TURN OFF LF LAST CHAR FLAG
	POPJ	P,			;AND RETURN
;
;COMPUTE BLOCK COUNT FROM NEGATIVE WORD COUNT
GETBKS:	PUSH	P,BK+1			;SAVE BK+1 FOR REMAINDER
	IDIVI	BK,200			;GET NEGATIVE BLOCK COUNT-1
	MOVNS	BK			;MAKE IT POSITIVE
	SKIPE	BK+1			;SKIP IF LAST BLOCK EXACTLY FULL
	  AOJ	BK,			;GET NEXT PARTIAL BLOCK NUMBER
	POP	P,BK+1			;RESTORE BK+1
	POPJ	P,			;AND RETURN
;
;OPEN, LOOKUP, AND ENTER DATA FILE ON OUTPUT CHANNEL
;
UPDTIO:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	PUSH	P,T3			;SAVE T3
	PUSH	P,T4			;SAVE T4
	MOVEI	CH,DATCHO		;SET UP FOR DATA FILE OUTPUT
	MOVE	T1,DFILE		;LOAD FILE NAME
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULTS
	PUSHJ	P,LOKFIL		;LOOKUP THE FILE ON OUTPUT CHANNEL
	  JRST	ILFORM			;IMPOSSIBLE (NOT FOUND)
	HLRE	BK,T4			;GET -WORD/BLOCK COUNT
	SKIPG	BK			;SEE IF BLOCK COUNT
	  PUSHJ	P,GETBKS		;NO. GO COMPUTE BLOCK COUNT
	MOVE	T1,DFILE		;LOAD FILE NAME FOR ENTER
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULTS
	PUSHJ	P,ENTFIL		;ENTER FILE ON OUTPUT CHANNEL
	POP	P,T4			;RESTORE T4
	POP	P,T3			;RESTORE T3
	POP	P,T2			;RESTORE T2
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
SUBTTL BEGIN ROUTINE
COMMENT/
	Position at start of data file, and reset the proper flags.
/
;
BEGIN:	TRNE	F,FLFAIL			;CHECK IF FILE EXISTS
	  JRST	NOTTHR			;NO. TELL USER NOT THERE
	PUSHJ	P,REWDAT			;REWIND DATA FILE
	TRZ	F,FEOF			;TURN OFF EOF FLAG
	JRST	COMMND			;GET NEXT COMMAND
SUBTTL PAGE ROUTINE
COMMENT/
	Type out next entry on the terminal.
/
;
PAGE:	TRNN	F,FEOF			;TEST IF AT EOF
	  JRST	PAGE1			;NO. CONTINUE
	SKIPL	STBKFF			;TEST IF AT FIRST ENTRY
	  JRST	ERROR			;NO. ILLEGAL COMMAND
PAGE1:	TRNE	F,FLFAIL		;CHECK IF FILE EXISTS
	  JRST	NOTTHR			;NO. GO TELL NOT THERE
	TRZ	F,FEOF			;CLEAR EOF FLAG IN CASE ON
	SETO	A,			;SET OUTPUT TO TTY
	PUSHJ	P,SHOW			;SHOW NEXT PAGE
	  JRST	PAGEOF			;JUMP IF EOF
	PUSHJ	P,BRKTTY		;BREAK OUTPUT TO TTY
	JRST	COMMND			;GO GET NEXT COMMAND
PAGEOF:	TRO	F,FEOF			;TURN ON EOF FLAG
	OUTSTR	[ASCIZ/NO MORE PAGES
/]
	JRST	COMMND			;GET NEXT COMMAND
SUBTTL TYPE ROUTINE
COMMENT/
	Type out the next entry on the terminal.
/
;
TYPE:	TRNE	F,FLFAIL			;CHECK IF FILE EXISTS
	  JRST	NOTTHR				;NO. GO TELL NOT THERE
	SKIPG	STBKFF				;SEE IF AT FIRST ENTRY
	  JRST	TYPFIR				;YES. GO REWIND FILE
	TRNE	F,FEOF				;SEE IF EOF FLAG IS ON
	  JRST	ERROR				;YES. ILLEGAL COMMAND
	PUSH	P,STBFFF			;SAVE STARTING FF BUFFER POS
	PUSH	P,STBKFF			;SAVE STARTING FF BLOCK
	MOVE	A,STBFFF			;GET STARTING FF BUFFER POS
	MOVE	BK,STBKFF			;GET STARTING FF BLOCK
	PUSHJ	P,POSTN				;POSITION AT START OF ENTRY
	SETO	A,				;OUTPUT TO TTY
	PUSHJ	P,SHOW				;OUTPUT FIELD
	  JRST	ILFORM				;ILLEGAL FORMAT ON EOF
	PUSHJ	P,BRKTTY			;BREAK OUTPUT TO TTY
	POP	P,STBKFF			;RESTORE STARTING FF BLOCK
	POP	P,STBFFF			;RESTORE STARTING FF BUFFER POS
	JRST	COMMND				;GO GET NEXT COMMAND
TYPFIR:	PUSHJ	P,REWDAT			;REWIND THE FILE
	SETO	A,				;OUTPUT TO TTY
	PUSHJ	P,SHOW				;SHOW FIELD
	  JRST	ILFORM				;ILLEGAL FORMAT ON EOF
	PUSHJ	P,BRKTTY			;BREAK OUTPUT TO TTY
	SETOM	STBKFF				;RESTORE STARTING FF BLOCK COUNT
	JRST	COMMND				;GO GET NEXT COMMAND
SUBTTL KILL ROUTINE
COMMENT/
	Delete the current entry.  Copy the file to FILE.TEM without the
current entry, then rename back to original file name.
/
;
KILL:	TRNE	F,FLFAIL		;CHECK IF FILE EXISTS
	  JRST	NOTTHR			;NO. TELL NOT THERE
	SKIPG	STBKFF			;CHECK IF AT FIRST ENTRY
	  JRST	KILFIR			;YES. GO TO SPECIAL ROUTINE
	TRNE	F,FEOF			;CHECK IF AT EOF
	  JRST	ERROR			;YES. ILLEGAL COMMAND
	PUSHJ	P,COPBEG		;COPY BEGINNING OF FILE TO FF
	PUSHJ	P,KILLS			;KILL ENTRY
	MOVE	BK,STBKFF		;GET STARTING FF BLOCK
	PUSHJ	P,RESPOS		;RESTORE POSITION BEFORE EDIT
	JRST	COMMND			;GET NEXT COMMAND
KILFIR:	PUSHJ	P,SETEDT		;OPEN CHANNEL AND ENTER EDIT FILE
	PUSHJ	P,REWDAT		;REWIND DATA FILE
	PUSHJ	P,KILLS			;KILL FIRST ENTRY
	PUSHJ	P,REWDAT		;REWIND DATA FILE AGAIN
	JRST	COMMND			;GO GET NEXT COMMAND
KILLS:	MOVEI	CH,DATCHI		;SET UP INPUT CHANNEL TO DATA FILE
	PUSHJ	P,CHRIN			;GET A CHARACTER
	  JRST	ILFORM			;SHOULD NOT GET HERE (EOF)
	CAIE	C,FF			;CHECK IF CHAR IS A FF
	  JRST	.-3			;NO. GO GET MORE CHARACTERS
	PUSHJ	P,EDTEND		;WRITE REST OF FILE AND RENAME
	OUTSTR	[ASCIZ/ENTRY KILLED
/]
	POPJ	P,			;RETURN
	SUBTTL REPLACE ROUTINE
COMMENT/
	Replace fields in the current entry.  Copy the file to FILE.TEM
with the changes, then rename to the original file.
/
;
REPLAC:	TRNE	F,FLFAIL		;CHECK IF FILE EXISTS
	  JRST	NOTTHR			;NO. TELL NOT THERE
	SKIPN	T2			;CHECK IF ANY OPTIONS GIVEN
	  SETO	OF,			;NO. SET ALL OPTION FLAGS
	SKIPG	STBKFF			;CHECK IF AT FIRST ENTRY
	  JRST	REPFIR			;YES. GO TO SPECIAL ROUTINE
	TRNE	F,FEOF			;CHECK IF AT EOF
	  JRST	ERROR			;YES. ILLEGAL COMMAND
	PUSHJ	P,COPBEG		;COPY BEGINNING OF FILE TO FF
	PUSHJ	P,REPLCS		;REPLACE FIELD(S)
	MOVE	BK,STBKFF		;GET STARTING FF BLOCK
	PUSHJ	P,RESPOS		;RESTORE POSITION BEFORE EDIT
	JRST	COMMND			;GET NEXT COMMAND
REPFIR:	PUSHJ	P,SETEDT		;OPEN CHANNEL AND ENTER EDIT FILE
	PUSHJ	P,REWDAT		;REWIND DATA FILE
	PUSHJ	P,REPLCS		;REPLACE FIELDS IN FIRST ENTRY
	PUSHJ	P,REWDAT		;REWIND DATA FILE AGAIN
	JRST	COMMND			;GO GET NEXT COMMAND
REPLCS:	PUSH	P,T1			;SAVE T1
	PUSH	P,T2			;SAVE T2
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET THE POINT
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
REPLC1:	PUSHJ	P,CHRIN			;GET A CODE
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
	GETIND	OPT,ILFORM		;GET INDEX OF CODE
	TRNE	OF,@OPT2(T1)		;CHECK IF THIS CODE IS ON
	  OUTSTR	@QUEST(T1)	;YES. OUTPUT QUESTION FOR THIS CODE
	MOVEI	CH,EDITO		;SET UP EDIT FILE OUTPUT CHANNEL
	MOVE	T2,[POINT 7,CODES(T1)]	;LOAD POINTER TO FIELD CODE
	MOVEI	CT,3			;3 CHAR FIELD CODE (.<CODE>:)
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET COLON
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
	MOVEI	CH,EDITO		;RESET EDIT FILE OUTPUT CHANNEL
LODCOD:	ILDB	C,T2			;GET A CHAR OF CODE
	PUSHJ	P,CHROUT		;OUTPUT IT TO EDIT FILE
	SOJG	CT,LODCOD		;LOOP BACK IF NOT ALL OF CODE
LODFLD:	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET A CHARACTER
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
LODFDA:	TRNE	OF,@OPT2(T1)		;CHECK IF CODE IS ON FOR REPLACE
	  JRST	LODFD1			;YES. DO NOT WRITE OUT FIELD
	MOVEI	CH,EDITO		;SET UP EDIT FILE OUTPUT CHANNEL
	PUSHJ	P,CHROUT		;OUTPUT CHAR
LODFD1:	CAIE	C,LF			;CHECK IF CHAR IS A LF
	  JRST	LODFLD			;NO. CONTINUE GETTING FIELD CHARS
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,CHRIN			;GET THE NEXT CHAR
	  JRST	ILFORM			;IMPOSSIBLE (EOF)
	CAIE	C,POINT			;CHECK IF CHAR IS A POINT
	  JRST	CHKFF			;YES. GO CHECK FOR END OF ENTRY (FF)
	TRNE	OF,@OPT2(T1)		;CHECK IF REPLACING THIS FIELD
	  PUSHJ	P,NEXT-1		;YES. GO READ REPLACEMENT
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	JRST	REPLC1			;LOOP BACK FOR NEXT FIELD
CHKFF:	CAIE	C,FF			;CHECK IF CHAR IS FF
	  JRST	LODFDA			;NO. CONTINUE READING FIELD
	TRNE	OF,@OPT2(T1)		;CHECK IF REPLACING THIS FIELD
	  PUSHJ	P,NEXT-1		;YES. GET REPLACEMENT FIELD
	MOVEI	CH,EDITO		;SET UP EDIT OUTPUT CHANNEL
	MOVEI	C,FF			;OUTPUT A FF
	PUSHJ	P,CHROUT		;TO EDIT FILE
	POP	P,T2			;RESTORE T2
	PUSHJ	P,EDTEND		;WRITE REST OF FILE AND RENAME
	POP	P,T1			;RESTORE T1
	POPJ	P,			;RETURN
	SUBTTL APPEND ROUTINE
COMMENT/
	Append an entry to the data file writing to the data file output
channel.
/
;
APPEND:	TRNE	F,FLFAIL		;SEE IF FILE THERE
	  JRST	NOTTHR			;NO. GO TELL NOT THERE
	PUSHJ	P,UPDTIO		;OPEN, LOOKUP, AND ENTER DATA FILE
	MOVEM	BK,STBKFF		;STORE LAST BLOCK AS STARTING FF BLOCK
	USETI	DATCHI,(BK)		;READ LAST BLOCK OF FILE
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,GETBF			;GET LAST BLOCK
	  JRST	ILFORM			;SHOULD NOT GET HERE (EOF)
	SOJ	BK,			;RESTORE BLOCK COUNT
	USETO	DATCHO,(BK)		;WRITE LAST BLOCK OF FILE
	MOVEI	T1,DATCHO		;OUTPUT GOES TO DATA FILE
	MOVEM	T1,OUTCHN
	SETO	A,			;COPY UNTIL EOF
	PUSHJ	P,COPBLK		;READ AND WRITE LAST BLOCK UNTIL EOF
	PUSHJ	P,INSENT		;APPEND A NEW ENTRY
	CLOSE	DATCHO,			;CLOSE DATA FILE OUTPUT CHANNEL
	MOVE	BK,STBKFF		;GET OLD EOF POSITION
	PUSHJ	P,RESPOS		;POSITION AT OLD EOF
	TRZ	F,FEOF			;TURN OFF EOF FLAG
	JRST	COMMND			;GO GET NEXT COMMAND
	SUBTTL INSERT ROUTINE
COMMENT/
	Insert and entry in the data file before the current entry writing to
the data file output channel.
/
;
INSERT:	MOVEI	T1,DATCHO		;OUTPUT GOES TO DATA FILE
	MOVEM	T1,OUTCHN
	TRNE	F,FLFAIL		;CHECK IF FILE EXISTS
	  JRST	CREATE			;NO. GO CREATE IT
	SKIPG	STBKFF			;SKIP IF NOT ON FIRST BLOCK
	  JRST	FIRINS			;GO TO SPECIAL ROUTINE FOR FIRST BLOCK
	TRNE	F,FEOF			;CHECK IF AT EOF
	  JRST	ERROR			;YES. ILLEGAL COMMAND
	PUSHJ	P,UPDTIO		;OPEN, LOOKUP, AND ENTER DATA FILE
	MOVE	BK,STBKFF		;GET BLOCK OF STARTING FF
	USETI	DATCHI,(BK)		;POINT TO THAT BLOCK FOR INPUT
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,GETBF			;GET BLOCK OF LAST FF
	  JRST	ILFORM			;SHOULD NOT GET HERE (EOF)
	SOJ	BK,			;RESTORE BLOCK COUNT
	USETO	DATCHO,(BK)		;POINT TO BLOCK OF STARTING FF FOR OUT
	MOVE	A,STBFFF		;LOAD BUFFER POS OF START OF ENTRY
	PUSHJ	P,COPBLK		;COPY BLOCK UP TO START OF ENTRY
	PUSHJ	P,INSENT		;INSERT A NEW ENTRY
	PUSHJ	P,WRTEND		;COPY THE REST OF THE FILE
	CLOSE	DATCHO,			;CLOSE DATA FILE OUTPUT CHANNEL
	MOVE	BK,STBKFF		;LOAD POS OF STARTING FF
	PUSHJ	P,RESPOS		;RESTORE THERE
	JRST	COMMND			;GET NEXT COMMAND
FIRINS:	PUSHJ	P,UPDTIO		;OPEN, LOOKUP, AND ENTER DATA FILE
	PUSHJ	P,REWDAT		;REWIND THE DATA FILE ON INPUT CHANNEL
	PUSHJ	P,INSENT		;INSERT AN ENTRY AT START OF FILE
	PUSHJ	P,WRTEND		;COPY REST OF FILE
	CLOSE	DATCHO,			;CLOSE DATA FILE FOR OUTPUT
	PUSHJ	P,REWDAT		;REWIND THE DATA FILE AGAIN
	JRST	COMMND			;GET NEXT COMMAND
CREATE:	MOVE	T1,DFILE		;LOAD FILE NAME
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULTS
	MOVEI	CH,DATCHO		;SET UP DATA FILE OUTPUT CHANNEL
	PUSHJ	P,ENTFIL		;ENTER FILE
	PUSHJ	P,INSENT		;INSERT FIRST ENTRY
	CLOSE	DATCHO,			;CLOSE OUTPUT CHANNEL TO DATA FILE
	MOVE	T1,DFILE		;LOAD FILE NAME
	HLLZ	T2,DFILE+1
	SETZB	T3,T4			;DEFAULTS
	MOVEI	CH,DATCHI		;SET UP DATA FILE INPUT CHANNEL
	PUSHJ	P,LOKFIL		;LOOKUP DATA FILE ON INPUT CHANNEL
	  JRST	ILFORM			;IMPOSSIBLE (NOT FOUND)
	TRZ	F,FLFAIL		;TURN OFF LOOKUP FAILED FLAG
	JRST	COMMND			;GET NEXT COMMAND
SUBTTL PURE AREA
;
STKSET:	IOWD	STAKSZ,PDSTK		;SET UP STACK
CODES:	ASCIZ/.A:/			;AUTHOR
	ASCIZ/.T:/			;TITLE
	ASCIZ/.R:/			;REFERENCE
	ASCIZ/.S:/			;SUMMARY
CMD1:	EXP	"A","B","D","E","F","H","N","I","K","P","R","S","T"
						;LIST OF COMMANDS
CMDLG==.-CMD1					;GET NUMBER OF COMMANDS
CMD2:	EXP	APPEND,BEGIN,DUMP,LEAVE,FIND	;COMMAND ROUTINES
	EXP	HELP,INPNAM,INSERT,KILL,PAGE,REPLAC,SEARCH,TYPE
OPT1:	EXP	"A","T","R","S"			;LIST OF ARGUMENTS
OPTLG==.-OPT1					;GET NUMBER OF OPTIONS
OPT2:	EXP	1,2,4,10			;FLAG VALUES OF ARGS
DEL1:	EXP	LF,FF,CR,CONZ			;THESE DELIMS MEAN EOL
DELG==.-DEL1-1					;GET NUMBER OF EOL DELIMS
	EXP	HT,VT,SPACE			;JUST IGNORE THESE DELIMS
DELLG==.-DEL1					;GET TOTAL NUMBER OF DELIMS
QUEST:	EXP AQ,TQ,RQ,SQ				;POINTERS TO QUESTIONS
AQ:	ASCIZ/
Enter author(s):
---------------
/
TQ:	ASCIZ/
Enter title of work:
-------------------
/
RQ:	ASCIZ/
Enter page and publication references to the work:
-----------------------------------------------
/
SQ:	ASCIZ/
Enter a summary - abstract of the work:
--------------------------------------
/
FILPTR:	POINT 6,DFILE				;POINTER TO FILE NAME
EXTPTR:	POINT 6,DFILE+1				;POINTER TO FILE EXTENSION
BSTPTR:	POINT 7,STRING			;POINTER TO BEGINNING OF STRING
TTYPTR:	POINT 7,TTYBUF			;POINTER TO TTY BUFFER
INSPTR:	POINT 4,I,12				;POINTER TO DEPOSIT CHAN IN INST
;
	END START