Google
 

Trailing-Edge - PDP-10 Archives - k20v7c - mfg/src/conmac.mac
There are no other files named conmac.mac in the archive.
	TITLE CONMAC
	INTERNAL CONMAC
	JS1=1
	JS2=2
	JS3=3
	ARG=4
	PNT=5
	T1=6
	T2=7
	CMD=10
	CNT=11
	T3=12
	SPNT=13
	T4=14
	P=17
	SEARCH MONSYM


CONMAC:	PUSH P,0
	PUSH P,1
	PUSH P,2
	PUSH P,3
	PUSH P,4
	PUSH P,5
	PUSH P,6
	PUSH P,7
	PUSH P,10
	PUSH P,11
	PUSH P,12
	PUSH P,13
	PUSH P,14

CMDIN:	MOVE ARG,(16)		;ARG/STARTING LOC OF ARG LIST
	MOVE CMD,@ARG		;CMD/MACCOMMAND

	CAIN CMD,^D1		;OPEN FILE FOR READ?
	JRST OPFIRD
	CAIN CMD,^D2		;OPEN FILE FOR WRITE?
	JRST OPFIWR
	CAIN CMD,^D4		;CLOSE FILE?
	JRST CLFILE
	CAIN CMD,^D6		;LOOKUP FILE?
	JRST LOOKUP
	CAIN CMD,^D11		;READ LINE FROM FILE?
	JRST RDLINE
	CAIN CMD,^D12		;WRITE LINE TO FILE?
	JRST WRLINE

	CAIN CMD,^D20		;REPLACE ITEM?
	JRST REPLAC
	CAIN CMD,^D21		;SEARCH COMMAND?
	JRST REPLAC

	HRROI JS1,[ASCIZ/
? ERROR ENTERED CONMAC WITH NO COMMAND?/]
	PSOUT
	JRST EXIT
	JRST EXIT
	
OPFIRD:	MOVE ARG,1(16)		;ARG/SECOND LOC OF ARG LIST
	MOVE JS2,@ARG		;JS2/POINTER TO FILENAME
	HRLZI JS1,(GJ%OLD+GJ%SHT)	;MUST BE OLD FILE/ SHORT FORM
	GTJFN			;JS1/JFN
	 ERJMP [MOVE JS1,@ARG
		MOVEI CNT,^D29
		ADJBP CNT,JS1
		MOVEI JS1,0
		DPB JS1,CNT
		MOVE JS1,@ARG
		PSOUT
		JUMPA ERROR]
	PUSHJ P,SAVJFN
	MOVE JS2,[7 B5+OF%RD]
OFRD:	OPENF			;OPEN FILE
	 ERJMP [MOVE JS1,@ARG
		MOVEI CNT,^D29
		ADJBP CNT,JS1
		MOVEI JS1,0
		DPB JS1,CNT
		MOVE JS1,@ARG
		PSOUT
		JUMPA ERROR]
	JRST EXIT

SAVJFN:	MOVE ARG,2(16)		;ARG/LOCATION OF THIRD ARGUMENT (JFN)
	HRLI JS1,0
	MOVEM JS1,@ARG
	POPJ P,



LOOKUP:	MOVE ARG,1(16)		;ARG/SECOND LOC OF ARG LIST
	MOVE JS2,@ARG		;JS2/POINTER TO FILENAME
	HRLZI JS1,(GJ%OLD+GJ%SHT)	;MUST BE OLD FILE/ SHORT FORM
	GTJFN			;IF FILE EXITS JS1/JFN
	 ERJMP [MOVE ARG,(16)
		SETZM @ARG	;IF LOOKUP FAILED RETURE A CMD OF 0
		JRST EXIT]
	RLJFN			;NOW RELEASE IT
	 ERJMP ERROR
	JRST EXIT



OPFIWR:	MOVE ARG,1(16)		;ARG/SECOND LOC OF ARG LIST
	MOVE JS2,@ARG		;JS2/POINTER TO FILENAME
	HRLZI JS1,(GJ%FOU+GJ%SHT)	;SHORT FORM
	GTJFN			;JS1/JFN
	 ERJMP [MOVE JS1,@ARG
		MOVEI CNT,^D29
		ADJBP CNT,JS1
		MOVEI JS1,0
		DPB JS1,CNT
		MOVE JS1,@ARG
		PSOUT
		JUMPA ERROR]
	PUSHJ P,SAVJFN
	MOVE JS2,[7 B5+OF%WR]
OFWR:	OPENF			;OPEN FILE
	 ERJMP [MOVE JS1,@ARG
		MOVEI CNT,^D29
		ADJBP CNT,JS1
		MOVEI JS1,0
		DPB JS1,CNT
		MOVE JS1,@ARG
		PSOUT
		JUMPA ERROR]
	JRST EXIT

CLFILE:	MOVE ARG,1(16)		;ARG/SECOND LOC OF ARG LIST
	MOVE JS1,@ARG		;JS2/POINTER TO FILENAME
	HRLI JS1,0
