perm filename LODREQ.FAI[S,AIL] blob sn#218370 filedate 1976-06-10 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002		TITLE	LODREQ	CHASE DOWN LOAD MODULE AND LIBRARY REQUESTS
C00005 00003	LODREQ:	RESET
C00011 00004	GETCMD:
C00018 ENDMK
C⊗;
	TITLE	LODREQ	CHASE DOWN LOAD MODULE AND LIBRARY REQUESTS
COMMENT ⊗
	Command string is similar to loader format:
		<out file>←<in file>,<in file>, ... ,<in file><alt>
	"Switches" are not allowed.  
⊗


?P←17
FF←0
A←1
B←2
C←3
D←4
T0←5
T1←6
T2←10
T3←11
T4←12
 T←T0
Q←13		;LAST,,FIRST	FILE DESCRIPTOR BLOCKS TO BE PROCESSED
DON←14		;FILES ALREADY PROCESSED
L←15		;LOW LIMIT OF CORE ALLOCATION
SR←16		;USED FOR FASTER SKIP RETURNS

IC←0		;CHANNELS
OC←1
EOF←←20000

$LNK←←0		;OFFSETS IN REQUEST BLOCKS
$EXT←←1
$FIL←←2
$PPN←←3
$DEV←←4
$LEN←←5		;LENGTH OF BLOCK

.LOD←←16	;LOADER BLOCK TYPES
.LIB←←17
.IDX←←14

EXTERNAL .JBFF,.JBREL

GETLCOR:MOVE	L,.JBFF
	MOVEI	T,-1+$LEN(L)	;HIGHEST ADDRESS WE NEED
GETCOR:
	CAMG	T,.JBREL
	 POPJ	P,		;IF WE ALREADY HAVE IT
	CORE	T,
	 JRST	[CORERR:OUTSTR	[ASCIZ/
CORE failed./]
		HALT	.
		POPJ	P,]
	POPJ	P,

FILERR:
	OUTSTR	(A)		;WHO FAILED
	PUSH	P,[OUTCHR C]	;DELIVER TO TERMINAL
	PUSHJ	P,FILPRT
	RELEASE	IC,
	RELEASE	OC,
	HALT	.
	JRST	LODREQ

FILPRT:				;-1(P)=INSTR TO XCT TO DISPOSE OF CHAR IN C
	MOVE	D,-1(P)		;INSTR TO XCT TO DISPOSE OF CHAR IN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	MOVE	T2,ALIAS
	MOVE	T1,$FIL(Q)
	MOVEI	T,DON
	JRST	DUPCHK
DUPTOP:	CAMN	T1,$FIL(T)
	CAME	T2,$PPN(T)
	 JRST	DUPCHK
	CAMN	T3,$DEV(T)
	 JRST	ISDUP
DUPCHK:	HRRZ	T,(T)
	JUMPN	T,DUPTOP
ISNEW:
	PUSHJ	P,CRLF
	PUSH	P,[PUSHJ P,CHROUT]
	PUSHJ	P,FILPRT	;IDENTIFY THIS FILE
	MOVEM	T3,$DEV(Q)	;BE SURE THESE ARE WELL DEFINED
	MOVEM	T2,$PPN(Q)
	MOVEM	T3,DEVOPN	;PREPARE TO READ THE FILE
	OPEN	IC,OPNADR
	 JRST	[MOVEI	A,[ASCIZ/
OPEN failed./]
		JRST	FILERR]
	MOVEM	T1,LOKADR	;FILENAME
	MOVEM	T4,LOKADR+1	;EXTENSION
	MOVEM	T2,LOKADR+3	;PPN
	LOOKUP	IC,LOKADR
	 JRST	[MOVEI	A,[ASCIZ/
LOOKUP failed./]
		JRST	FILERR]

	SKIPN	T,BUFLOC	;PUT BUFFER RING IN SAME PLACE ALL THE TIME
	 MOVE	T,.JBFF
	EXCH	T,.JBFF
	INBUF	IC,=19		;TRACK AT A TIME AT STANFORD
	SKIPE	BUFLOC
	 JRST	BL.1
	MOVEM	T,BUFLOC	;WAS FIRST TIME, SO BUFLOC← OLD .JBFF
	JRST	NXTTAB		;AND LEAVE .JBFF ALONE
