Google
 

Trailing-Edge - PDP-10 Archives - BB-4170G-SM - sources/futili.mac
There are 49 other files named futili.mac in the archive. Click here to see a list.
;<3-MONITOR>FUTILI.MAC.91,  7-Nov-77 13:02:12, EDIT BY KIRSCHEN
;MORE COPYRIGHT UPDATING...
;<3-MONITOR>FUTILI.MAC.90, 12-Oct-77 13:47:48, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>FUTILI.MAC.89, 20-Sep-77 15:17:41, EDIT BY HURLEY
;PERFORMANCE IMPROVEMENT - GET STR NUMBER FROM UNIQUE CODE IN CNVSTR
;<3-MONITOR>FUTILI.MAC.88,  3-Aug-77 14:31:16, EDIT BY HALL
;MAKE CPYTU1 WORK FROM ANY SECTION
;<3-MONITOR>FUTILI.MAC.87, 14-Jun-77 20:16:45, EDIT BY OSMAN
;ADD CPYTU1 ROUTINE.
;<3-MONITOR>FUTILI.MAC.86,  2-May-77 20:32:43, EDIT BY BOSACK
;<3-MONITOR>FUTILI.MAC.85, 28-Feb-77 04:36:55, EDIT BY CROSSLAND
;TCO 1744 ADD CPYFU2 ROUTINE FOR CRJOB JSYS
;<3-MONITOR>FUTILI.MAC.84, 23-Jan-77 15:10:21, Edit by MCLEAN
;<3-MONITOR>FUTILI.MAC.83, 27-Dec-76 17:32:38, EDIT BY HURLEY
;<3-MONITOR>FUTILI.MAC.82, 27-Nov-76 22:01:56, Edit by MCLEAN
;<3-MONITOR>FUTILI.MAC.81, 25-Nov-76 02:09:58, Edit by MCLEAN
;TCO 1669 EXTENDED ADDRESSING
;<2-MONITOR>FUTILI.MAC.80,  2-Nov-76 14:58:42, EDIT BY MILLER
;<2-MONITOR>FUTILI.MAC.79,  2-Nov-76 14:38:42, EDIT BY MILLER
;TCO 1642. CHECK BYTE POINTER BEFORE GOING NOINT IN CPYFUS
;<2-MONITOR>FUTILI.MAC.78,  1-Nov-76 14:33:14, EDIT BY KIRSCHEN
;MAKE GTSTOF, FRJSSO TURN -1 INTO UNIQUE CODE FOR CONNECTED STR
;<2-MONITOR>FUTILI.MAC.77, 21-Oct-76 12:20:45, Edit by MCLEAN
;TCO 1612 FIX ERROR RETURN FOR CNVSTD
;<2-MONITOR>FUTILI.MAC.76, 11-Oct-76 09:09:00, EDIT BY HURLEY
;<2-MONITOR>FUTILI.MAC.75,  5-Oct-76 17:07:42, EDIT BY HALL
;ADDITION TO PREVIOUS EDIT
;<2-MONITOR>FUTILI.MAC.74,  4-Oct-76 16:48:49, EDIT BY HALL
;ADDED CKJBNO AND CKJBLI TO VERIFY A JOB NUMBER
;<2-MONITOR>FUTILI.MAC.73,  1-Oct-76 16:39:52, EDIT BY HURLEY
;ADD CNVSTU ROUTINE TO CONVERT A USER NAME STRING TO USER NUMBER
;<2-MONITOR>FUTILI.MAC.72, 30-Sep-76 15:33:09, EDIT BY HALL
;FIXED BUG IN GTSTOF (RELGRP WAS CLOBBERING T2)
;<2-MONITOR>FUTILI.MAC.71, 30-Sep-76 12:59:40, EDIT BY HALL
;MADE GTSTOF ZERO JSSDM WHEN CREATING A NEW SLOT
;<2-MONITOR>FUTILI.MAC.70, 30-Sep-76 12:53:59, EDIT BY HALL
;FIXED FNDSTO 
;<2-MONITOR>FUTILI.MAC.69, 29-Sep-76 17:16:34, EDIT BY HALL
;MADE GTSTOF RELEASE GROUP SPACE IF NECESSARY; MADE FNDSTO LOOK FOR
; JSSDM; ADDED FRJSSO ENTRY POINT TO FRJSST
;<2-MONITOR>FUTILI.MAC.68, 28-Sep-76 17:05:17, EDIT BY HALL
;FIXED BUG IN FNDSTO
;<2-MONITOR>FUTILI.MAC.67, 28-Sep-76 14:47:59, EDIT BY HALL
;CHANGED GTSTOF, FNDSTO, AND FNDSTM TO TAKE UNIQUE CODE.  DELETED
;GTCSNO AND GTOJNO
;<2-MONITOR>FUTILI.MAC.66, 27-Sep-76 18:08:53, EDIT BY HALL
;MADE GTSTOF CALL FNDSTO; ADDED FRJSST; FIXED ERROR HANDLING IN CNVSTD
;<2-MONITOR>FUTILI.MAC.65, 23-Sep-76 16:02:08, Edit by HESS
;CHANGE STR # TO UNIQUE CODE FOR STDEV/DEVST
;<2-MONITOR>FUTILI.MAC.64, 23-Sep-76 15:33:01, EDIT BY KIRSCHEN
;ADD ROUTINES TO FIND STRUCTURE BLOCK IN JSB AND FAIL IF NOT THERE
;<2-MONITOR>FUTILI.MAC.63, 20-Sep-76 10:36:36, EDIT BY HALL
;ADDED COMMENTS TO EXPLAIN REQUIREMENTS FOR STRUCTURE CONVERSION ROUTINES
;<2-MONITOR>FUTILI.MAC.62, 31-Aug-76 17:11:58, EDIT BY HALL
;MADE CPYUSR, CPYFU0, ETC. USE STKVAR'S 
;<2-MONITOR>FUTILI.MAC.61, 27-Aug-76 16:02:58, EDIT BY HALL
;FIX TO CPYUSR EDIT
;<2-MONITOR>FUTILI.MAC.60, 27-Aug-76 16:00:59, EDIT BY HALL
;ADJUST PREVIOUS EDIT TO BACK UP THE BYTE POINTER BY ONE CHARACTER
;<2-MONITOR>FUTILI.MAC.59, 26-Aug-76 15:15:53, EDIT BY HALL
;MADE CPYUSR, CPYFUS, ETC. RETURN USER'S UPDATED BYTE POINTER IN AC 3
;<2-MONITOR>FUTILI.MAC.58, 25-Aug-76 12:32:08, EDIT BY OSMAN
;<2-MONITOR>FUTILI.MAC.57, 25-Aug-76 11:29:13, EDIT BY HALL
;MADE STRCNV ACCEPT -1 AND CONVERT IT TO THE USER'S CONNECTED STRUCTURE
;<2-MONITOR>FUTILI.MAC.56, 23-Aug-76 09:08:02, EDIT BY KIRSCHEN
;FIX CPYUSR BUG - ADJUST CHAR COUNT BASED ON LENGTH OF BLOCK USED
;<2-MONITOR>FUTILI.MAC.55, 12-Aug-76 18:08:58, EDIT BY HALL
;ADDED CNVSTD ROUTINE - CONVERTS STR:<DIR> TO STRUCTURE UNIQUE CODE,,
;DIRECTORY NUMBER
;<2-MONITOR>FUTILI.MAC.54, 11-Aug-76 12:06:12, EDIT BY HURLEY
;ADD CNVDIR ROUTINE AND DISALLOW USER NUMBERS IN CNVSTR
;<2-MONITOR>FUTILI.MAC.53,  5-Aug-76 15:26:35, EDIT BY KIRSCHEN
;ADD CPYUSR ROUTINE- IT'S CPYFUS WITH DESIRED BLOCK SIZE IN B
;<2-MONITOR>FUTILI.MAC.52,  4-Aug-76 19:27:08, EDIT BY HURLEY
;<2-MONITOR>FUTILI.MAC.51,  4-Aug-76 19:15:59, EDIT BY HURLEY
;<2-MONITOR>FUTILI.MAC.50,  4-Aug-76 14:02:47, EDIT BY HURLEY
;<2-MONITOR>FUTILI.MAC.49,  4-Aug-76 11:44:53, EDIT BY MILLER
;FIX CNVSTR
;<2-MONITOR>FUTILI.MAC.48,  4-Aug-76 10:39:14, EDIT BY KIRSCHEN
;ADD STRCNV ROUTINE
;<2-MONITOR>FUTILI.MAC.47,  3-Aug-76 20:12:40, EDIT BY HURLEY
;<2-MONITOR>FUTILI.MAC.46,  3-Aug-76 19:17:08, EDIT BY HURLEY
;EXPAND DIRECTORY NUMBERS TO 36 BITS
;<2-MONITOR>FUTILI.MAC.45,  2-Aug-76 13:26:23, EDIT BY HALL
;MADE CNVSTR AND GTSTOF RETURN ERROR CODES
;<2-MONITOR>FUTILI.MAC.44,  2-Aug-76 13:00:36, EDIT BY HALL
;CHANGED PREVIOUS EDIT (TYPO)
;<2-MONITOR>FUTILI.MAC.43,  2-Aug-76 12:32:34, EDIT BY HALL
;IN GTSTOF CHANGED TEST FOR FREE SLOT IN JSSTRT
;<2-MONITOR>FUTILI.MAC.42,  1-Aug-76 18:20:45, EDIT BY HALL
;FIXED TYPOS IN GTSTOF AND CNVSTR
;<2-MONITOR>FUTILI.MAC.41,  1-Aug-76 16:00:15, EDIT BY HALL
;FIXED USE OF BAD DEFSTRS
;<2-MONITOR>FUTILI.MAC.40, 29-Jul-76 16:18:37, EDIT BY HALL
;FIXED TYPO IN GTSTOF
;<2-MONITOR>FUTILI.MAC.39, 29-Jul-76 16:10:50, EDIT BY HALL
;ADDED GTSTOF ROUTINE
;<2-MONITOR>FUTILI.MAC.38, 25-Jul-76 13:24:43, EDIT BY HALL
;FURTHER FIXES TO GTOJCD,ETC.
;<2-MONITOR>FUTILI.MAC.37, 25-Jul-76 13:00:30, EDIT BY HALL
;CHANGES TO CNVSTR,GTOJCD,GTOJNO,GTCSCD,GTCSNO
;<2-MONITOR>FUTILI.MAC.36, 24-Jul-76 13:57:21, EDIT BY HALL
;MADE FIX TO PREVIOUS EDIT - MISSING LABEL
;<2-MONITOR>FUTILI.MAC.35, 24-Jul-76 13:35:39, EDIT BY HALL
;ADDED LOCKING OF STRUCTURE TO CNVSTR
;<2-MONITOR>FUTILI.MAC.34, 24-Jul-76 13:28:53, EDIT BY HALL
;ADDED ENTRY POINTS GTOJCD AND GTOJNO FOR GETTING CONNECTED STRUCTURE
;AND DIRECTORY FOR JOB OTHER THAN SELF
;<2-MONITOR>FUTILI.MAC.33, 24-Jul-76 10:38:37, EDIT BY HALL
;ADDED ROUTINES GTCSCD,GTCDNO,CNVSTR
;<2-MONITOR>FUTILI.MAC.2, 10-MAY-76 14:06:53, EDIT BY KIRSCHEN
;USE .DVDSK WHEN FORMING DEVICE DESIGNATOR FOR STRUCTURE IN STRST ROUTINE
;<2-MONITOR>FUTILI.MAC.1, 10-MAY-76 10:18:04, EDIT BY KIRSCHEN
;ADD STRST ROUTINE
;<2MONITOR>FUTILI.MAC.31, 16-JAN-76 17:48:17, EDIT BY MURPHY
;<2MONITOR>FUTILI.MAC.30, 23-DEC-75 12:49:21, EDIT BY LEWINE


