Google
 

Trailing-Edge - PDP-10 Archives - QT020_T20_4.1_6.1_SWSKIT_851021 - swskit-hacks/itexti.mac
There are no other files named itexti.mac in the archive.
	TITLE	ITEXTI - Integrated TEXTI Processing Routine
	SUBTTL	J. G. ZIMA/JGZ

	SEARCH	MONSYM,MACSYM	;MONITOR SYMBOLS
	.REQUEST REL:MACREL	;MACSYM ROUTINES
	.DIRECTIVE FLBLST	;NICE LOOKING
	SALL			; LISTINGS


	STDAC.		;STANDARD AC CONVENTIONS


;ITEXTI -- ROUTINE TO PERFORM AN INTEGRATED TEXTI CALL TO FILL
;A BUFFER WITH DATA.  ALLOWS ^B TO INCLUDE A FILE, AND ^E TO
;INVOKE AN EDITOR TO EDIT THE BUFFER, OR ^K TO REDISPLAY, ALA MS.
;
;CALL WITH:
;   T1/	POINTER TO SUFFICIENTLY LARGE BUFFER
;   T2/	BYTE COUNT FOR BUFFER
;   T3/ POINTER FOR CONTROL-R STRING (PROMPT)
;	CALL	ITEXTI
;   RETURNS:	+1 ON ERRORS, INCLUDING BUFFER FULL
;		+2 ON NORMAL RETURN WITH BUFFER FILLED WITH ASCIZ
;
;USES T1-T4.

ITEXTI::
	TLC	T1,777777	;HANDLE -1,,ADR
	TLCN	T1,777777
	 HRLI	T1,(POINT 7,0)	;REPLACE WITH REAL BYTE POINTER
	MOVEM	T1,ITEX.B+.RDDBP ;SET BUFFER POINTER
	MOVEM	T1,ITEX.B+.RDBFP ;AND BACKUP POINTER
	MOVEM	T2,ITEX.B+.RDDBC ;SET BUFFER COUNT
	MOVEM	T2,ITCNT	;ALSO REMEMBER HERE FOR EDITING
	SKIPN	T3		;IF CONTROL-R STRING NULL
	HRROI	T3,[0]		; FAKE IT
	TLC	T3,777777	;HANDLE -1,,ADR
	TLCN	T3,777777
	 HRLI	T3,(POINT 7,0)	;REPLACE WITH REAL BYTE POINTER
	MOVEM	T3,ITEX.B+.RDRTY ;SET CONTROL-R BUFFER POINTER

ITEX.J:	XMOVEI	T1,ITEX.B	;ADDRESS OF ARG BLOCK
	TEXTI			;DO IT
	 ERJMP	R		;ERROR - LET HIM FIGURE IT OUT

;NOW FIGURE OUT WHY WE ARE HERE AND IF IT'S TIME TO GO

	MOVE	T1,ITEX.B+.RDFLG ;GET FLAGS
	TXNN	T1,RD%BTM	;DONE ON A BREAK?
	 RET			;NO - THIS IS SUPPOSED TO MEAN BUFFER FULL

	;...

;EXTRACT BREAK CHARACTER, AND BACK POINTER UP OVER IT.

	LDB	T1,ITEX.B+.RDDBP ;GET BREAK CHAR
	SETZ	T2,		;NULL
	DPB	T2,ITEX.B+.RDDBP ;TO TIE OFF BUFFER
	MOVX	T2,-1		;BACKUP
	ADJBP	T2,ITEX.B+.RDDBP ;POINTER
	MOVEM	T2,ITEX.B+.RDDBP ; AND RETURN IT
	AOS	ITEX.B+.RDDBC	;COUNT THE EXTRA SPACE AVAILABLE
	CAIE	T1,.CHCNZ	;CONTROL-Z?
	CAIN	T1,.CHESC	; OR ESCAPE?
	 RETSKP			; YES, ALL DONE

;HERE IT MUST BE CONTROL-B OR CONTROL-E OR CONTROL-K

	CAIN	T1,.CHCNB	;CONTROL-B?
	 JRST	ITEX.F		; YES - APPEND FILE TO BUFFER
	CAIN	T1,.CHCNE	;CONTROL-E?
	 JRST	ITEX.E		; YES - EDIT BUFFER
	CAIN	T1,.CHVTB	;CONTROL-K?
	 JRST	ITEX.K		; YES - REDISPLAY TEXT AND LOOP
	RET			;SOME KIND OF MISTAKE...
	SUBTTL	REDISPLAY CONTROL