BL.1:	MOVEM	T,.JBFF		;NOT FIRST TIME, RESTORE .JBFF
NXTTAB:
	PUSHJ	P,WORDIN	;RETURN WORD IN C
	 JRST	ISDUP		;END OF FILE
	JUMPE	C,NXTTAB	;ZERO WORDS ARE A PAIN
	HLRZ	T,C		;TABLE TYPE
	CAIE	T,.LOD
	CAIN	T,.LIB
	 JRST	QBLOCK		;FOUND ONE WE WANT

				;DISCARD. TABLE TYPE IN T, "COUNT" IN RH(C)
	CAIN	T,.IDX		;INDEX BLOCKS ARE SPECIAL
	 JRST	[MOVEI	T,(C)	;NO RELOC BITS HERE
		JRST	SKE.1]
SKEOP1:	MOVEI	T,(C)		;WORD COUNT
	JUMPE	T,NXTTAB	;ZERO WORDS ARE A PAIN
	CAIG	T,22		;ONE SUBBLOCK?
	 AOJA	T,SKE.1		;YES, COUNT ITS RELOC BITS
	IDIVI	T,22		;WHOLE BLOCKS
	IMULI	T,23		;WORDS IN WHOLE BLOCKS
	JUMPE	T+1,.+2		;NO REMAINDER
	ADDI	T,1(T+1)	;PARTIAL BLOCK HAS RELOC BITS
SKE.1:	CAML	T,IBUF+2	;ENOUGH IN CURRENT BUFFER?
	 JRST	SKE32		;NO
	ADDM	T,IBUF+1	;INCR BYTE POINTER
	MOVNI	T,(T)
	ADDM	T,T,IBUF+2	;DECR COUNT
	JRST	NXTTAB
SKE32:	SUB	T,IBUF+2	;HAD THIS MANY
	PUSHJ	P,WORDIN+1	;FORCE NEXT BUFFER
	 JRST	[TABERR:MOVEI	A,[ASCIZ/
File format error./]
		PUSHJ	P,FILERR]
	JRST	SKE.1		;DELECTE SOME MORE

QBLOCK:
	MOVEI	T4,(T)		;SAVE TABLE TYPE
	MOVEI	FF,(C)		;# DATA WORDS
	PUSHJ	P,WORDIN	;IGNORE RELOC WORD
	 JRST	TABERR
QBLK.1:
	PUSHJ	P,GETLCOR
	PUSHJ	P,WORDIN	;READ THE ENTRIES INTO BLOCK AT  (L)
	 JRST	TABERR
	MOVEM	C,$FIL(L)
	PUSHJ	P,WORDIN
	 JRST	TABERR
	MOVEM	C,$PPN(L)
	PUSHJ	P,WORDIN
	 JRST	TABERR
	MOVEM	C,$DEV(L)
	SETZM	$EXT(L)

	HLRZ	T,Q		;BASE OF CURRENT LAST ELEMENT
	HRRZM	L,$LNK(T)	;PUT THIS ONE AT END
	SETZM	$LNK(L)
	HRLI	Q,(L)
	MOVEI	L,$LEN
	ADDM	L,.JBFF
	PUSHJ	P,CRLF
	CAIE	T4,.LIB
	 JRST	QBLK.2
	MOVEI	C," "
	PUSHJ	P,CHROUT
	MOVEI	C," "
	PUSHJ	P,CHROUT
	MOVEI	C," "
	PUSHJ	P,CHROUT
	MOVEI	C,"L"
	PUSHJ	P,CHROUT
	MOVEI	C,"I"
	PUSHJ	P,CHROUT
	MOVEI	C,"B"
	PUSHJ	P,CHROUT
QBLK.2:
	MOVEI	C,11
	PUSHJ	P,CHROUT	;INDENT REQUIRED FILE
	MOVS	Q,Q		;PRINT THE FILE NAME AT END OF QUEUE
	PUSH	P,[PUSHJ P,CHROUT]
	PUSHJ	P,FILPRT
	MOVS	Q,Q		;RESTORE Q TO LAST,,FIRST
	SUBI	FF,3
	JUMPN	FF,QBLK.1	;LOOP FOR ALL FILES IN TABLE
	JRST	NXTTAB		;WE ATE THIS ONE THE HARD WAY