;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1976, 1977, 1978 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SEARCH PROLOG
	TTITLE FUTILITY
	SWAPCD

;NO SPECIAL AC DEFINITIONS USED HEREIN

; Save ac's before monitor call

SAVAC::	ADD P,BHC+NSAC-1	; Make room for nsac ac's
	JUMPGE P,MSTKOV
	PUSH P,-<NSAC-1>(P)	; Move return to end
	MOVEM NSAC-1,-1(P)	; Save last ac
	MOVEI NSAC-1,-NSAC(P)	; Make blt pointer
	BLT NSAC-1,-2(P)	; Blt onto stack
	RET

RESAC::	MOVSI NSAC-1,-NSAC(P)	; Blt from stack to 0
	BLT NSAC-1,NSAC-1
	POP P,-NSAC(P)		; Move return to new top
	SUB P,BHC+NSAC-1	; Flush the room on the stack
	RET
;ROUTINE TO ACCEPT YES/NO ANSWER FROM USER.  REQUIRES USER TO
;TYPE Y OR N.  RETURNS "TRUE" ON Y, "FALSE" ON N IN A.

YESNO::	STKVAR <<YESNOL,2>,YESAB,YESAC>
	SE1CAL
	MOVEM B,YESAB		;PRESERVE ALL ACS
	MOVEM C,YESAC