;ITEX.K - HERE ON A CONTROL-K TO REDISPLAY THE BUFFER AND REENTER
;THE INPUT STATE

ITEX.K:	TMSG	<^K

>				;MAKE OURSELVES KNOWN WITH BLANK LINES
	MOVE	T1,ITEX.B+.RDBFP ;POINTER TO START OF BUFFER
	PSOUT			;REDISPLAY THE INPUT
	JRST	ITEX.J		; AND REENTER INPUT STATE
	SUBTTL	INSERT FILE CONTROL

;ITEX.F - HERE ON A CONTROL-B TO PROCESS AN INCLUDE FILE

ITEX.F:	TMSG <
(Insert file: >
	MOVX	T1,GJ%SHT+GJ%FNS+GJ%OLD+GJ%CFM ;FILE MUST EXIST
	MOVE	T2,[.PRIIN,,.PRIOU] ;TERMINAL
	GTJFN			;FIND THE FILE
	 ERJMP	ITEX.1		;FAILED
	MOVEM	T1,ITJFN	;SAVE THE JFN
	CALL	COPY		;COPY FILE INTO BUFFER
	 JRST	ITEX.1		;ERROR OF SOME SORT
	MOVE	T1,ITJFN	;DON'T NEED JFN ANYMORE
	RLJFN			; SO FLUSH IT
	 ERJMP	.+1		;(WHO CARES?)
	TMSG	<...EOF)
>				;SAY ITS THE END
	JRST	ITEX.J		;AND REENTER THE INPUT STATE


;HERE ON ERRORS IN THE ATTEMPT TO READ THE INCLUDE FILE - COMPLAIN AND RETRY

ITEX.1:	PERSTR	<
? Cannot process file: >	;COMPLAIN
	MOVE	T1,ITJFN	;GET THE JFN AND
	CLOSF			;TRY TO CLEAN UP
	 ERJMP	.+1
	MOVE	T1,ITJFN	;JFN AGAIN
	RLJFN
	 ERJMP	.+1
	JRST	ITEX.F		;AND TRY ALL OVER AGAIN
	SUBTTL	EDITOR CONTROL

;ITEX.E - HERE ON A CONTROL-E TO COPY THE BUFFER INTO A FILE AND
;INVOKE THE EDITOR, THEN COPY THE RESULTANT FILE BACK INTO THE BUFFER
;AND REENTER THE INPUT STATE

ITEX.E:	TMSG	<
>				;GET TO A NEW LINE FOR ESTHETICS SAKE
	MOVX	T1,GJ%SHT+GJ%TMP ;SHORT FORM GTJFN FOR TEMP FILE
	HRROI	T2,[ASCIZ/MSG.TMP;T/] ;THE FILENAME
	GTJFN			;GET A HANDLE
	 ERJMP	ITEX.2		;FAILURE
	MOVEM	T1,ITJFN		;SAVE THE JFN
	MOVX	T2,FLD(7,OF%BSZ)+OF%WR ;TO WRITE
	OPENF			;OPEN THE FILE TO WRITE
	 ERJMP	ITEX.2		;FAILURE
	MOVE	T2,ITEX.B+.RDBFP ;POINTER TO START OF BUFFER
	SETZ	T3,		;ENDS WITH A NULL
	SOUT			;OUTPUT THE BUFFER
	 ERJMP	ITEX.2		;FAILURE
	TXO	T1,CO%NRJ	;CLOSE, KEEPING JFN AROUND
	CLOSF			;CLOSE THE FILE
	 ERJMP	ITEX.2		;FAILURE

