	.TITLE *** TDV FUNCTION "RENAME"
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/
/	EDIT #15	30 NOV 71	C. PROTEAU
/
/ COPYRIGHT 1971, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ TDV (TASK DEVELOPMENT) TASK, NAMED "REN...", FOR RENAMING FILES ON
/ THE DISK VIA "LUN".
/
/////////////////////////////////////////////////////////
/							/
/ COMMAND STRING EXAMPLE:				/
/							/
/	TDV>REN OLDFIL,NEWFIL				/
/							/
/	TDV>REN OLDFIL SRC,NEWFIL 003			/
/							/
/	TDV>REN OLDFIL 002, 003				/
/							/
/	TDV>REN OLDFIL BIN,NEWFIL			/
/							/
/////////////////////////////////////////////////////////
/
/ THE OLD FILE NAME EXTENSION IS OPTIONAL -- "SRC" IS THE DEFAULT ASSUMPTION.
/
/ THE NEW FILE NAME AND/OR EXTENSION IS OPTIONAL -- THE OLD FILE NAME
/ AND/OR EXTENSION IS USED IN DEFAULT.
/
	.EJECT
/ THE COMMAND INPUT LINE IS READ BY THE RESIDENT TDV TASK ("TDV...") AND
/ IS TRANSFERRED TO THIS TASK BY MEANS OF THE XFRCMD DIRECTIVE.
/
/	COMMAND SYNTAX = 'REN'$<NSP><SP><FILE NAME>((<SP><EXT>)/)
/			 <COM>(<FILE NAME>/<FILE NAME><SP><EXT>/
/			 <SP><EXT>)(<CR>/<AM>)
/
/	<NSP> = NON-SPACE CHARACTER
/	<SP>  = A SPACE CHARACTER
/	<FILE NAME> = 1 TO 6 ALPHANUMERIC CHARACTERS
/	<EXT> = 1 TO 3 ALPHANUMERIC CHARACTERS
/	<COM> = A COMMA
/	<CR>  = A CARRIAGE RETURN
/	<AM>  = AN ALTMODE
/	$<..> OR $(..) = ANY NUMBER, INCLUDING NONE, OF THE ITEM <..> OR (..).
/
/ AT COMPLETION OF THE RENAME FUNCTION, THE TERMINATING CHARACTER OF THE
/ COMMAND LINE IS EXAMINED. IF IT IS A CARRIAGE RETURN, THE RESIDENT TDV
/ TASK IS "REQUESTED" AND "RENAME" EXITS. IF THE LINE IS TERMINATED BY AN
/ ALTMODE, "RENAME" EXITS WITHOUT "REQUESTING" "TDV...". A CTRL T TYPEIN
/ IS THEN NECESSARY TO RE-ESTABLISH TDV DIALOGUE.
/
	.DEC
LUN=17				/LUN NORMALLY ASSIGNED TO DISK.
TDVTTY=13			/TDV TTY ERROR LUN.
	.OCT
X10=10				/AUTOINCREMENT REGISTER 10.
IDX=ISZ				/USED WHEN THE SKIP IS NOT INTENDED.
CBFSIZ=40			/SIZE OF THE COMMAND LINE BUFFER FOR UP
				/TO 80 CHARACTERS.
/
	.EJECT
REN	CAL	XFER		/TRANSFER THE COMMAND LINE READ BY "TDV...".
	CAL	WAITFR
	LAW	-16		/IS THE BUFFER TOO SMALL, I.E., IS THE
	SAD	EV		/COMMAND LINE TOO LONG?
	JMP	ERR1		/YES.
/
/ INITIALIZE THE FETCH-A-CHARACTER SUBROUTINE. THIS MUST BE DONE HERE,
/ RATHER THAN BEING ASSEMBLED IN, IN CASE THE TASK IS FIXED IN CORE AND
/ IS THUS NOT REINITIALIZED.
/
	LAC	(FACLB+2)
	DAC	FACLBX
	LAC	(FACCB+5)
	DAC	FACCBX