YESN2:	HRROI A,YESNOL		;POINT TO STACK BUFFER
	MOVE B,[RD%BEL+^D10]
	MOVEI C,0		;NO ^R BUFFER
	RDTTY			;READ A LINE
	 JRST YESN1		;SHOULDN'T HAPPEN
	TXNN B,RD%BTM		;LINE TERMINATED WITH BREAK CHAR?
	JRST YESN1		;NO, OBJECT
	MOVE B,YESAB		;RESTORE AC'S
	MOVE C,YESAC
	LDB A,[POINT 7,YESNOL,6] ;GET FIRST CHAR OF LINE
	CAIL A,"A"+40		;LOWER CASE?
	CAILE A,"Z"+40
	SKIPA			;NO
	SUBI A,40		;YES, CONVERT
	CAIN A,"Y"		;GOT A "Y"?
	JRST RTRUE		;YES, RETURN TRUE
	CAIN A,"N"		;GOT A "N"?
	JRST RFALSE		;YES, RETURN FALSE
YESN1:	HRROI A,[ASCIZ / (Y OR N) /]
	PSOUT			;PROMPT USER
	JRST YESN2		;TRY AGAIN
;COPY STRING FROM USER TO JSB.  ASSIGN SPACE AND TRIM BLOCK AFTER COPY.
;ACCEPTS:
;	A/ STRING PTR TO USER'S ADDRESS SPACE
;	CALL CPYFU0
; RETURN +1: NO ROOM
; RETURN +2: SUCCESS, NOINT
;		A/ LOOKUP PTR TO JSB FREE SPACE
;		B/ UPDATED STRING PTR IN JSB FREE SPACE
;		C/ UPDATED STRING POINTER IN USER ADDRESS SPACE

CPYFU0::SETZB D,B		;DO TRMBLK AFTER COPY, USE DEFAULT BLOCK SIZE
	SE1CAL
	JRST CPYUS4

;COPY STRING FROM USER TO JSB.  ASSIGN SPACE BUT DONOT TRIM BLOCK.
; A/ STRING PTR TO USER'S ADDRESS SPACE
; B/ LENGTH OF BLOCK IN WORDS IF CALLING CPYUSR
;	CALL CPYFUS (OR CPYUSR IF SUPPLYING LENGTH)
; RETURN +1: NO ROOM
; RETURN +2: SUCCESS, NOINT
;		A/ LOOKUP PTR TO JSB FREE SPACE
;		B/ UPDATED STRING PTR IN JSB FREE SPACE
;		C/ UPDATED STRING POINTER IN USER SPACE

CPYFUS::SETZM B			;USE DEFAULT BLOCK SIZE
CPYUSR::SETO D,			;SAY NO TRMBLK

	SE1CAL
CPYUS4:	STKVAR<CPYFLG,CPYPTR>
	MOVEM D,CPYFLG		;SAVE FLAG FOR TRIMMING BLOCK
	HLRZ C,A		;GET LH OF BYTE POINTER
	CAIN C,-1		;IS BP -1,,ADDR?
	HRLI A,(<POINT 7,0>)	;YES. GET REASONABLE LH
	XCTBU [	LDB C,A]	;TEST THE BYTE POINTER FOR AN INDIRECT LOOP
	MOVEM A,CPYPTR		;SAVE USER'S STRING POINTER
	SKIPN B			;BLOCK SIZE SUPPLIED ?
	MOVEI B,MAXLW		;NO, USE DEFUALT SIZE
	ADDI B,1		;ALLOW FOR BLOCK HEADER
	NOINT
	CALL ASGJFR		;ASSIGN JSB SPACE. RETURNS ADDRESS OF
				; BLOCK IN AC 1
	 JRST [	MOVE A,CPYPTR	;FAILED. RESTORE USER'S POINTER
		RET]		;TAKE ERROR RETURN
	MOVE B,CPYPTR		;B/POINTER TO USER SPACE
	HRRZ C,A
	HRRZ C,(C)		;GET SIZE OF THIS BLOCK FROM HEADER
	IMULI C,5		;GET # OF CHARACTERS IN BLOCK
	SUBI C,6		;ALLOW FOR NULL; SUBTRACT # OF CHARS IN HEADER
				; 5*(SIZE-1) - 1
	MOVE D,CPYFLG		;RESTORE FLAG FOR TRIMMING BLOCK
	JRST CPYFU6		;GO DO THE COPY