CLF:	CLOSF
	 ERJMP [MOVE JS1,@ARG
		MOVEI CNT,^D29
		ADJBP CNT,JS1
		MOVEI JS1,0
		DPB JS1,CNT
		MOVE JS1,@ARG
		PSOUT
		JUMPA ERROR]
	JRST EXIT



RDLINE:	MOVE ARG,1(16)		;ARG/SECOND LOC OF ARG LIST
	MOVE PNT,@ARG		;PNT/POINTER FOR MAC-REC
	MOVE ARG,2(16)		;ARG/THIRD LOC OF ARG LIST
	HRRZ JS1,@ARG		;JS1/0,,MAC-JFN
	MOVEI T1,^D132		;SET UP MAXIMUM LINE WIDTH OF 132 +CR,LF
RDLOOP:	BIN		;READ A BYTE FROM FILE
	 ERJMP [GTSTS		;ERROR GET STATUS
		TLNE JS2,(GS%EOF)	;AT END OF FILE?
		JRST RDEOF	
		JUMPA ERROR]	;NO POSSIBLY DATA ERROR
		
	CAIN JS2,012		;!!!TERMINATE ON A LINE FEED!!!
	JRST EXIT
	SOJL T1,RDLOOP		;STOP STORING AFTER 132 CHARS BUT CONT TO LF
	CAIN JS2,015		;DON'T STORE CR'S
	JRST RDLOOP
	IDPB JS2,PNT		;STORE BYTE IN MAC-REC
	JRST RDLOOP		;CONTINUE

RDEOF:	MOVE ARG,(16)		;RETURNING A CMD OF ZERO SIGNIFIES EOF
	SETZM @ARG
	JRST EXIT		;TERMINATE
	

WRLINE:	MOVE ARG,1(16)		;ARG/SECOND ARG IN ARG LIST
	MOVE PNT,@ARG		;PNT/POINTER FOR MAC-REC
	MOVE T2,[^D132]
	ADJBP T2,PNT		;ADJUST THE BYTE POINTER AHEAD 132 BYTES
	MOVEM T2,PNT
	MOVE T2,[^D132]

WRTST:	LDB T1,PNT		;GET A BYTE
	CAIN T1," "		;NULL OUT TRAILING SPACES
	JRST WRNULL
	CAIN T1,0		;AND NULLS
	JRST WRNULL
	CAIN T1,012		;AND LINE FEEDS
	JRST WRNULL
	CAIN T1,015		;AND CARRIAGE RETURNS
	JRST WRNULL
	JRST WROUT		;FOUND LAST CHAR


WRNULL:	HRRI T1,0
	DPB T1,PNT		;REPLACE TRAILING SPACES WITH NULLS
	SOJLE T2,WROUT		;CHECK TO SEE IF AT BEG OF LINE
	MOVE T1,[-1]
	ADJBP T1,PNT		;ADJ POINTER BACK 1 BYTE
	MOVEM T1,PNT
	JRST WRTST		;LOOP UNTIL HIT NONSPACE OR BEG OF LINE

WROUT:	MOVE PNT,@ARG		;GET INITAIL POINTER BACK
	MOVE ARG,2(16)
	HRRZ JS1,@ARG		;JS1/0,,JFN

WRLP:	SETZM JS2,JS2
	ILDB JS2,PNT		;JS2/BYTE
	CAIN JS2,0		;IS IT A NULL?
	JRST WREND		;SKIP AND GO OUPUT CR,LF
	BOUT			;OUTPUT THE BYTE
	JRST WRLP

WREND:	MOVEI JS2,015
	BOUT			;OUTPUT A CR
	MOVEI JS2,012
	BOUT			;OUTPUT A LF
	JRST EXIT

REPLAC:	MOVE ARG,2(16)		;ARG/3RD LOC OF ARGLIST
	MOVE JS2,@ARG		;JS2/POINTER FOR OLD-ITEM

;FIRST FIGURE SIZE OF OLD-ITEM

	MOVE PNT,JS2
	MOVE CNT,[^D99]
	MOVE JS3,CNT
	ADJBP JS3,PNT		;ADJ PNT AHEAD 99 PLACES
	MOVEM JS3,PNT

REPSIZ:	LDB T2,PNT
	CAIE T2," "		;LOOK FOR A NON SPACE
	JRST REPCHA
	MOVE JS3,[-1]
	ADJBP JS3,PNT		;MOVE PNT BACK A SPACE
	MOVEM JS3,PNT
	SOJL CNT,EXIT		;OLD-ITEM MUST NOT BE ALL SPACES
	JRST REPSIZ		;LOOP UNTIL HIT NON-SPACE

REPCHA:	MOVEM CNT,JS3		;SAVE SIZE OF OLD-ITEM IN JS3

;NOW SEARCH FOR THE STRING IN THE OLD-LINE

	MOVE T3,[^D130]		;T3/USED TO COUNT RECORD SIZE
	MOVE ARG,1(16)		;ARG/2ND LOC OF ARGLIST
	MOVE PNT,@ARG		;PNT/POINTER FOR OLD-LINE
	MOVEI T4,^D131
	ADJBP T4,PNT		;T4/CUTOFF LIMIT FOR COPYING TO NEW-LINE
	MOVE PNT,@ARG
	MOVE SPNT,PNT		;SPNT/POINTER FOR OLD-LINE OLD-ITEM

