.;
.;----------------------------------------------------------------------------
.;
.;	CMD-PROGRAM:	COPY
.;
.;	PURPOSE:	Selective copy of files.
.;			Demonstration command file for undocumented 
.;			RSX11M V3.2 INDirect command processor.
.;
.;	AUTHOR:		? Received from Han Lasance 2 years ago.
.;
.;	DATE:		?
.;
.;	MODIFIED BY:	Jan H. Belgraver	11-JUN-82	JB01	V1.1
.;			Printing of files copied in GO-mode.
.;
.;			Jan H. Belgraver	31-JAN-83	JB02	V1.2
.;			For compatibility with DCL.
.;
.;			Jan H. Belgraver	14-DEC-84	JB03	1.3
.;			1. Sort directory before making listing.
.;			2. Use SRD for listing
.;
.;			Jan H. Belgraver	18-DEC-84	JB04	1.4
.;			If priviledged user and on same device, a 
.;			rename instead of copy is also possible.
.;
.;----------------------------------------------------------------------------
.;
.enable substitution
.enable	quiet								! JB02
	.SETF	DCL							! JB02
	.IF	<CLI> EQ "DCL"	.SETT	DCL				! JB02
.;	If current CLI is DCL reset to MCR				! JB02
	.IFT	DCL	SET TERMINAL/MCR
.disable	quiet							! JB02
.;
.SETF	FLAG
.SETS	STRING ""
.SETF	GO
.SETF	PRINT								! JB01
.SETF	RENAME								! JB03
.;
.;	ASK FOR COMMAND PARAMETERS IF NOT PRESENT
.;
.IF	P2 EQ ""	.ASKS P1 FROM	
.IF	P2 EQ ""	.ASKS P2 TO	
.PARSE	P1	":"	DEVIN	DUMMY					! JB03
.PARSE	P2	":"	DEVOUT	DUMMY					! JB03
.IF	DEVIN EQ DEVOUT .SETT	DEVEQL					! JB03
.IFF	<PRIVIL>	.GOTO	DIRLST					! JB04
.ASK	MODE Rename
.IFT	MODE	.IFT	DEVEQL	.SETT	RENAME				! JB04
.DIRLST:
.;
.;	FIND OUT WHAT TO COPY
.;
.enable	quiet								! JB03
SRD	'P1'DIRECTORY.TMP;1234='P1'/NA					! JB03
.OPENR	'P1'DIRECTORY.TMP;1234
.LOOP:
	.SETS	PREVIO	STRING
	.READ	RECORD
	.IFT	<EOF>	.GOTO	EXIT
	.IF	<FILERR> NE 1	.GOTO	ERROR
	.TEST	RECORD
	.IF	<STRLEN> LE 2	.GOTO	LOOP
.;
	.SETS	STRING	RECORD
	.PARSE	STRING	".;"	NAME TYPE VERS
	.IF	TYPE EQ ""	.GOTO	LOOP
.;
.;	WATCH OUT FOR THE FILE ITSELF
.;
	.IF	NAME NE "DIRECTORY"	.GOTO	MORE
	.IF	TYPE NE "TMP"	.GOTO	MORE
	.IF	VERS NE "1234"	.GOTO	MORE
	.GOTO	LOOP
.MORE:
	.disable quiet
	.IFT	GO	.GOTO	COPY
	.ASKS	ANSWER	Copy 'STRING' [Y,N,Q,G,^] ?
	.IF	ANSWER EQ ""	.GOTO LOOP
	.SETS	FIRST	ANSWER [1:1]
	.IF	FIRST EQ "N"	.GOTO LOOP
	.IF	FIRST EQ "Y"	.GOTO COPY
	.IF	FIRST EQ "Q"	.GOTO EXIT
	.IF	FIRST EQ "G"	.SETT GO
	.IF	FIRST EQ "^"	.SETT FLAG
	.IFT	GO	.ASK	PRINT	Printing filenames
	.IFT	GO	.GOTO	COPY
	.IFF	FLAG	.GOTO	MORE
	.SETS	CURREN	STRING
	.SETS	STRING	PREVIO
.COPY:
	.IFT	PRINT	;	'STRING'
	.enable	quiet
	.IFF	RENAME	PIP	'P2'/CD/FO='P1''STRING'			! JB04
	.IFT	RENAME	PIP	'P2'/RE='P1''STRING'			! JB03
	.IF	<EXSTAT> GT 1	.SETF	RENAME				! JB03
	.IF	<EXSTAT> GT 1	.SETT	FLAG				! JB03
	.IFT	RENAME	PIP	'P2''STRING'/PR/FO	! Set to correct! JB03
.;							! file ownership.
	.IFF	FLAG	.GOTO	LOOP
	.SETF	FLAG
	.SETS	STRING	CURREN
	.GOTO	MORE
.ERROR:
	.disable	quiet
	;..... ERROR '<FILERR>' IN '<FILSPC>'
.EXIT:
	.enable	quiet							! JB03
	PIP	'P1'DIRECTORY.TMP;1234/DE				! JB03
.FINISH:
	.enable	quiet							! JB02
	.;	If user CLI was DCL reset terminal.			! JB02
	.IFT	DCL	SET /DCL=TI:
.disable display
.EXIT