;COPY STRING FROM USER TO SPACE ALREADY ASSIGNED
; A/ LOC OF BLOCK IN JSB FREE SPACE
; B/ STRING PTR IN USER'S ADDRESS SPACE
;	CALL CPYFU1
; RETURN +2: ALWAYS, STRING COPIED AND BLOCK NOT TRIMMED
;		A/ -(NWORDS-1) ,, ORG (LOOKUP POINTER)
;		B/ BYTE POINTER TO END OF STRING (BEFORE NULL)
;		C/ UPDATED STRING POINTER IN USER'S ADDRESS SPACE

;THE BLOCK THAT IS PROVIDED MUST HAVE ROOM FOR MAXLC CHARACTERS PLUS A
;WORD (NORMALLY THE HEADER)

CPYFU1::SETO D,			;SAY NO TRMBLK
	SE1CAL
	MOVEI C,MAXLC		;USE DEFAULT NUMBER OF CHARACTERS
	JRST CPYFU6		;GO DO THE COPY


;COPY STRING FROM USERS TO SPACE ALREADY ASSIGNED.  LIKE CPYFU1 BUT
;THE LENGTH IS PROVIDED BY THE CALLER
; A/ LOC OF BLOCK IN JSB FREE SPACE
; B/ STRING PTR IN USER'S ADDRESS SPACE
; C/ LENGTH OF STRING
;	CALL CPYFU2
; RETURN +2: ALWAYS, STRING COPIED AND BLOCK NOT TRIMMED
;		A/ -(NWORDS-1) ,, ORG (LOOKUP POINTER)
;		B/ BYTE POINTER TO END OF STRING (BEFORE NULL)
;		C/ UPDATED STRING POINTER IN USER'S ADDRESS SPACE

;THE BLOCK THAT IS PROVIDED MUST HAVE ROOM FOR THE CHARACTERS PLUS A
;WORD (NORMALLY THE HEADER)

CPYFU2::SETO D,			;SAY NO TRMBLK
	SE1CAL
	JRST CPYFU6		;GO DO THE COPY
;CPYFU6 - COMMON CODE FOR CPYUSR, CPYFUS, CPYFU1, CPYFU0

;A/LOCATION OF FREE SPACE
;B/USER'S STRING POINTER
;C/NUMBER CHARACTERS THAT FREE SPACE CAN HOLD
;D/0 IF WANT TO TRIM BLOCK AFTER COPY, -1 IF NOT

CPYFU6:	STKVAR<CPYFLG,CPYBLK,CPYUPT,CPYLPT>
	MOVEM D,CPYFLG		;SAVE TRMBLK FLAG
	MOVEM A,CPYBLK		;SAVE LOCATION OF FREE SPACE BLOCK
	EXCH A,B		;A/USER'S STRING POINTER, B/ADDRESS OF JSB FREE SPACE
	HRLI B,(<POINT 7,0,35>)	;POINT TO FIRST WORD AFTER HEADER
	JUMPGE A,CPYUS1		;IF USER SPECIFIED (-1,,ADDRESS)
	CAML A,[777777000000]	; CONVERT IT TO BYTE POINTER FOR ILDB
	HRLI A,(<POINT 7,0>)

CPYUS1:	XCTBU [ILDB D,A]	;GET THE NEXT CHARACTER FROM USER SPACE
	CAIN D,"V"-100		;QUOTE CHARACTER?
	XCTBU [ILDB D,A]	;YES, GET NEXT CHAR
	SOSGE C			;OUT OF SPACE IN JSB BLOCK?
	MOVEI D,0		;YES. OVERWRITE LAST CHARACTER WITH NULL
	JUMPE D,CPYUS2		;FOUND A NULL OR OUT OF SPACE?
	CAIL D,"A"+40		;NO. LOWER CASE?
	CAILE D,"Z"+40
	SKIPA			;NO
	TRZ D,40		;YES, RAISE
	IDPB D,B		;STORE IN FREE SPACE BLOCK
	JRST CPYUS1		;GO GET NEXT CHARACTER

;AT END OF STRING.  APPEND A NULL AND BACKUP THE LOCAL COPY OF THE USER'S BYTE
;POINTER TO POINT TO THE LAST CHARACTER

CPYUS2:	MOVNI C,1		;AMOUNT TO ADJUST BYTE POINTER
	ADJBP C,A		;BACKUP THE USER'S BYTE POINTER TO POINT TO
				; LAST CHARACTER
	MOVEM C,CPYUPT		;SAVE THE ADJUSTED POINTER
	MOVE A,CPYBLK		;RECOVER ORG OF BLOCK
	MOVEM B,CPYLPT		;SAVE END STRING PTR
	IDPB D,B		;APPEND NULL TO STRING
	SKIPE CPYFLG		;WANT TO TRIM BLOCK?
	JRST [	SUBM A,B	;NO. COMPUTE -NWORDS
		HRLI A,1(B)	;MAKE LOOKUP PTR: -(NWORDS-1),,ORG
		JRST CPYUS3]
	CALL TRMBLK		;YES. A/ADDRESS OF BLOCK, B/LAST WORD USED
				;TRIM BLOCK, RETURN EXCESS TO FREE LIST
	HRRZ A,CPYBLK		;RECOVER ORG
	MOVN B,0(A)		;GET NEG LENGTH OF BLOCK
	HRLI A,2(B)		;NWORDS-1 = BLOCKLENGTH-2
CPYUS3:	MOVE C,CPYUPT		;RECOVER USER'S UPDATED BYTE POINTER
	MOVE B,CPYLPT		;RECOVER PTR TO END OF STRING IN JSB
	RETSKP