;BUILD THE EDIT COMMAND LINE

	HRROI	T1,ITSTR	;BUILD EDIT COMMAND STRING
	FMSG	<EDIT >		;IN ITSTR BUFFER
	 ERJMP	ITEX.2		;FAILURE
	MOVE	T2,ITJFN	;GET FILE JFN AS INPUT FILE
	MOVX	T3,JS%SPC	;FULL FILE SPEC
	SETZ	T4,0		;NO PREFIX STUFF
	JFNS			;ADD TO BUFFER
	 ERJMP	ITEX.2		;FAILURE
	FMSG	< >		;DELIMIT WITH A SPACE
	 ERJMP	ITEX.2		;FAILURE
	MOVE	T2,ITJFN	;GET FILE JFN AS OUTPUT FILE
	MOVX	T3,JS%SPC	;FULL FILE SPEC
	SETZ	T4,0		;NO PREFIX STUFF
	JFNS			;ADD TO BUFFER
	 ERJMP	ITEX.2		;FAILURE
	FMSG	<
>				;END WITH CRLF
	 ERJMP	ITEX.2		;FAILURE

	;...

;MAKE THE EDIT COMMAND AVAILABLE

	HRROI	T1,ITSTR	;POINT BACK TO START OF COMMAND
	RSCAN			; AND PUT IT INTO THE RSCAN BUFFER
	 ERJMP	ITEX.2		;FAILURE

	HRROI	T2,[ASCIZ/EDITOR:/] ;THE DESIRED EDITOR
	CALL	DOFORK		;TRY TO RUN IT
	 JRST	ITEX.2		;FAILED SOMEHOW...


;NOW COPY THE FILE BACK INTO THE BUFFER

	MOVE	T1,ITEX.B+.RDBFP ;RESET THE BUFFER
	MOVEM	T1,ITEX.B+.RDDBP ;BACK TO THE BEGINNING
	MOVE	T1,ITCNT	 ;GET SAVED USER BYTE COUNT
	MOVEM	T1,ITEX.B+.RDDBC ;RESET THE BYTE COUNT
	CALL	COPY		;READ IT BACK
	 JRST	ITEX.2		;SOME SORT OF ERROR...
	MOVE	T1,ITJFN	;GET JFN BACK AGAIN
	TXO	T1,DF%EXP	;SET EXPUNGE BIT
	DELF			;DELETE AND EXPUNGE THE CRITTER
	 ERJMP	.+1		;(TOUGH)
	TMSG	<
[Editing completed, type CTRL-K to redisplay]
>				;INFORM
	JRST	ITEX.J		;AND REENTER INPUT STATE


;HERE ON ERRORS TRYING TO RUN THE EDITOR

ITEX.2:	MOVX	T1,.PRIIN	;CLEAR INPUT BUFFER
	CFIBF			; IN CASE OF LEFTOVER RSCAN
	 ERJMP	.+1
	PERSTR	<
? Cannot edit text because: >	;COMPLAIN
	SKIPE	T1,ITJFN	;TRY TO CLEAN UP
	CLOSF
	 ERJMP	.+1
	SKIPE	T1,ITJFN
	RLJFN
	 ERJMP	.+1
	JRST	ITEX.J		;REENTER INPUT STATE AND HOPE...
	SUBTTL	COPY FILE INTO INPUT BUFFER

;COPY - COPY FILE WHOSE JFN IS IN ITJFN INTO THE BUFFER
;
;   RETURNS: +1	ON ERRORS
;	     +2 ON SUCCESS WHEN COMPLETED, JFN CLOSED BUT RETAINED
;
;TRIES TO HANDLE BUFFER FULL BY TRUNCATING FILE....

COPY:	MOVE	T1,ITJFN	;FETCH THE JFN
	MOVX	T2,FLD(7,OF%BSZ)+OF%RD ;READ ASCII
	OPENF			;OPEN THE FILE
	 ERJMP	R		;RETURN ON ERROR

COPY.L:	BIN			;READ A BYTE
	 ERJMP	COPY.X		; AND SEE IF DONE
	JUMPE	T2,COPY.L	;IGNORE NULLS
	IDPB	T2,ITEX.B+.RDDBP;ADD TO BUFFER
	SOSLE	ITEX.B+.RDDBC	;COUNT THE EXTRA SPACE USED
	JRST	COPY.L		;AND LOOP

;HERE WE RAN OUT OF SPACE.  TRY TO GET AWAY WITH TRUNCATING THE FILE...

	TMSG	<
[Buffer full, file is truncated]
>				;TRY TO WARN
	AOS	ITEX.B+.RDDBC	;MAKE A LITTLE SPACE
	MOVE	T1,ITJFN	;GET JFN BACK AND CLOSE
	JRST	COPY.C		;CLOSE