/
/ FLUSH COMMAND INPUT THROUGH THE FIRST BREAK CHARACTER.
/
FLUSH	JMS	FAC		/FETCH A CHARACTER FROM COMMAND LINE.
	SAD	(40)		/SPACE?
	JMP	FILE1
	SAD	(15)		/CARRIAGE RETURN?
	SKP
	SAD	(175)		/ALTMODE?
	JMP	ERR2		/SYNTAX ERROR.
	JMP	FLUSH
/
/ UNPACK THE FIRST FILE NAME.
/
FILE1	LAC	(BUF-1)		/INITIALIZE THE NAME BUFFER.
	DAC*	(X10)
	LAW	-7		/UNPACK FILE NAME (UP TO 6 CHARACTERS).
	JMS	UNPACK		/RETURN IF NO ERROR OCCURRED.
/
/ CONVERT THE FILE NAME TO .SIXBT AND STORE IT IN THE "RENAME" CPB.
/
	.DEC
	LAC	BUF+2
	LRS	6
	LAC	BUF+1
	LRS	6
	LAC	BUF+0
	LLS	12
	SNA
	JMP	ERR2		/SYNTAX ERROR -- NULL FILE NAME.
	DAC	RENAME+3
	LAC	BUF+5
	LRS	6
	LAC	BUF+4
	LRS	6
	LAC	BUF+3
	LLS	12
	DAC	RENAME+4
	.OCT
/
/ THE FILE NAME EXTENSION IS OPTIONAL; THE DEFAULT EXTENSION IS "SRC".
/ VALIDATE THE DELIMITER.
/
	LAC	CHAR
	SAD	(54)		/COMMA?
	JMP	USESRC		/ASSUME DEFAULT "SRC" EXTENSION.
	SAD	(40)		/SPACE?
	SKP
	JMP	ERR2		/NO -- ILLEGAL DELIMITER.
/
/ UNPACK THE FIRST FILE NAME EXTENSION.
/
	LAW	-4		/UNPACK EXTENSION (UP TO 3 CHARACTERS).
	JMS	UNPACK		/RETURN IF NO ERROR OCCURRED.
/
/ CONVERT THE FILE NAME EXTENSION TO .SIXBT AND STORE IT IN THE "RENAME" CPB.
/
	.DEC
	LAC	BUF+8
	LRS	6
	LAC	BUF+7
	LRS	6
	LAC	BUF+6
	LLS	12
	.OCT
	SNA
	JMP	ERR2		/SYNTAX ERROR -- NULL EXTENSION.
	SKP
/
/ USE THE DEFAULT EXTENSION "SRC".
/
USESRC	LAC	(232203)	/.SIXBT "SRC".
	DAC	RENAME+5
/
/ VALIDATE THE DELIMITER.
/
	LAC	CHAR
	SAD	(54)		/COMMA?
	SKP
	JMP	ERR2		/NO -- ILLEGAL DELIMITER.
/
	.EJECT
/ UNPACK THE SECOND FILE NAME.
/
	LAC	(BUF-1)		/INITIALIZE THE NAME BUFFER.
	DAC*	(X10)
	LAW	-7		/UNPACK FILE NAME (UP TO 6 CHARACTERS).
	JMS	UNPACK		/RETURN IF NO ERROR OCCURRED.
/
/ CONVERT THE FILE NAME TO .SIXBT AND STORE IT IN THE "CLOSE" CPB.
/
	.DEC
	LAC	BUF+2
	LRS	6
	LAC	BUF+1
	LRS	6
	LAC	BUF+0
	LLS	12
	DAC	CLOSE+3
	LAC	BUF+5
	LRS	6
	LAC	BUF+4
	LRS	6
	LAC	BUF+3
	LLS	12
	DAC	CLOSE+4
	.OCT
/
/ IF THE SECOND FILE NAME WAS OMITTED IN THE COMMAND STRING, INDICATED BY
/ THE FACT THAT THE FIRST WORD IS 0, USE THE FIRST FILE NAME IN DEFAULT.
/
	LAC	CLOSE+3
	SZA
	JMP	GETEX2
	LAC	RENAME+3
	DAC	CLOSE+3
	LAC	RENAME+4
	DAC	CLOSE+4