; Copy string to user
; Call:	A	; User pointer
;	B	; LocatiOn of string block
;	CALL CPYTUS
;	UPDATED POINTER ALWAYS WRITTEN TO USER'S AC2.  USE CPYTU1 FOR
;	WRITING UPDATED POINTER TO SOMEWHERE ELSE

CPYTUS::MOVEI C,2	;RETURN UPDATED POINTER IN USER'S AC2
	CALLRET CPYTU1	;DO THE WORK AND RETURN

; Copy string to user
; Call:	A	; User pointer
;	B	; LocatiOn of string block
;	C	;USER ADDRESS INTO WHICH TO WRITE UPDATED POINTER
;	CALL CPYTU1

CPYTU1::SE1CAL
	ACVAR <W1>		;RESERVE A WORK REGISTER
	JUMPGE A,STDIR0
	CAML A,[777777000000]
	HRLI A,(<POINT 7,0>)
STDIR0:	MOVE W1,[POINT 7,0(B),35] ;GET A BYTE POINTER TO SOURCE
STDIR2:	ILDB D,W1
	JUMPE D,STDIR3
	XCTBU [IDPB D,A]
	JRST STDIR2

STDIR3:	UMOVEM A,@C
	XCTBU [IDPB D,A]
	RET
; ROUTINE TO FORM A FILESPEC OF THE FORM STR:FILE-SPEC
;
; CALL: ACCEPTS IN T1/ DESTINATION POINTER
;		   T2/ STRUCTURE NUMBER
;		   T3/ POINTER TO FILENAME
;		CALL STRST
; RETURNS: +1	 ERROR
;	   +2	SUCCESS

STRST::	SE1CAL
	ASUBR <DSTPNT,STRNM,FPNTR>
	MOVE T1,STRNM		;COPY STRUCTURE #
	CALL STRCNV		;CONVERT TO UNIQUE CODE
	 RET			;ERROR
	MOVE T2,T1		;RETURNS IN T1
	HRLI T2,.DVDES+.DVDSK	;FORM DEVICE DESIGNATOR
	MOVE T1,DSTPNT		;GET POINTER
	DEVST			;TRANSLATE STR NUMBER TO STRING
	 RET			;RETURN, ERROR
	MOVEI T4,":"		;GET DEVICE PUNCTUATION
	IDPB T4,T1		;TERMINATE STRUCTURE NAME
	MOVE T2,FPNTR		;GET POINTER TO FILESPEC
	SETZM T3		;TERMINATE ON NULL
	SOUT			;COPY REMAINDER OF FILENAME
	 ERJMP R		;IF ERROR, JUST RETURN
	RETSKP			;RETURN
;GTCSCD, GTOJCD, - ROUTINES TO GET CONNECTED STRUCTURE AND DIRECTORY

;ACCEPTS: IF CALLING GTCSCD, NONE
;	 IF CALLING GTOJCD,
;		T1/OFFSET TO USE IN ADDRESSING OTHER JOB'S JSB

;RETURNS +1: ALWAYS
;		T1/STRUCTURE UNIQUE CODE,,DIRECTORY NUMBER

;GTCSCD HANDLES THE CASE WHERE THE JOB IS ASKING ABOUT ITSELF.
;IT ASSUMES THE JSB IS MAPPED AT THE USUAL PLACE
;GTOJCD HANDLES THE CASE WHERE THE JOB IS ASKING ABOUT ANOTHER
;JOB.  THE JSB MUST BE MAPPED, AND T1 MUST CONTAIN THE DIFFERENCE BETWEEN
;WHERE THE JSB IS USUALLY MAPPED AND WHERE THE OTHER JOB'S JSB IS MAPPED.
;THIS VALUE IS RETURNED BY SETJSB

GTCSCD::SETZ T1,		;THIS JOB. JSB IS MAPPED IN USUAL PLACE
GTOJCD::LOAD T2,JSUC,(T1) 	;GET UNIQUE CODE FOR CONNECTED STRUCTURE
	LOAD T1,JSDIR,(T1)	;GET CONNECTED DIRECTORY NUMBER
	HRL T1,T2		;GET STRUCTURE CODE
	RET
;CNVSTR - CONVERT STRUCTURE UNIQUE CODE TO STRUCTURE NUMBER (OFFSET
;IN STRTAB)

;ACCEPTS:
;	T1/STRUCTURE UNIQUE CODE IN RH

;RETURNS +1: STRUCTURE DOES NOT EXIST IN SDB
;	 +2: STRUCTURE EXISTS, NOINT
;		T1/STRUCTURE NUMBER

;NOTE: THIS LEAVES THE STRUCTURE LOCKED.  ALWAYS CALL ULKSTR TO UNLOCK IT

CNVSTR::NOSKED
	LDB T2,[POINT STRNS,T1,35] ;GET THE STR NUMBER 
	CAIGE T2,STRN		;IS IT A LEGAL STR NUMBER?
	SKIPN T3,STRTAB(T2)	;GET ADDRESS OF SDB FOR THIS STRUCTURE
	RETBAD (STRX01,<OKSKED>) ;UNKNOWN STRUCTURE UNIQUE CODE
	LOAD T4,STRUC,(T3)	;GET STRUCTURE UNIQUE CODE
	CAME T1,T4		;IS IT THE ONE WE WANT?
	RETBAD (STRX01,<OKSKED>) ;UNKNOWN STRUCTURE UNIQUE CODE
	INCR STRLK,(T3)		;INDICATE STRUCTURE LOCKED
	NOINT
	OKSKED
	HRRZ T1,T2		;RETURN OFFSET IN STRTAB AS STRUCTURE NUMBER
	RETSKP

;ULKSTR - UNDO THE LOCKING DONE BY CNVSTR