FIN:	RELEASE	IC,
	RELEASE	OC,
	OUTSTR	[ASCIZ/
/]
	JRST	LODREQ
GETCMD:
define ch.alt<175>	;favorite flavor of altmode
	OUTCHR	["*"]
	SETZM	DEVNAM
	SETZM	NARROW#	;ASSUME "←"
	SETZM	ONAME
	PUSH	P,[0]		;DEFAULT EXTENSION
	PUSHJ	P,GETFIL	;TRY FOR LISTING FILE
	 JRST	[SKIPN	T,DEVNAM	;DEVICE ONLY
		  JRST	TTYOUT
		JRST	.+1
		TTYOUT:MOVSI	T,'TTY'
		MOVEM	T,OUTDEV
		MOVEM	T,ONAME
		JRST	GETO]
	CAIE	1,"←"
	CAIN	1,"="
	JRST	.+2
	 JRST	[SETOM NARROW↔JRST TTYOUT]
	SKIPN	FILNAM
	 JRST	TTYOUT	;NO FILE NAME, MUST BE TTY
	SKIPN	T,DEVNAM
	 MOVSI	T,'DSK'	;FILL IN DEFAULT
	MOVEM	T,OUTDEV
GETO:	OPEN	OC,OPNOUT
	 JRST	[OUTSTR	[ASCIZ/
Cannot OPEN output device./]
		HALT	.-1]
	SKIPN	T,ONAME
	 MOVE	T,FILNAM
	MOVEM	T,ONAME
	MOVE	T,EXTION
	MOVEM	T,ONAME+1
	SETZM	ONAME+2
	MOVE	T,PPPN
	MOVEM	T,ONAME+3
	ENTER	OC,ONAME
	 JRST	[OUTSTR	[ASCIZ/
Cannot ENTER output file./]
		HALT	.-1]

	PUSHJ	P,GETLCOR
	MOVSI	Q,(L)		;INITIAL QUEUE IS EMPTY
	HRRI	Q,(L)
	SETZM	(Q)
	MOVEI	L,$LEN
	ADDM	L,.JBFF
GETLUP:
	SKIPE	NARROW
	 JRST	[SETZM	NARROW	;REUSE FIRST FILE NAME
		JRST	GETL.1]
	PUSH	P,['REL   ']
	SETZM	DEVNAM
	PUSHJ	P,GETFIL
	 JRST	[OUTSTR	[ASCIZ/
Bad file spec./]
		JRST	GETCMD]
GETL.1:	PUSHJ	P,GETLCOR
	MOVE	T,FILNAM
	MOVEM	T,$FIL(L)
	MOVE	T,EXTION
	MOVEM	T,$EXT(L)
	MOVE	T,DEVNAM
	MOVEM	T,$DEV(L)
	MOVE	T,PPPN
	MOVEM	T,$PPN(L)
	HLRZ	T4,Q		;LAST ON QUEUE
	HRRZM	L,(T4)		;LINK THIS ONE TO CURRENT LAST ONE
	SETZM	(L)		;ZERO OUT LINK
	HRLI	Q,(L)
	MOVEI	L,$LEN
	ADDM	L,.JBFF
	CAIE	1,CH.ALT
	 JRST	GETLUP		;CONTINUE UNTIL ALTMODE
	POPJ	P,
	
	
;GET FILE SPEC FROM TTY LINE (STOLEN FROM GRUMP[X,AIL])
;uses 0,1,2,3,4
;called via
;	push	p,[<default extension>]
;	pushj	p,getfil
;	 <no file name, or device only specified>
;	<success return>	;char which broke the scan in is 1
begin getfil
	opdef go [jrst]
	define pop0j <popj p,>
	define pop2j <jrst[sub p,[2,,2]↔jrst @2(p)]>
	define pop3j <jrst[sub p,[3,,3]↔jrst @3(p)]>
	define arg2 <-1(p)>