/
/ VALIDATE THE DELIMITER.
/
GETEX2	LAC	CHAR
	SAD	(15)		/CARRIAGE RETURN?
	SKP
	SAD	(175)		/ALTMODE?
	JMP	USEEX1		/YES -- USE THE FIRST EXTENSION.
	SAD	(40)		/SPACE?
	SKP
	JMP	ERR2		/NO -- ILLEGAL DELIMITER.
/
	.EJECT
/ UNPACK THE SECOND FILE NAME EXTENSION.
/
	LAW	-4		/UNPACK EXTENSION (UP TO 3 CHARACTERS).
	JMS	UNPACK		/RETURN IF NO ERROR OCCURRED.
/
/ CONVERT THE FILE NAME EXTENSION TO .SIXBT AND STORE IT IN THE "CLOSE" CPB.
/
	.DEC
	LAC	BUF+8
	LRS	6
	LAC	BUF+7
	LRS	6
	LAC	BUF+6
	LLS	12
	.OCT
	SNA
	JMP	ERR2		/SYNTAX ERROR -- NULL EXTENSION.
	SKP
/
/ USE THE FIRST FILE NAME EXTENSION AS THE DEFAULT ASSUMPTION.
/
USEEX1	LAC	RENAME+5
	DAC	CLOSE+5
/
/ VALIDATE THE DELIMITER.
/
	LAC	CHAR
	SAD	(15)		/CARRIAGE RETURN?
	SKP
	SAD	(175)		/ALTMODE?
	SKP
	JMP	ERR2		/NO -- ILLEGAL DELIMITER.
/
	.EJECT
/ RENAME THE FILE.
/
	CAL	RENAME		/OPEN THE FILE FOR RENAMING.
	CAL	WAITFR
	LAC	EV
	SAD	(-13)
	JMP	ERR3		/FILE NOT FOUND.
	SAD	(-6)
	JMP	ERR4		/DEVICE CAN'T RENAME.
	SAD	(-54)
	JMP	ERR5		/FILE STILL OPEN.
	SPA
	JMP	ERR6		/ERROR DURING RENAME.
/
	CAL	CLOSE		/CLOSE AND RENAME THE FILE.
	CAL	WAITFR
	LAC	EV
	SPA
	JMP	ERR6		/ERROR DURING RENAME.
/
/ EXIT.
/
	LAC	CHAR
	SAD	(15)		/CARRIAGE RETURN?
EXIT	CAL	REQTDV		/YES -- REQUEST "TDV...".
	CAL	(10)		/NO -- EXIT WITHOUT WAITING FOR RESULT.
/
/ ERRORS -- PRINT THE ERROR MESSAGE AND THEN REQUEST "TDV..." EVEN IF
/ THE LINE TERMINATOR IS AN ALTMODE.
/
ERR1	LAC	(MES1)		/COMMAND LINE TOO LONG.
	SKP
ERR2	LAC	(MES2)		/SYNTAX ERROR.
	SKP
ERR3	LAC	(MES3)		/FILE NOT FOUND.
	SKP
ERR4	LAC	(MES4)		/DEVICE CAN'T RENAME.
	SKP
ERR5	LAC	(MES5)		/FILE STILL OPEN.
	SKP
ERR6	LAC	(MES6)		/"RENAME" ERROR.
	DAC	TYPE+4
	LAC	EV		/SAVE EV VALUE SO THAT SOMEONE MAY EXAMINE
	DAC	ERRCOD		/IT BY USING THE "OPEN" MCR FUNCTION.
	CAL	TYPE		/TYPE THE MESSAGE.
	CAL	WAITFR
	JMP	EXIT
/
TYPE	2700			/"WRITE" CPB.
	EV
	TDVTTY			/TDV TTY ERROR LUN.
	2			/IOPS ASCII.
	XX			/MESSAGE ADDRESS.
/
	.EJECT