;ACCEPTS:
;	T1/STRUCTURE NUMBER (OFFSET IN STRTAB)

;RETURNS +1:ALWAYS	CLOBBERS ONLY AC T1

ULKSTR::
	CALL ULKST1		;UNLOCK IT
	OKINT
	RET

;ROUTINE TO UNLOCK STR WITHOUT DOING AN OKINT

ULKST1::
	MOVE T1,STRTAB(T1)	;ADDRESS OF SDB FOR THIS STRUCTURE
	JE STRLK,(T1),[BUG(CHK,ULKSTZ,<OVERLY DECREMENTED STRUCTURE LOCK>)
		RET]		;DONT DO THE DECREMENT
	DECR STRLK,(T1)		;DECREMENT LOCK COUNT
	RET
;STRCNV - ROUTINE TO CONVERT A STRUCTURE NUMBER TO A UNIQUE CODE
;
; ACCEPTS IN T1/ STRUCTURE NUMBER
;		CALL STRCNV
; RETURNS: +1	 FAILED, ERROR CODE IN T1
;	   +2	SUCCESS,
;		T1/ UNIQUE CODE

;NOTE: INPUT TO THIS ROUTINE IS OFTEN THE RIGHT HALF OF A DEVICE DESIGNATOR.
;SINCE (600000,,-1) IS A LEGAL DESIGNATOR RESULTING FROM A LOOKUP OF THE
;DEVICE 'DSK', THIS ROUTINE CONVERTS IT TO THE USER'S CONNECTED STRUCTURE.

;IMPORTANT! THE STRUCTURE LOCK SHOULD BE LOCKED WHEN THIS ROUTINE IS
;CALLED

STRCNV::CAIE T1,-1		;WAS 'DSK' SPECIFIED?
	JRST STRCN1		;NO. MUST BE A REAL STRUCTURE NUMBER
	CALL GTCSCD		;YES. GET THIS USER'S CONNECTED STRUCTURE,,DIRECTORY
	HLRZS T1		;GET STRUCTURE ONLY
	RETSKP			;RETURN SUCCESSFULLY
STRCN1:	SKIPN T1,STRTAB(T1)	;GET ADDRESS OF STRUCTURE DATA BLOCK
	RETBAD (STRX01)		;RETURN "NO SUCH STRUCTURE"
	LOAD T1,STRUC,(T1)	;GET UNIQUE CODE FOR THIS STRUCTURE
	RETSKP			;RETURN SUCCESS


;CNVDIR -ROUTINE TO CONVERT A USER NUMBER TO ITS LOGGED-IN DIRECTORY NUMBER
;ACCEPTS IN T1/	USER NUMBER
;	CALL CNVDIR
;RETURNS +1:	ALWAYS - DIRECTORY NUMBER IN T1

;IT IS NOT NECESSARY TO HAVE THE STRUCTURE LOCKED WHEN CALLING THIS
;ROUTINE.  HOWEVER, IF THE UNIQUE CODE THAT THIS RETURNS IS TO BE CONVERTED
;TO A STRUCTURE NUMBER, THE LOCK MUST BE LOCKED AT THAT TIME

CNVDIR::HLRZ T2,T1		;GET CODE
	CAIE T2,USRLH		;IS THIS A USER NUMBER?
	RET			;NO, ASSUME IT IS A DIR NUMBER ALREADY
	MOVE T2,STRTAB+PSNUM	;GET POINTER TO SDB
	LOAD T2,STRUC,(T2)	;GET UNIQUE CODE
	HRL T1,T2		;SET UP THE DIRECTORY NUMBER
	RET			;AND RETURN
;GTSTOF - GET STRUCTURE OFFSET IN JSB

;ACCEPTS:
;	T1/STRUCTURE UNIQUE CODE

;	CALL GTSTOF

;RETURNS +1: NO ENTRY FOUND FOR STRUCTURE AND NO SLOT FREE
;	 +2: ENTRY FOUND FOR STRUCTURE OR CREATED
;		T2/ ADDRESS OF WORD 0 IN BLOCK FOR THIS STRUCTURE
;		T1,T3,T4 ARE PRESERVED

;THE JSB CONTAINS 3-WORD GROUPS THAT DESCRIBE A STRUCTURE.  THIS
;ROUTINE FINDS THE GROUP FOR A GIVEN STRUCTURE AND RETURNS THE ADDRESS
;OF THE 0TH WORD. IF THERE IS NO GROUP FOR THE STRUCTURE BUT THERE IS ROOM
;FOR A NEW ENTRY, IT CREATES THE NEW ENTRY, STORING THE STRUCTURE
;UNIQUE CODE AND ZEROING THE REMAINING FIELDS. THE DEFSTRS IN PROLOG
;CONTAIN OFFSETS FROM THIS WORD (0,1,AND 2).  NOTE THAT THIS WORKS
;ONLY FOR THE CALLING JOB.

; NOTE: JSB STRUCTURE INFO LOCK (JSSTLK) MUST BE LOCKED BY CALLER !

GTSTOF::
	STKVAR<<GTSTAC,2>,STRN01,GTSTT2>
	CAIE T1,-1		;UNIQUE CODE FOR DSK: SPECIFIED ?
	JRST GTSTF1		;NO, GO SAVE UNIQUE CODE
	CALL GTCSCD		;YES, GET UNIQUE CODE FOR CONNECTED STR
	HLRZ T1,T1		;KEEP JUST THE UNIQUE CODE