COPY.X:	GTSTS			;GET FILE CONDITION
	TXNN	T2,GS%EOF	;NORMAL END-OF-FILE?
	 RET			; NO - ERROR
COPY.C:	TXO	T1,CO%NRJ	;KEEP THE JFN ABOUT BUT
	CLOSF			; YES, CLOSE FILE
	 RET			;FAILED
	MOVE	T1,ITEX.B+.RDDBP ;COPY OF BYTE POINTER
	SETZ	T2,0		;APPEND A NULL BYTE TO
	IDPB	T2,T1		;MAKE SURE BUFFER IS ASCIZ
	RETSKP			;SUCCESS RETURN
	SUBTTL	DOFORK - RUN THE SPECIFIED FILE

;DOFORK - RUN THE FILE WHOSE NAME IS POINTED TO BY T2
;
;	RETURNS  +1:	ON ERRORS
;		 +2:	ON SUCCESS AFTER THE FORK COMPLETES

DOFORK:	MOVX	T1,GJ%SHT+GJ%OLD ;GTJFN BITS FOR EXISTING FILE
	GTJFN			;TRY TO FIND IT
	 ERJMP	R		; FAILED
	MOVEM	T1,ITFRK	;STORE JFN TEMPORARILY
	MOVX	T1,CR%CAP	;PASS OUR CAPS
	CFORK			; INTO A NEW FORK
	 ERJMP	DOFO.1		;FAILED
	HRLM	T1,ITFRK	;SAVE IT
	MOVE	T1,ITFRK	;FORK,,JFN
	GET			;GET THE FILE
	 ERJMP	DOFO.1		;FAILED
	HLLZS	ITFRK		;JFN PASSED TO GETTED FORK NOW
	HLRZ	T1,ITFRK	;FORK HANDLE AGAIN
	SETZ	T2,		;NO OFFSET
	SFRKV			;RUN IT
	 ERJMP	DOFO.1		;FAILED
	WFORK			;WAIT FOR IT
	 ERJMP	DOFO.1		;FAILED BADLY SOMEHOW...
	KFORK			; AND CROAK IT WHEN DONE (RFSTS FOR OK?)
	 ERJMP	.+1		;OH WELL...
	SETZM	ITFRK		;NO MORE FORK
	RETSKP			;SUCCESS RETURN

DOFO.1:	HLRZ	T1,ITFRK	;GET FORK HANDLE
	SKIPE	T1		;DON'T TRY IF NONE
	KFORK			;DUMP IT
	 ERJMP	.+1
	HRRZ	T1,ITFRK	;GET JFN BACK
	SKIPE	T1		;DON'T TRY IF NONE
	RLJFN			;DUMP IT
	 ERJMP	.+1
	RET			;DONE WITH ERRORS
	SUBTTL	DATA AREA


ITJFN:	BLOCK	1		;JFN FOR INSERT OR EDIT FILE
ITFRK:	BLOCK	1		;FORK HANDLE FOR EDITOR
ITCNT:	BLOCK	1		;SAVED USER BYTE COUNT FOR BUFFER
ITSTR:	BLOCK	200/5+1		;STRING BUFFER FOR EDIT COMMAND
ITEX.B::
	.RDBRK			;.RDCWB - COUNT OF WORDS IN ARG BLOCK
	RD%BRK!RD%JFN		;.RDFLG - FLAGS WORD
	.PRIIN,,.PRIOU		;.RDJFN - JFNS TO USE
	Z			;.RDDBP - DESTINATION POINTER
	Z			;.RDDBC - DESTINATION BYTE COUNT
	Z			;.RDBFP - BACKUP POINTER FOR .RDDBP
	Z			;.RDRTY - CONTROL-R BUFFER POINTER
	ITEX.M			;.RDBRK - ADDRESS OF BREAK MASK.

ITEX.M:	BRINI.			;INITIALIZE BREAK MASK
	BRKCH.	.CHCNB		;CONTROL-B
	BRKCH.	.CHCNE		;CONTROL-E
	BRKCH.	.CHVTB		;CONTROL-K
	BRKCH.	.CHCNZ		;CONTROL-Z
	BRKCH.	.CHESC		;ESCAPE
	EXP	W0.,W1.,W2.,W3.	; AND GENERATE THE MASK WORDS


	END