MES1	005002; 0; .ASCII "REN-LINE TOO LONG"<15>
MES2	004002; 0; .ASCII "REN-SYNTAX ERR"<15>
MES3	005002; 0; .ASCII "REN-FILE NOT FOUND"<15>
MES4	005002; 0; .ASCII "REN-CAN'T RENAME"<15>
MES5	005002; 0; .ASCII "REN-FILE STILL OPEN"<15>
MES6	004002; 0; .ASCII "REN-RENAME ERR"<15>
/
	.EJECT
/ SUBROUTINE UNPACK -- UNPACK 7-BIT ASCII CHARACTERS FROM THE COMMAND
/ INPUT LINE AND STORE THEM SEQUENTIALLY IN "BUF" VIA X10 (ALREADY SET UP).
/ THE NEGATIVE COUNT OF (MAXIMUM NUMBER OF CHARACTERS + 1) IS IN THE AC.
/
/ CALLING SEQUENCE:
/
/	-COUNT IN THE AC
/	JMS	UNPACK
/	(RETURN IF NO ERROR OCCURRED)
/
/ ALTERED REGISTERS:
/
/	AC & MQ
/
UNPACK	0
	DAC	CNT		/SAVE COUNT.
LOOP1	JMS	FAC		/FETCH A CHARACTER.
	DAC	CHAR
	SAD	(54)		/COMMA?
	JMP	NOT6BT		/YES -- DELIMITER.
	AAC	-41
	SPA
	JMP	NOT6BT		/NOT .SIXBT. CHAR < 41.
	AAC	-77
	SMA
	JMP	NOT6BT		/NOT .SIXBT. CHAR > 137.
	ISZ	CNT
	SKP
	JMP	ERR2		/TOO MANY CHARACTERS.
	LAC	CHAR		/STORE CHARACTER.
	DAC*	X10
	JMP	LOOP1
/
/ FILL IN THE REMAINDER OF THE NAME WITH ZEROS.
/
	DZM*	X10
NOT6BT	ISZ	CNT
	JMP	.-2
	JMP*	UNPACK
/
	.EJECT
/ SUBROUTINE FAC -- FETCH A CHARACTER FROM THE 5/7 ASCII LINE BUFFER 'FACLB'.
/ THE INDICIES 'FACLBX' AND 'FACCBX' MUST BE SET WHEN A NEW LINE IS READ.
/ CHARACTERS ARE NOT FETCHED BEYOND TERMINAL CHARACTERS.
/
/ CALLING SEQUENCE:
/
/	JMS	FAC
/	(UNCONDITIONAL RETURN WITH CHARACTER IN THE AC)
/
/ ALTERED REGISTERS:
/
/	AC & MQ
/
FAC	0
	LAC*	FACCBX		/FETCH THE NEXT UNPACKED CHARACTER FROM 'FACCB'.
	SMA			/WAS THE CHARACTER BUFFER (FACCB) EMPTY?
	JMP	FAC2		/NO -- TEST FOR A TERMINAL CHARACTER.
	LAC	(FACCB-1)	/YES -- REFILL 'FACCB' FROM THE INPUT LINE.
	DAC	FACCBX
	LAC*	FACLBX		/(FIRST HALF OF WORD PAIR).
	IDX	FACLBX
	LMQ
	CLA!CLL
	JMS	FACUPS		/(FIRST CHARACTER).
	JMS	FACUPS		/(SECOND CHARACTER).
	JMS	FACUPS		/(FIRST 4 BITS OF THIRD CHARACTER).
	LAC*	FACLBX		/(SECOND HALF OF WORD PAIR).
	IDX	FACLBX
	LRS	17		/(LAST 3 BITS OF THIRD CHARACTER).
	XOR*	FACCBX
	DAC*	FACCBX
	CLA
	JMS	FACUPS		/(FOURTH CHARACTER).
	JMS	FACUPS		/(FIFTH CHARACTER).
	LAC	(FACCB)		/RESET THE CHARACTER BUFFER INDEX.
	DAC	FACCBX
	LAC*	FACCBX		/FETCH THE FIRST CHARACTER FROM THE
				/CHARACTER BUFFER.