GTSTF1:	MOVEM T1,STRN01		;SAVE STRUCTURE UNIQUE CODE
	DMOVEM T3,GTSTAC	;SAVE AC'S 3 AND 4 TO RETURN
	CALL FNDSTO		;FIND THE SLOT FOR THIS STRUCTURE OR THE
				; FIRST FREE SLOT
	 JRST [	CAIN T1,STRX02	;FAILED. INSUFFICIENT RESOURCES?
		RETBAD		;YES. NO ROOM FOR A NEW ENTRY
		MOVE T1,STRN01	;GET STRUCTURE UNIQUE CODE
		STOR T1,JSSTN,(T2) ;FOUND FREE SLOT. STORE STRUCTURE CODE
		MOVEM T2,GTSTT2	;SAVE OFFSET TO JSB
		OPSTR <SKIPE T1,>,JSGRP,(T2) ;DOES THE SLOT POINT TO GROUPS?
		CALL RELGRP	;YES. RELEASE THE SPACE HOLDING THE GROUPS
		MOVE T2,GTSTT2	;RESTORE OFFSET
		SETZRO <JSMCI,JSSDM,JSGRP,JSADN>,(T2) ;INITIALIZE REMAINING FIELDS
		JRST .+1]
	DMOVE T3,GTSTAC		;RESTORE AC'S 3 AND 4
	RETSKP
;FNDSTO - FIND STRUCTURE OFFSET IN THIS JOB'S JSB
;FNDSTM - FIND STRUCTURE OFFSET IN A JOB'S JSB
;
;ACCEPTS IN T1/	STRUCTURE UNIQUE CODE
;	    T2/ OFFSET TO MAPPED JSB RETURNED BY SETJSB (IF CALLING FNDSTM)
;		CALL FNDSTO/FNDSTM
;RETURNS: +1: FAILED,
;		IF STRUCTURE NOT FOUND BUT THERE IS A FREE SLOT,
;			T1/STRX01
;			T2/LOCATION OF FIRST FREE SLOT
;		IF STRUCTURE NOT FOUND AND THERE IS NO FREE SLOT,
;			T1/STRX02
;	  +2: SUCCESS,
;		T1/UNCHANGED
;		T2/ADDRESS OF FIRST WORD IN BLOCK FOR THIS STRUCTURE

; NOTE: JSB STRUCTURE INFO LOCK (JSSTLK) MUST BE LOCKED BY CALLER !

FNDSTO::MOVEI T2,0		;ASSUME JSB MAPPED IN NORMAL PLACE
FNDSTM::MOVEI T2,JSSTRT(T2)	;POINT TO FIRST BLOCK OF STRUCTURE INFO
	SETOM T4		;INDICATE NO FREE SLOT FOUND YET
	HRLI T2,-STRN		;SET UP AOBJN POINTER TO LOOP THRU STR BLOCKS
FNDST1:	LOAD T3,JSSTN,(T2)	;GET STRUCTURE UNIQUE CODE FOR THIS BLOCK
	CAMN T3,T1		;FOUND DESIRED BLOCK ?
	RETSKP			;YES.  RETURN WITH ADDRESS IN T2
	CAIE T3,JSFRST		;NO. IS THIS SLOT FREE?
	JRST [	JE JSSDM,(T2),FNDST2 ;NO. HAS THE STRUCTURE BEEN DISMOUNTED?
		JRST .+1]	;YES. SLOT IS AVAILABLE
	SKIPGE T4		;HAVE WE FOUND A FREE SLOT BEFORE?
	HRRZM T2,T4		;NO. SAVE LOCATION FOR LATER

FNDST2:	ADDI T2,JSSTMX-1	;SET UP TO LOOK AT NEXT BLOCK
	AOBJN T2,FNDST1		;LOOP OVER ALL BLOCKS IN THIS JSB

;END OF BLOCKS. IF A FREE SLOT WAS FOUND, RETURN ITS ADDRESS

	SKIPGE T4		;DID WE FIND A FREE SLOT?
	RETBAD (STRX02)		;NO. RETURN 'INSUFFICIENT RESOURCES'
	MOVE T2,T4		;YES. RETURN ITS ADDRESS
	RETBAD (STRX01)		;RETURN 'NO SUCH STRUCTURE'
;FRJSST AND FRJSSO - FREE JSB STRUCTURE INFORMATION

;ACCEPTS: IF CALLING FRJSST,
;		T1/ STRUCTURE UNIQUE CODE
;	  IF CALLING FRJSSO,
;		T1/STRUCTURE UNIQUE CODE
;		T2/OFFSET TO MAPPED JSB AS RETURNED BY SETJSB

;RETURNS +1: ALWAYS

;THIS ROUTINE CHECKS TO SEE IF THE SLOT IN THE JSB FOR THE GIVEN
;STRUCTURE IS NEEDED.  IF NOT, IT SETS THE STRUCTURE NUMBER TO -1
;THUS MAKING THE SLOT AVAILABLE

FRJSST::SETZ T2,		;FOR THIS JOB, OFFSET IS ZERO
FRJSSO::CAIE T1,-1		;WAS UNIQUE CODE FOR DSK: ?
	JRST FRJS10		;NO, USE UNIQUE CODE SUPPLIED
	LOAD T1,JSUC,(T2)	;YES, GET UNIQUE CODE FOR CONNECTED STR
FRJS10:	CALL FNDSTO		;GET ADDRESS OF STRUCTURE DATA IN JSB
	 RET			;NO SLOT FOR THIS STRUCTURE
	OPSTR <SKIPE>,JSMCI,(T2) ;IS THE MOUNT COUNT INCREMENTED
	 RET			;YES. CAN'T CLEAR IT THEN
	OPSTR <SKIPE>,JSADN,(T2) ;IS A DIRECTORY ACCESSED?
	 RET			;YES. CAN'T CLEAR IT THEN
	OPSTR <SKIPE>,JSGRP,(T2) ;ARE THERE ANY GROUPS?
	 RET			;YES. CAN'T CLEAR IT THEN

;USER HAS NEITHER ACCESSED STRUCTURE NOR INCREMENTED ITS COUNT.
;FREE THE SLOT

	MOVX T3,JSFRST		;SET UP TO INDICATE FREE
	STOR T3,JSSTN,(T2)	;RESET STRUCTURE UNIQUE CODE TO -1
	RET
