;<134-TENEX>FUTILI.MAC;16    28-APR-75 12:14:42    EDIT BY CLEMENTS
;<134-TENEX>FUTILI.MAC;15    28-APR-75 11:32:49    EDIT BY CLEMENTS
;<134-TENEX>FUTILI.MAC;14    24-APR-75 14:15:15    EDIT BY CLEMENTS
;<133-TENEX>FUTILI.MAC;13     8-DEC-74 12:10:50    EDIT BY CLEMENTS
; ADDED CPYFU2 ENTRY POINT FOR LONGER STRING LENGTH
;<TENEX-132>FUTILI.MAC;12     9-NOV-73 20:02:51	EDIT BY CLEMENTS

	SEARCH	STENEX,PROLOG
	TITLE	FUTILITY
	SUBTTL	R.S.TOMLINSON 8 JUN 72

; Pointers to things in fdb

	USE	RESPC

PFILPC::POINT 18,FDBBYV(A),35	; Pointer to size in pages of file
PFILBS::POINT 6,FDBBYV(A),11	; Pointer to last byte size
PFILVC::POINT 6,FDBBYV(A),5	; Pointer to version retention count
PBYTPO::POINT 6,FILBYT(JFN),5	; Points to "p" of file byte pointer
PBYTSZ::POINT 6,FILBYT(JFN),11	; Points to "s" of file byte pointer

	USE	SWAPPC

EXTERN	SKPRET,MAXLC,MAXLW,ASGJFR,BHC,MSTKOV

; Save ac's before monitor call

	USE	SWAPPC

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
	POPJ P,

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
	POPJ P,

; Copy string from user to a free area in the jsb
; Call:	A	; String pointer
;	PUSHJ P,CPYFUS
; Return
;	+1	; No room
;	+2	; Ok
;	A	; Lookup pointer

CPYFUS::PUSH P,A		; SAVE "FROM" ADDRESS
	MOVEI B,MAXLW+1		; NEED THIS MANY WORDS OF FREE STORAGE
	NOINT
	PUSHJ P,ASGJFR
	JRST [	POP P,A
		POPJ P,]	;COULDN'T GET IT
	POP P,B			; FROM ADDRESS -- TO IS IN A
CPYFU1::MOVEI C,MAXLC		; Enter here when storage isnt needed
CPYFU2::PUSH P,A		; ENTER HERE FOR DIFFERENT LENGTH
	EXCH A,B
	HRLI B,(<POINT 7,0,35>)	; TO BYTES -- AFTER HDR WORD IN B
	JUMPGE A,CPYUS1		; STRING POINTER FOR "FROM" BYTES
	CAML A,[777777000000]
	HRLI A,(<POINT 7,0>)
CPYUS1:	XCTBU [ILDB D,A]
	SOSG C
	MOVEI D,0		; After maxlc chars, force null
	JUMPE D,CPYUS2
	CAIL D,140		; LOWER CASE?
	TRZ D,40		; YES, RAISE
	IDPB D,B
	JRST CPYUS1

CPYUS2:	MOVE A,(P)		; STORAGE BLK HEADER (DATA-1)
	MOVEM B,(P)		; AND UPDATED STRING POINTER
	IDPB D,B
	HRL B,A			; Location OF WORD WITH TERM NULL to lh of a
	SUB A,B			; Compute number of full words
	HRRI B,1(A)
	MOVS A,B		; Is now a lookup pointer
	POP P,B
	JRST SKPRET

; Copy string to user
; Call:	A	; User pointer
;	B	; Locatin of string block
;	PUSHJ P,CPYTUS

CPYTUS::JUMPGE A,STDIR0
	CAML A,[777777000000]
	HRLI A,(<POINT 7,0>)
STDIR0:	HRLI B,(<POINT 7,0,35>)
STDIR2:	ILDB C,B
	JUMPE C,STDIR3
	XCTBU [IDPB C,A]
	JRST STDIR2

STDIR3:	UMOVEM A,2
	XCTBU [IDPB C,A]
	POPJ P,

END