/
FAC2	SAD	(015)		/IF IT IS A TERMINAL CHARACTER, CARRIAGE
	JMP*	FAC		/RETURN OR ALTMODE, RETURN WITH THE CHARACTER
	SAD	(175)		/IN THE AC BUT DO NOT AUGMENT THE CHARACTER
	JMP*	FAC		/BUFFER INDEX. THUS, REPEATED CALLS TO FAC
				/WILL RETURN THE TERMINAL CHARACTER.
/
	IDX	FACCBX		/IT IS NOT A TERMINAL CHARACTER -- AUGMENT
	JMP*	FAC		/THE CHARACTER BUFFER INDEX AND RETURN WITH
				/THE CHARACTER IN THE AC.
/
	.EJECT
/ SUBROUTINE FACUPS -- UNPACKING SUBROUTINE USED BY 'FAC'.
/
/ CALLING SEQUENCE:
/
/	AC & LINK MUST BE CLEARED.
/	NEXT CHARACTER MUST BE IN
/	THE HIGH-ORDER END OF THE MQ.
/	'FACCBX' MUST  POINT TO THE
/	WORD PRECEDING THE ONE IN
/	WHICH THE CHARACTER IS TO
/	BE STORED.
/	JMS	FACUPS
/	(UNCONDITIONAL RETURN WITH
/	'FACCBX' POINTING TO THE
/	STORED CHARACTER AND WITH
/	THE AC & LINK LEFT CLEARED)
/
/ ALTERED REGISTERS:
/
/	AC & MQ
/
FACUPS	0
	LLS	7		/SHIFT THE CHARACTER INTO THE AC. THE LOW
	IDX	FACCBX		/ORDER BITS OF THE THIRD CHARACTER ARE ZERO
	DAC*	FACCBX		/BECAUSE THE LINK IS ZERO.
	CLA
	JMP*	FACUPS
/
FACLBX	XX			/LINE BUFFER INDEX.
FACCBX	XX			/CHARACTER BUFFER INDEX.
FACCB	.BLOCK	5		/CHARACTER BUFFER (5 IMAGE ALPHA CHARACTERS).
	-1			/END-OF-'FACCB' INDICATOR.
/
	.EJECT
REQTDV	1			/"REQUEST" CPB.
	0			/NO EVENT VARIABLE.
	.SIXBT	"TDV"
	.SIXBT	"..."
	0			/USE THE DEFAULT PRIORITY.
/
RENAME	3700			/"OPEN FOR RENAMING" CPB.
	EV
	LUN
	.SIXBT	"---"		/FILE NAME -- 1ST HALF.
	.SIXBT	"---"		/FILE NAME -- 2ND HALF.
	.SIXBT	"---"		/FILE NAME -- EXTENSION.
/
CLOSE	3400			/"CLOSE AND RENAME" CPB.
	EV
	LUN
	.SIXBT	"---"		/FILE NAME -- 1ST HALF.
	.SIXBT	"---"		/FILE NAME -- 2ND HALF.
	.SIXBT	"---"		/FILE NAME -- EXTENSION.
/
XFER	37			/"TRANSFER TDV COMMAND LINE" CPB.
	EV
	FACLB			/BUFFER ADDRESS.
	CBFSIZ			/BUFFER SIZE.
/
WAITFR	20			/"WAITFOR" CPB.
	EV
/
EV	0			/EVENT VARIABLE.
CNT	0			/COUNTER.
CHAR	0			/INPUT CHARACTER.
ERRCOD	0			/EV VALUE SAVED BEFORE ERROR PRINTOUT IN
				/CASE SOMEONE WANTS TO EXAMINE IT USING
				/THE "OPEN" MCR FUNCTION.
/
	.DEC
BUF	.BLOCK 9		/FILE NAME BUFFER.
	.OCT
/
FACLB	.BLOCK	CBFSIZ		/COMMAND INPUT BUFFER, OR
				/FETCH-A-CHARACTER BUFFER.
	064032			/GUARD WORD -- GUARANTEES FINDING
				/CARRIAGE RETURN AT END OF BUFFER.
/
	.END	REN