;CNVSTD - CONVERT STRUCTURE DESIGNATOR TO STRUCTURE UNIQUE CODE,,DIRECTORY

;ACCEPTS:
;	T1/(STRUCTURE UNIQUE CODE,,DIRECTORY)
;		OR
;	   POINTER TO STRING IN USER'S SPACE

;	CALL CNVSTD (OR CNVSTU IF USER STRING IS SUPPLIED)

;RETURNS +1: NO SPACE IN JSB OR RCDIR FAILURE
;	 +2: SUCCESS,
;		T1/(STRUCTURE UNIQUE CODE,,DIRECTORY)

;THIS ROUTINE IS CALED WHEN A JSYS CALL MAY HAVE EITHER A 
;(STRUCTURE UNIQUE CODE,,DIRECTORY NUMBER) OR A POINTER TO A STRING OF THE
;FORM STR:<DIR>.  IT RETURNS (STRUCTURE UNIQUE CODE,,DIRECTORY NUMBER)

CNVSTU::SKIPA T2,[RCUSR]	;GET USER NUMBER
CNVSTD::MOVE T2,[RCDIR]		;GET DIRECTORY NUMBER
	STKVAR <CNDESG,CNDFR1,CNDINS>
	MOVEM T2,CNDINS		;STORE THE JSYS TO BE EXECUTED
	LOAD T3,NMFLG,T1	;GET BITS 0-2
	CAIN T3,NUMVAL		;IS IT A NUMBER?
	JRST CNVSD1		;YES. NO CONVERSION NEEDED
	MOVEI T2,MAXLW+1+^D9	;T2/MAXIMUM LENGTH OF STR:<DIR>
	CALL CPYUSR		;COPY THE STRING INTO THE JSB AND GO NOINT
	 RETBAD(STRX02,<OKINT>) ;INSUFFICIENT JSB SPACE
	MOVEM T1,CNDFR1		;SAVE LOCATION IN JSB OF BLOCK
	HRROI T2,1(T1)		;T2/POINTER TO THE STRING (AFTER HEADER IN JSB)
	MOVX T1,RC%EMO		;T1/EXACT MATCH ONLY (NO RECOGNITION)
	XCT CNDINS		;CONVERT STRING TO STRUCTURE,,DIRECTORY
	 ERJMP CNVSD2		;FAILED
	TXNE T1,RC%NOM		;DID WE GET A MATCH?
	JRST [	MOVEI T1,STRX03	;NO. REPORT ERROR
		JRST CNVSD3]
	TXNE T1,RC%AMB		;DID WE GET A UNIQUE MATCH?
	JRST [	MOVEI T1,STRX04	;NO. REPORT ERROR
		JRST CNVSD3]
	MOVEM T3,CNDESG		;SAVE (UNIQUE CODE,,DIRECTORY)
	MOVEI T1,JSBFRE		;T1/SPACE IS IN JSB
	MOVE T2,CNDFR1		;T2/POINTER TO SPACE IN JSB
	CALL RELFRE		;RETURN SPACE GOTTEN BY CPYUSR
	OKINT			;CPYUSR WENT NOINT
	MOVE T1,CNDESG		;RESTORE (STRUCTURE UNIQUE CODE,,DIR)
CNVSD1:	RETSKP			;SUCCESS

;ERROR. RETURN SPACE IN JSB THAT CPYUSR GOT

CNVSD3:	MOVEM T1,LSTERR		;SAVE ERROR CODE
CNVSD2:	MOVEI T1,JSBFRE		;T2/SPACE IS IN JSB
	MOVE T2,CNDFR1		;T2/POINTER TO SPACE IN JSB
	CALL RELFRE		;RETURN SPACE GOTTEN BY CPYUSR
	OKINT			;CPYUSR WENT NOINT
	MOVE T1,LSTERR		;RESTORE ERROR CODE
	RETBAD			;ERROR RETURN
;CKJBNO AND CKJBLI - CHECK A JOB NUMBER FOR VALIDITY

;ACCEPTS:
;	T1/JOB NUMBER

;	CALL CKJBNO
;	   OR
;	CALL CKJBLI

;RETURNS +1: JOB NUMBER IS INVALID OR NOT LOGGED IN
;		T1/ERROR CODE
;	 +2: JOB NUMBER IS OK (SEE BELOW)
;		T1/ CONTENTS OF JOBDIR FOR THIS JOB

;CKJBNO SUCCEEDS IF THE JOB NUMBER IS VALID (< NJOBS) AND EXISTS
;	(JOBRT IS NOT NEGATIVE)
;CKJBLI SUCCEEDS IF THE ABOVE IS TRUE AND THE JOB IS LOGGED IN

CKJBNO::SETOM T2		;INDICATE DOESN'T HAVE TO BE LOGGED IN
	SKIPA
CKJBLI::SETZM T2		;INDICATE HAS TO BE LOGGED IN
	CAIL 1,0		;IS THE NUMBER POSITIVE?
	CAIL 1,NJOBS		;YES. IS IT LEGAL?
	RETBAD (ARGX07)		;NO. RETURN 'INVALID JOB NUMBER'
	SKIPGE JOBRT(T1)	;YES. DOES THE JOB EXIST?
	RETBAD (ARGX08)		;NO. RETURN 'NO SUCH JOB'
	SKIPE T2		;DO WE WANT IT TO BE LOGGED IN?
	RETSKP			;NO. JOB NUMBER IS OK, THEN
	HRRZ T1,JOBDIR(T1)	;GET LOGGED IN DIRECTORY
	SKIPN T1		;IS IT LOGGED IN?
	RETBAD (ARGX15)		;NO. RETURN 'JOB IS NOT LOGGED IN'
	RETSKP			;YES. SUCCESS
	TNXEND
	END