REPTST:	MOVE JS1,JS2		;RESTORE POINT FOR OLD-ITEM.

TSTLOP:	ILDB T1,PNT
	SOJL T3,EXIT		;QUIT LOOKING AFTER 132 CHARS
	ILDB T2,JS1

	CAME T1,T2
	JRST [MOVE SPNT,PNT
		MOVE CNT,JS3	;RESTORE COUNT = SIZE OF CURRENT ITEM
		JRST REPTST]

REGOO:	SOJG CNT,TSTLOP		;LOOP UNTIL ENTIRE ITEM MATCHES

;HERE WHEN ITEM FOUND
	MOVE ARG,(16)
	SETZM @ARG		;RETURNING CMD OF 0 MEANS SEARCH SUCCESS
	CAIN CMD,^D21
	JRST EXIT		;IF CMD IS SEARCH EXIT

;NOW GO ABOUT REPLACING ITEM
	MOVEM PNT,JS2		;SAVE POINTER FOR LAST PART OF OLD-LINE
	MOVE ARG,4(16)
	MOVE JS1,@ARG		;JS1/POINTER FOR NEW-RECORD
	MOVE ARG,1(16)		;ARG/2ND LOC OF ARGLIST
	MOVE PNT,@ARG		;PNT/POINTER FOR OLD RECORD
	MOVE T3,[^D131]		;LIMIT FOR BYTES TRANSFERED TO NEW-LINE

;COPY OLD LINE TO NEW LINE UP TO START OF OLD ITEM
REPLOP:	CAMN PNT,SPNT		;UNTIL HIT OLD-ITEM
	JRST REPIN
	ILDB T1,PNT		;LOAD FROM OLD-LINE
	IDPB T1,JS1		;INTO NEW-LINE
	SOJL T3,EXIT
	JRST REPLOP

;NOW FIGURE SIZE OF NEW ITEM
REPIN:	MOVE ARG,3(16)		;ARG/4TH LOC OF ARGLIST
	MOVE PNT,@ARG		;PNT/POINTER FOR NEW-ITEM
	MOVE T2,[^D99]
	MOVE CNT,T2
	ADJBP T2,PNT		;ADJST POINT FOR NEW-ITEM AHEAD 100 CHARS
	MOVEM T2,PNT

NSLOP:	MOVE T2,[-1]		;ADJ PNT BACK 1 CHAR
	ADJBP T2,PNT
	MOVEM T2,PNT
	LDB T2,PNT
	CAIN T2,040		;UNTIL HIT NON SPACE
	JRST [SOJG CNT,NSLOP	;DON'T GO PAST BEG OF NEW-ITEM
		JRST NSLXIT]	;IF ALL SPACES SIZE = 0
	SOJA CNT,.+1		;

;NOW INSERT THE NEW-ITEM

NSLXIT:	MOVE PNT,@ARG		;RESTORE POINTER FOR NEW-ITEM

RINLOP:	SOJL CNT,RINXIT		;CNT/NUMBER OF CHARS IN NEW ITEM
	ILDB T1,PNT
	IDPB T1,JS1
	SOJL T3,EXIT		;STOP ADDING TO NEW LINE AFTER 132 CHARS
	JRST RINLOP

;NOW RESTORE THE REMAINDER OF ORIG LINE
RINXIT:	MOVE PNT,JS2		;PNT/POINTER FOR REMAINDER OF OLD-LINE

;MISSING A BYTE?

REPEND:	CAMN T4,PNT		;BUT DON'T GO PAST END OF ORIG LINE
	JRST EXIT
	ILDB T1,PNT
	IDPB T1,JS1
	SOJL T3,EXIT		;KEEP ADDING CHARS FROM OLD LINE UNT LINE FULL
	JRST REPEND


ERROR:	MOVEI JS1,40		;OUTPUT A SPACE
	PBOUT
	HRRI JS2,777777		;MOST RECENT ERROR
	HRLI JS2,400000		;FOR CURRENT PROCESS
	MOVEI JS1,.PRIOU	;OUTPUT TO TERM
	MOVEI JS3,0		;NO LIMIT ON MESSAGE
	ERSTR			;CONVERT ERRNUM AND PRINT MESSAGE
	JRST .+1
	JRST .+1
	HRROI JS1,[ASCIZ/
%IO ERROR - CONTINUE ? (Y,N)  /]
	PSOUT
	PBIN
	CAIN JS1,"N"
	HALTF
	CAIE JS1,"Y"
	JRST ERROR
	JRST EXIT


EXIT:
	POP P,14
	POP P,13
	POP P,12
	POP P,11
	POP P,10
	POP P,7
	POP P,6
	POP P,5
	POP P,4
	POP P,3
	POP P,2
	POP P,1
	POP P,0
	POPJ P,

	END