↑getfil:
	SETZM FILNAM↔SETZM EXTION↔SETZM SQCNT#	;BRACKET NEST DEPTH
	SETZM EXTION+1↔SETZM PPPN
	MOVE 4,[POINT 6,FILNAM,-1]↔MOVEI 2,6
	INCHWL 1↔CAIN 1,15↔GO[INCHWL↔POP2J]↔AOS(P)
	CAIN 1,"?"↔GO[OUTSTR[ASCIZ/This program chases load requests.
outfile←infile,infile, ...,infile<ALT>
*/]
			CLRBFI↔JRST GETFIL]
	JRST L+1
L:	INCHWL 1
	CAILE 1,"z"↔POP2J
	CAIL 1,"a"↔SUBI 1,40		;CONVERT LOWER CASE
	CAIN 1,":"↔GO[MOVE 4,FILNAM↔MOVEM 4,DEVNAM↔SOS (P)↔GO GETFIL]
	CAIN 1,"."↔GO[MOVE 4,[POINT 6,EXTION,-1]↔MOVEI 2,3↔GO L]
	CAIN 1,"["↔GO[AOS SQCNT↔MOVE 4,[POINT 6,PPPN,-1]  ↔MOVEI 2,3↔GO L]
	CAIN 1,","↔GO[SKIPN SQCNT↔JRST EOL+1	;TOP-LEVEL COMMA
			HLRZ PPPN
		      PUSHJ P,[PPJUST:	JUMPE [OUTSTR[ASCIZ/BAD P,PN
/]↔						CLRBFI↔SOS -1(P)↔POP3J]	
		   	 		TRNE 77↔POP0J↔LSH -6↔GO PPJUST]
		      HRLM PPPN↔MOVE 4,[POINT 6,PPPN,17]↔MOVEI 2,3↔GO L]
	CAIN 1,"]"↔GO[SOS SQCNT↔HRRZ PPPN↔PUSHJ P,PPJUST
		   HRRM PPPN↔INCHWL 1↔GO FINQ]
FINQ:	CAIN 1,15↔GO EOL			;END OF THE LINE.
	CAIN 1,12↔POP2J
	 CAIE 1,"←"
	CAIN 1,"="↔GO EOL+1	;SEPARATING EQUALS OR LEFT ARROW
	CAIN 1,CH.ALT↔GO EOL+1	;TERMINATING ALTMODE
	CAIG 1," "↔GO L	;IGNORE GARBAGE.
	SOJL 2,L↔SUBI 1,40↔IDPB 1,4↔GO L

EOL:	INCHWL 2
	SKIPN 2,EXTION↔MOVE 2,ARG2↔MOVEM 2,EXTION
	POP2J
BEND


WORDIN:	SOSG	IBUF+2
	IN	IC,
	JRST	WORD.1
	STATZ	IC,EOF
	POPJ	P,		;YES EOF, NO SKIP RETURN
	MOVEI	A,[ASCIZ/
IN error./]
	JRST	FILERR
WORD.1:	ILDB	C,IBUF+1
	POP	P,SR
	JRST	1(SR)


CRLF:	MOVEI	C,15
	PUSHJ	P,CHROUT
	MOVEI	C,12
CHROUT:	SOSG	OBUF+2		;PUT CHAR IN  C  INTO OUTPUT BUFFER
	OUT	OC,
	JRST	CHROU1
	OUTSTR	[ASCIZ/
OUT failed./]
	HALT	.-2
CHROU1:	IDPB	C,OBUF+1
	POPJ	P,

OPNADR:	14	;BUFFERED BINARY
DEVOPN:	BLOCK	1
	0,,IBUF	;HEADER AT IBUF

OPNOUT:	0	;ASCII CHARACTERS
OUTDEV:	BLOCK	1
	OBUF,,0	;HEADER AT OBUF

DEVNAM:	0
FILNAM:	0	;FILE NAME.
EXTION:	0	;EXTENSION.
	0
PPPN:	0	;PROJECT-PROGRAMMER.

IBUF:	BLOCK	3
LOKADR:	BLOCK	4

OBUF:	BLOCK 3
ONAME:	BLOCK	4
LPDL←←10
	PDL:	BLOCK LPDL

	END	LODREQ