Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-06 - 43,50441/rev.mac
There are 15 other files named rev.mac in the archive. Click here to see a list.
	TITLE	REV	REVIEWS FILES!
	SUBTTL	DAVID ROLFE     CALTECH     AUGUST, 1976
	TWOSEG
	IFNDEF FTCIT,<FTCIT==0	;SET TO ENCODE CIT FEATURES>

;ONLY ONE OF THE FOLLOWING .TEXT LINES MAY BE USED
;THIS PUTS SOME CODE IN THE LOW SEG, MAKING REV 2+4P
;	.TEXT\SCNNER,WILDER,LIB/SEGMENT:LOW/SEARCH\
;THIS PUT ALL CODE IN THE HIGH SEG, MAKING REV 2+5P, BIGGER BUT ALL SHARABLE
	.TEXT\SCNNER,WILDER,LIB/SEARCH\

VREV==2
VEDIT==4
VMINOR==0
VWHO==5

	LOC	<.JBVER==137>
	BYTE (3)VWHO(9)VREV(6)VMINOR(18)VEDIT

COMMENT	^

REV IS DESIGNED TO BE A GENERALLY USEFUL FILE MANIPULATOR.
FOR DETAILS OF THE USE OF REV, SEE THE FILE REV.HLP.

THERE ARE TWO MAIN REASONS FOR THE EXISTENCE OF REV:
	1.)  THE FLEXIBLE "REV MODE", WHERE FILES ARE INDIVIDUALLY
	     DISPLAYED AND REVIEWED, IS NOT AVAILABLE ELSEWHERE.
	     (THIS IS SOMEWHAT SIMILAR TO K/I, BUT THAT IS NOT AS
	     POWERFUL.)
	2.)  WHILE REV MAKES AVAILABLE THE MOST USEFUL FEATURES OF
	     PIP, DIRECT, KJOB, AND SETSRC, REV WILL RUN IN A MINIMUM
	     OF 1K+2K IN CORE.  WITHOUT THE CUMBERSOME SCAN AND WILD
	     AND HIGH OVERHEAD AND SPECIAL CASE CODE THAT IS NEVER USED
	     IN MOST SYSTEM PROGRAMS, REV CAN BE SMALLER AND FASTER
	     THAN ITS COMPETITION.  HOPEFULLY REV WILL HAVE MOST OF
	     THE ADVANTAGES AND NONE OF THE DISADVANTAGES OF A
	     REAL SCAN-AND-WILD PROGRAM.  THUS REV PROBABLY HAS THE
	     GREATEST VALUE ON HEAVILY USED OR HEAVILY SWAPPED SYSTEMS.


REV IS A MULTIPLE MODULE PROGRAM.  THE MODULES ARE:

	REV -- THE MAIN ROUTINES
	SCNNER -- THE COMMAND SCANNER
	WILDER -- THE WILD CARD HANDLER
	LIB -- MINOR SUBROUTINES

ALL FOUR OF THE MODULES SHOULD BE AVAILABLE WHEN LOADING.
TO LOAD THE PROGRAM, IT IS ONLY NECESSARY TO GIVE THE COMMAND
.LOAD REV
AND REV WILL TELL LINK TO LOAD THE OTHER THREE MODULES.
PLEASE REPORT ANY BUGS TO:

	DAVID ROLFE
	135 S. ROOSEVELT AVE.
	PASADENA, CALIFORNIA  91107




	EDIT HISTORY

01	FIRST RELEASE

02	ADD THE /CONFIRM SWITCH TO GET CONFIRMATION BEFORE CHANGES
	ARE MADE

03	ADD /PASSWO AND /CODE SWITCHES TO ENCRYPT FILES.  /PASSWO
	WILL ALWAYS GET A NEW PASSWORD, /CODE WILL USE THE LAST
	PASSWORD IF THERE WAS ONE.

04	FIX SWITCHES TO USE THE NEW UNIQUE-MATCH-UNECESSARY FEATURE
	OF SCNNER.  THIS IS DONE BY PLACING A "*" BEFORE THE SWITCHES
	WE WISH TO ACCEPT WITH A NON-UNIQUE MATCH.  THIS IS SIMILAR
	TO A SCAN FEATURE

***** BEGIN VERSION 2 *****

^	;END OF COMMENT
	SUBTTL	DEFINITIONS

	OPDEF	PJRST	[JRST]
	OPDEF	PJSP	[JSP]
	OPDEF	PJUMPG	[JUMPG]

;ASSEMBLY CONSTANTS

	PDLSIZ==50	;DEPTH OF PDL
	RDLSIZ==^D100	;FOR LOOK BACK FACILITY OF REV
	HLPDEV=='HLP   '
	HLPPPN==2,,5
	HLPNAM=='REV   '
	HLPEXT=='HLP   '


;DATA CHANNELS

	WLD==0		;OPEN TO GOOD DEV BY WILDER, MAY BE USED
	TTY==1		;TTY CHANNEL
	ICHN==2		;CHANNEL FOR INPUT
	OCHN==3		;CHANNEL FOR OUTPUT


;AC'S
	T1=1		;TEMP
	T2=2		; ..
	T3=3		; ..
	T4=4		; ..
	P1=5		;PRESERVED
	P2=6
	F=15		;FLAGS, NOT USED BY SCNNER OR WILDER
	RP=16		;REV PDL, NOT USED BY SCNNER OR WILDER
	P=17		;PDL


;RIB

	.RBPPN==1	;PPN
	.RBNAM==2	;FILE NAME
	.RBEXT==3	;EXTENSION
	.RBPRV==4	;PRIV BITS
	.RBSIZ==5	;SIZE IN WORDS
	.RBVER==6	;VERSION
	.RBSPL==7	;SPOOLING WORD
	.RBTIM==35	;UNIVERSAL DATE/TIME


;JOBINT DATA

	ER.ICC==1B34	;^C INTERCEPT
;FLAGS USED

	FL.FST==(1B0)	;SIGN BIT -- INDICATES FAST LISTING
	FL.REV==(1B1)	;REV MODE
	FL.ACC==(1B2)	;DOING ACCESS
	FL.BAD==(1B3)	;LOOKUP FAILURE
	FL.NOW==(1B4)	;COMMAND IS PROCESSED WITHOUT WILDER CALL
	FL.SUP==(1B5)	;SUPER COMMAND -- PROTECT FILE LOW IF NEEDED
	FL.EQ==(1B6)	;THERE WAS AN EQUALS SIGN IN THE COMMAND
	FL.AFT==(1B7)	;THIS WAS A /AFTER COMMAND
	FL.MRG==(1B8)	;THERE IS A SINGLE OUTPUT FILE
	FL.UP==(1B9)	;SET IF GOING UP IN REV MODE
	FL.OUT==(1B10)	;OUTPUT DEVICE HAS BEEN SELECTED FOR DIRECTORY LIST
	FL.CLS==(1B11)	;THE OUTPUT CHANNEL REQUIRES CLOSING ON COMMAND COMPLETION
	FL.CTP==(1B12)	;DO NOT RETURN TO MONITOR LEVEL ON ^C'S
	FL.WAT==(1B13)	;WAIT FOR OUTPUT TO FINISH ON COMMAND TERMINATION
	FL.TRL==(1B14)	;DO TRAILING SPACES ON FAST LISTING
	FL.CON==(1B15)	;GET CONFIRMATION BEFORE PROCESSING FILES
	FL.PSW==(1B16)	;CODE TRANSFERRED FILES

	COMFLG==FL.FST!FL.REV!FL.ACC!FL.BAD!FL.NOW!FL.SUP!FL.EQ!FL.AFT!FL.MRG
		FL.OUT!FL.CLS!FL.CTP!FL.WAT!FL.TRL!FL.CON!FL.PSW
			; FLAGS ZEROED ON EVERY NEW COMMAND LINE
;I/O CONSTANTS

	IO.ERR==740000	;MAJOR ERROR BITS
	UU.PHS==1B0	;PHYSICAL ONLY BIT FOR OPEN
	.IOASL==1	;ASCII MODE
	.IOIMG==10	;IMAGE MODE
	.IODMP==17	;DUMP MODE
	IO.SUP==1B28	;DON'T ECHO TTY
	CL.RST==1B30	;BIT ON CLOSE PREVENTS WRITING OF FILE


;CHKACC DEF

	.ACREN==1	;CHECK RENAME PRIV'S


;DEVCHR BITS

	DV.TTA==1B4	;DEVICE IS A CONTROLLING TTY
	DV.AVL==1B12	;DEVICE IS AVAILABLE TO THIS JOB
	DV.TTY==1B14	;DEVICE IS A TTY
	DV.DIR==1B15	;DEVICE HAS A DIRECTORY

;PATH FUNCTIONS

	.PTFRD==-1	;RETURNS DEFAULT PATH
	.PTFSD==-2	;DEFINES DEFAULT PATH
	.PTFSL==-3	;DEFINE LIBRARY
	.PTFRL==-4	;READ LIBRARY

	PT.NEW==1B32	;RETURNED IF /NEW ENABLED
	PT.SYS==1B33	;RETURNED IF /SYS ENABLED
			;**NOTE THAT DOCUMENTATION HAD INVERTED
			;**THESE LAST TWO.  OLD UUOSYM WAS WRONG ALSO.
	PT.SNW==1B34	;SET TO ENABLE /NEW
	PT.SSY==1B35	;SET TO ENABLE /SYS


;GETTAB STUFF

	.GTJLT==130	;JOB'S LOGGED IN TIME
	%CNDTM==53,,11	;PRESENT UNIVERSAL DATE/TIME

;TRMOP. DEF'S

	.TOSOP==2	;FUNCTION TO SKIP IF OUTPUT BUFFER NOT EMPTY

;HIBER DEF'S

	HB.RWJ==1B15	;ONLY THIS JOB MAY WAKE ITSELF
	SUBTTL	DATA STORAGE

RELOC	0

;THE ORDER OF THESE BLOCKS CORRESPONDS TO THE ORDER OF DATA RETURNED
;BY SCNNER

NDEV:	BLOCK	3	;DEVICES
NFIL:	BLOCK	.RBPRV+1;FILE NAME
NPTH:	BLOCK	10	;PATH
NFMSK:	BLOCK	2	;FILE MASK AND EXTENSION MASK
NPMSK:	BLOCK	6	;MASK OF PATHS
NFLAGS:	BLOCK	1	;FLAGS RETURNED BY SCNNER

ODEV:	BLOCK	3
OFIL:	BLOCK	.RBPRV+1
OPTH:	BLOCK	10
OFMSK:	BLOCK	2
OPMSK:	BLOCK	6

CNFIL:	BLOCK	2	;COPY NEW FILE NAME AND EXT
CNPTH:	BLOCK	6	;COPY NEW PATH
;OTHER STORAGE

	FRSZER==.	;FIRST DATA TO ZERO
SNCWRD:	BLOCK	1	;ARGUMENT TO /AFTER IN UNV DATE/TIME, IF ANY
PTHWRD:	BLOCK	1	;HOLDS BITS TO BE SET OR CLEARED FOR PATH
LSTDEV:	BLOCK	1	;LAST DEVICE TYPED OUT
OLDRP:	BLOCK	1	;HOLDS OLD REV PDL WORD
LSTPTH:	BLOCK	6	;LAST PATH TYPED OUT
FCOUNT:	BLOCK	1	;COUNT OF FILES FOR FAST OUTPUT
DISP:	BLOCK	1	;DISPATCH ADDR
	COMLST==.-1	;WORDS ZEROED ON EVERY NEW COMMAND

LSTCH:	BLOCK	1	;LAST CHARACTER IN
PASSWO:	BLOCK	1	;PASSWORD USED TO CODE STUFF
TEMP:	BLOCK	1	;RANDOM LOCATION
SAVFF:	BLOCK	1	;SAVE .JBFF
SAVEP:	BLOCK	1	;SAVE P
SAVERP:	BLOCK	1	;SAVE RP
CTLCBK:	BLOCK	4	;USED FOR .JBINT TRAPS
MYPPN:	BLOCK	1	;PPN WE ARE RUNNING UNDER
TRMBLK:	BLOCK	2	;SPACE FOR TRMOP.
TOBUF:	BLOCK	3	;TTY OUTPUT BUFFER HEADER
IBUF:	BLOCK	3	;DATA INPUT BUFFER HEADER
OBUF:	BLOCK	3	;DATA OUTPUT BUFFER HEADER
	LSTZER==.-1	;LAST ADDR TO ZERO

PDL:	BLOCK	PDLSIZ	;SPACE FOR PDL
RDL:	BLOCK	RDLSIZ	;SPACE FOR REV PDL


;HI SEG STORAGE
RELOC	400000

PDLWRD:	IOWD	PDLSIZ,PDL	;POINTER TO PDL
	SUBTTL	MAIN ROUTINES

REV:	JFCL			;CCL
	RESET			;CLEAR THE WORLD
	MOVE	P,PDLWRD	;SET UP P
IFN FTCIT,<	;IF DOING CIT STUFF
	RESCAN	1		;READ COMMAND LINE
	SKPINL			;ANYTHING TO READ?
	  JRST	REV0		;NO, SKIP THIS PART
	MOVEI	0,1B27!1B32	;SET UP SCANNER FLAGS TO READ NEW COMMAND, ACCEPT ALL
	INCHWL	T4		;READ THE FIRST CHARACTER
	CAIE	T4,"X"		;THE CALTECH "X" COMMAND?
	  PUSHJ	P,GETCH##	;NO, SO EAT COMMAND LINE
REV0:
>		;END FTCIT CONDITIONAL
	SETZB	F,FRSZER	;FIRST LOC TO ZERO
	MOVE	T1,[FRSZER,,FRSZER+1]	;GET SET
	BLT	T1,LSTZER	;FINISH UP
	MOVE	T1,[4,,CTRAP]	;SET UP JOBINT BLOCK
	MOVEM	T1,CTLCBK	;WITH ADDR
	MOVEI	T1,ER.ICC	;AND CONDITION
	MOVEM	T1,CTLCBK+1	; ..
	MOVEI	T1,CTLCBK	;SET UP ADDR
	MOVEM	T1,.JBINT##	;AND TRAP ^C'S
	GETPPN	T1,		;GET OUR PPN
	  JFCL			;THIS WILL SOONER OR LATER BE MAGIC!
	MOVEM	T1,MYPPN	;SAVE IT
	MOVEI	T1,.TOSOP	;TRMOP FUNCTION TO SKIP IF TTY TYPING
	MOVEM	T1,TRMBLK	;SET UP IN TRMOP. BLOCK
	PJOB	T1,		;OUR JOB
	TRMNO.	T1,		;OUR LINE
	  SETZ	T1,		;DETACHED??
	MOVEM	T1,TRMBLK+1	;SAVE IN TRMOP. BLOCK
	OPEN	TTY,[UU.PHS!.IOASL
		     'TTY   '
		     TOBUF,,0]	;GRAB OUR TTY
	  HALT	.		;CHICKEN LITTLE WAS RIGHT!
	OUTBUF	TTY,1		;SET UP OUTPUT BUFFER
	MOVE	T1,.JBFF##	;GET .JBFF WITH BUFFERS
	MOVEM	T1,SAVFF	;AND SAVE A COPY
;MAIN PROGRAM LOOP

MLOOP:	MOVE	P,PDLWRD	;SET UP P
	PUSHJ	P,TTYOUT	;SEND ALL IN BUFFER
	MOVEI	T1,PUTTTY	;CHARACTER OUTPUT FOR TTY
	MOVEM	T1,OUTADR##	;SET UP ADDRESS FOR LIB OUTPUT
	TLNE	F,FL.CLS	;INPUT FILES MERGED?
	  RELEAS OCHN,		;YES, CLOSE OUTPUT FILE NOW
	TLNE	F,FL.WAT	;WAIT FOR COMMAND TO FINISH?
	  PUSHJ	P,TTYWAT	;YES, DON'T RETURN 'TILL DONE
	MOVE	T1,SAVFF	;GET SAVED .JBFF
	MOVEM	T1,.JBFF##	;AND RESTORE IT
	SKPINL			;DEFEAT ^O
	OUTCHR	["*"]		;SEND A STAR
	SETZM	FRSZER		;CLEAR WORDS ZEROED ON COMMAND
	MOVE	T1,[FRSZER,,FRSZER+1]	;GET SET
	BLT	T1,COMLST	;ZERO ALL
	TLZ	F,COMFLG	;CLEAR COMMAND FLAGS
	SETZM	ALLWLD##	;DON'T FORCE WILD CARD SEARCH
	SETZM	KEPCOR##	;WE ARE NOT RESERVING CORE FROM WILDER
	SETZM	SCNWRD##	;SCANNING IS DEFAULT
	MOVE	T1,[1B0!1B1!1B2!1B3!1B8!1B14!1B32]	;SCNNER FLAGS
	MOVE	T2,SWCWRD	;POINT TO SWITCHES FOR SCNNER
	PUSHJ	P,SCNNER##	;CALL COMMAND SCANNER
	  JRST	MLOOP		;ERROR RETURN
	MOVEM	T1,LSTCH	;SAVE FLAGS AND LAST CHAR
	HRRZ	T2,T1		;GET LAST LETTER IN
	CAIE	T2,"="		;EQUALS SIGN?
	  JRST	DOCOM		;NO, GO PROCESS COMMAND
	TLO	F,FL.EQ		;EQUALS SIGN IN
	PUSHJ	P,NSPECS	;SAVE THE NEW FILE SPECS
	JRST	NLOOP1		;NOW FALL INTO SECOND LOOP
NLOOP:	HRRZ	T1,LSTCH	;GET LAST CHAR
	CAIE	T1,","		;COMMA INDICATING MORE TO COME?
	  JRST	MLOOP		;NO, MAIN LOOP AGAIN
NLOOP1:	TLZ	F,FL.SUP	;DON'T LET SUPER BE STICKY
	PUSHJ	P,TTYOUT	;MAKE SURE TTY BUFFER IS OUT
	MOVSI	T1,(1B1!1B3!1B8!1B14)	;SCNNER FLAGS
	MOVE	T2,SWCWRD	;POINT TO SWITCHES
	PUSHJ	P,SCNNER##	;CALL SCANNER
	  JRST	MLOOP		;ERROR, FLICK IT
	MOVEM	T1,LSTCH	;SAVE LAST CHAR

;FALL INTO COMMAND PROCESSING
DOCOM:	JUMPL	T1,NLOOP	;RESTART IF NULL COMMAND
	SKIPE	T2,DISP		;DISPATCH ADDR SET UP?
	  JRST	DOCOM1		;YES, SKIP ON
	TLNE	F,FL.EQ		;IF EQUALS SIGN
	  TROA	T2,$COPY	;THEN DEFAULT TO COPY COMMAND
	  TROA	T2,$DIR		;ELSE DEFAULT TO DIRECT COMMAND
	  JRST	DOCOM1		;IF /COPY, GO NOW
	TLNN	T1,(1B5)	;SKIP IF NO PROTECTION SPECIFIED
	  MOVEI	T2,$PROT	;PROTECT FILE INSTEAD
DOCOM1:	MOVE	T1,[DEVSPC##,,ODEV]	;COPY DATA BLOCK
	BLT	T1,ODEV+27	;FOR SAFEKEEPING
	TLZE	F,FL.NOW	;EXECUTE WITHOUT WILDER?
	  JRST	DONOW		;YES, GO DO IT
	CAIE	T2,$DIR		;IF DIRECT
	CAIN	T2,$REV		;OR REV
	  JRST	DOCOM2		;GO MAKE CHECKS
	CAIE	T2,$FAST	;IF FAST LIST
	  JRST	DOCOM3		;NOT, SKIP
DOCOM2:	MOVE	T1,LSTCH	;GET SCNNER FLAGS
	TLNE	T1,(1B1)	;IF NO NAME
	  SETOM	OFMSK		;THEN MAKE WILD
	TLNE	T1,(1B2)	;IF NO EXTENSION
	  SETOM	OFMSK+1		;THEN THAT IS WILD
DOCOM3:	MOVEM	T2,DISP		;STORE DISPATCH ADDR
	HRLZ	T1,T2		;NOW SET UP DISPATCH ADDR
	HRRI	T1,ODEV		;AND ADDR OF DATA BLOCK
	PUSHJ	P,WILDER##	;CALL WILD CARD HANDLER
	SKIPE	FCOUNT		;ODD NUMBER OF FILES OUTPUT?
	  PUSHJ	P,TTCRLF	;YES, FINISH WITH CRLF
	JRST	NLOOP		;SCAN MORE COMMANDS


DONOW:	PUSHJ	P,(T2)		;CALL SUBROUTINE IN QUESTION
	  SKIPA			;ERROR RETURN
	JRST	MLOOP		;GOOD RETURN
	PUSHJ	P,STROUT##	;TELL
	  ASCIZ/I'm sorry, but I can't do that
/
	JRST	MLOOP		;MORE COMMANDS
	SUBTTL	SWITCHES

;THESE TABLES ARE PASSED TO SCNNER FOR SWITCH DECODING
;THE TABLE OF SIXBIT SWITCHES ALLOWED ARE IMMEDIATELY FOLLOWED
; BY THE TABLE OF DISPATCH ADDRESSES.

;PREPARE MACRO TO CREATE SWITCHES

DEFINE X<
	Y	(ACCESS,ACCES)
	Y	(AFTER,AFTER)
	Y	(BACKSC,BACK)
	Y	(CODE,CODE)
	Y	(CONFIR,CNFRM)
	Y	(*COPY,COPY)
	Y	(DELETE,DEL)
	Y	(DIRECT,DIR)
	Y	(*EXIT,EXIT)
	Y	(*FAST,FAST)
	Y	(*HELP,HELP)
	Y	(*INDIV,REV)
	Y	(*KILL,DEL)
	Y	(LIBRAR,LIB)
	Y	(LIST,DIR)
	Y	(NOSCAN,NOSCN)
	Y	(PASSWO,PSW)
	Y	(*PATH,PATH)
	Y	(NEW,NEW)
	Y	(SYS,SYS)
	Y	(NONEW,NONEW)
	Y	(NOSYS,NOSYS)
	Y	(PROTEC,PROT)
	Y	(RENAME,REN)
	Y	(SINCE,SINCE)
	Y	(*SUPER,SUPER)
	Y	(*TYPE,TYPE)

>	;END OF STAR MODE SWITCHES
;NOW PREPARE TABLE OF SIXBIT SWITCHES

DEFINE Y(SWITCH,LABEL),<
	SIXBIT/SWITCH/
>

COMSWC:	XLIST	;INVOKE THE X MACRO TO GENERATE SIXBIT TABLE
	X
	LIST
COMLEN==.-COMSWC	;NUMBER OF SWITCHES


;NOW PREPARE DISPATCH TABLE

DEFINE Y,(SWITCH,LABEL),<
	EXP %'LABEL
>

	XLIST	;NOW INVOKE THE X MACRO TO GENERATE DISPATCH TABLE
	X
	LIST


SWCWRD:	-COMLEN,,COMSWC		;AOBJN WORD TO SWITCHES
;NOW DO THE SAME FOR REV MODE SWITCHES

DEFINE X<

	Y	(CODE,CODE)
	Y	(*COPY,COPY)
	Y	(DELETE,DEL)
	Y	(*EXIT,EXIT)
	Y	(*KILL,DEL)
	Y	(PASSWO,PSW)
	Y	(PROTEC,PROT)
	Y	(RENAME,REN)
	Y	(*SUPER,SUPER)
	Y	(*TYPE,TYPE)
	Y	(*UP,UP)

>	;END OF REV MODE SWITCHES

;DEFINE SIXBIT TABLE

DEFINE Y(SWITCH,LABEL),<
	SIXBIT/SWITCH/
>

REVSWC:	XLIST	;GENERATE SIXBIT COMMAND TABLE
	X
	LIST
REVLEN==.-REVSWC	;NUMBER OF REV SWITCHES


DEFINE Y(SWITCH,LABEL),<
	EXP %'LABEL
>

	XLIST	;GENERATE DISPATCH TABLE
	X
	LIST


SWRWRD:	-REVLEN,,REVSWC		;AOBJN WORD TO REV SWITCHES
;DISPATCH HERE FROM SCNNER, T1 HAS LAST CHAR TYPED

%CNFRM:	TLOA	F,FL.CON!FL.TRL	;MUST CONFIRM EVERY FILE
%BACK:	SETOM	BCKWRD##	;SET WILDER FLAG FOR BACKWARDS SCAN
	POPJ	P,		;RETURN

%SUPER:	TLOA	F,FL.SUP	;SET SUPER FLAG
%NOSCN:	SETOM	SCNWRD##	;TURN OFF SCANNING IN WILDER
	POPJ	P,		;RETURN

%AFTER:	TLOA	F,FL.AFT	;FLAG AFTER SWITCH
%UP:	TLOA	F,FL.UP		;FLAG GOING UP
	SETOM	ALLWLD##	;AND FORCE WILDCARDS ON WILDER
	POPJ	P,		;RETURN

%NOSYS:	SKIPA	T2,[(PT.SSY)]	;GET SYS FLAG IN LH
%NONEW:	MOVSI	T2,PT.SNW	;SO WE KNOW TO UNSET
	JRST	%NEW1		;AND FALL INTO CODE
%SYS:	SKIPA	T2,[PT.SSY]	;GET BIT
%NEW:	MOVEI	T2,PT.SNW	;NEW BIT
%NEW1:	IORM	T2,PTHWRD	;SAVE IN PATH WORD
%PATH:	SKIPA	T2,[EXP $PATH]	;SET UP DISPATCH
%LIB:	MOVEI	T2,$LIB		;LIB DISPATCH
	JRST	%EXIT1		;DO IT IMMEDIATELY

%HLPSW:	SKIPA	T2,[EXP $HLPSW]	;SET UP DISPATCH
%EXIT:	MOVEI	T2,$EXIT	;SET UP
%EXIT1:	TLO	F,FL.NOW	;DO IT WITHOUT WILDER
	JRST	GOTDSP

%FAST:	SKIPA	T2,[EXP $FAST]	;FAST LIST
%TYPE:	MOVEI	T2,$TYPE	;SET UP ADDR
	JRST	GOTDSP

%REV:	SKIPA	T2,[EXP $REV]	;SET UP ADDR
%REN:	MOVEI	T2,$REN		; ..
	JRST	GOTDSP

%PSW:	SETZM	PASSWO		;FORCE SCAN OF NEW PASSWORD
%CODE:	TLO	F,FL.PSW	;FLAG THAT WE ARE CODING
	POPJ	P,		;RETURN

%COPY:	SKIPA	T2,[EXP $COPY]	;SET UP DISPATCH ADDRESS
%DEL:	MOVEI	T2,$DEL		; ..
	JRST	GOTDSP

%ACCES:	TLO	F,FL.ACC	;ACCESS FLAG
%DIR:	SKIPA	T2,[EXP $DIR]	;SET UP DIRECT ADDRESS
%PROT:	MOVEI	T2,$PROT	;SET UP PROT ADDR
;	JRST	GOTDSP
;HERE WITH DISPATCH ADR IN T2

GOTDSP:	EXCH	T2,DISP		;SAVE DISPATCH ADDR
	JUMPE	T2,CPOPJ##	;IF NO DOUBLE SWITCH, RETURN
	CAMN	T2,DISP		;IF DISPATCHES MATCH
	  POPJ	P,		;THEN RETURN OK ANYWAY
	MOVEI	T2,[ASCIZ/Multiple switches illegal/]
	JRST	GIVERR##	;GIVE MSG AND QUIT


;HERE TO DO /HELP

%HELP:	MOVEI	T2,$HELP	;ASSUME NORMAL /HELP
	CAIE	T1,":"		;WERE WE RIGHT, OR ARE MORE ARGS COMING?
	  JRST	%EXIT1		;WE WERE RIGHT, SET UP DISPATCH
	PUSHJ	P,WRDINX##	;READ ARGUMENT TO /HELP
	HRROI	T1,[EXP 'SWITCH',%HLPSW]	;ONLY ONE ARG LEGAL
	PJRST	DOSWCH##	;GO SEE IF WE GOT IT


;FOR THE /SINCE:XXX SWITCH

SNCSWC:	SIXBIT/LOGIN/		;GIVE FILES SINCE LOGIN TIME
	SIXBIT/TODAY/		;GIVE FILES CREATED TODAY
	SIXBIT/YESTER/		;GIVE FILES CREATED YESTERDAY OR TODAY
SNCLEN==.-SNCSWC		;NUMBER OF /SINCE ARGUMENT

	EXP	%LOGIN		;WHERE TO DISPATCH ON LOGIN ARG
	EXP	%TODAY		;WHERE TO DISPATCH ON TODAY ARG
	EXP	%YEST		;WHERE TO DISPATCH ON YESTER ARG

SWSWRD:	-SNCLEN,,SNCSWC		;-LENTH,,ADDR

%SINCE:	CAIE	T1,":"		;COLON TYPED, INDICATING SWITCH VALUE?
	SKIPA	T2,SNCSWC	;NO, ASSUME /SINCE:LOGIN
	PUSHJ	P,WRDINX##	;YES, READ ARGUMENT
	MOVE	T1,SWSWRD	;GET SINCE SWITCH WORD
	PJRST	DOSWCH##	;AND DISPATCH TO PROPER ADDR


%LOGIN:	HRROI	T1,.GTJLT	;GETTAB FOR OUR LOGGED IN TIME
	GETTAB	T1,		;GET IT
	  JRST	%TODAY		;CAN'T, USE /TODAY INSTEAD
	JRST	%TDAY1		;FINISH UP

%TODAY:	TDZA	T2,T2		;ZERO IN LH OF T2 FOR TODAY ONLY
%YEST:	MOVSI	T2,1		;NUMBER OF DAYS AGO IN LH
	MOVE	T1,[%CNDTM]	;UNIVERSAL DATE/TIME
	GETTAB	T1,		;GET IT
	  TDZA	T1,T1		;NO, ACCEPT EVERYTHING
	SUB	T1,T2		;ADJUST FOR DATE
	TRZ	T1,-1		;FORGET TIME OF DAY
%TDAY1:	MOVEM	T1,SNCWRD	;SAVE DATE
	POPJ	P,		;RETURN
	SUBTTL	FUNCTIONS

$REV:	HLLZS	LSTCH		;MAKE SURE COMMAND IS TERMINATED
	PUSHJ	P,CHKEQ		;MAKE SURE COMMAND LEGAL
	SETZM	OLDRP		;NOT LOOKING UP STACK
	TLO	F,FL.REV	;FLAG REV MODE
REV1:	SKPINC			;DEFEAT ^O
	  JFCL
	TLZ	F,FL.FST!FL.SUP!FL.CTP!FL.PSW	;NOT SUPER OR DOING FAST LIST
	PUSHJ	P,LSTFIL	;LIST FILE SPEC'S
	  JRST	REV2		;CAN'T, IGNORE THIS FILE
	MOVE	T1,RP		;COPY REV PDL
	SUB	T1,[2,,2]	;MOVE BACK 1 ENTRY
	MOVEM	T1,SAVERP	;AND SAVE AS IF NOTHING HAPPENED
	PUSHJ	P,STROUT##	;SHOW REVIEWING MODE
	  ASCIZ/  : /
	PUSHJ	P,TTYOUT	;SEND LINE
	SETZM	DISP		;CLEAR OLD DISPATCH ADDR
	TLZ	F,FL.UP		;GOING DOWN BY DEFAULT
	MOVE	T1,[1B2!1B8!1B32]	;EXPECT SWITCHES AND PROTECTION
	MOVE	T2,SWRWRD	;ONLY REV SWITCHES
	PUSHJ	P,SCNNER##	;TELL ME WHAT TO DO WITH IT
	  JRST	REV1F		;ERROR, TRY AGAIN
	SETCM	T2,T1		;GET COMPLEMENTED T1 INTO T2
	TLNN	T2,(1B1!1B2!1B3!1B4!1B5)	;ANY FILESPECS IN?
	SKIPE	DISP		;OR AN ADDRESS TO DISPATCH TO?
	  SKIPA			;YES, DO IT
	  JRST	REV2		;NO, JUST CONTINUE
	PUSHJ	P,NSPECS	;SAVE THE NEW FILE SPECS
	SKIPN	T1,DISP		;GET DISP ADDR
	  MOVEI	T1,$REN		;NONE, ASSUME RENAME
	MOVEM	T1,DISP		;SAVE DISPATCH ADDR
	MOVEM	P,SAVEP		;SAVE P FOR ^C TRAP
	PUSHJ	P,(T1)		;GO DISPATCH
REV1F:	  SKIPA	RP,SAVERP	;ERROR SOMEWHERE, RESTORE OLD RP
RLOOP:	  SKIPA	P1,DISP		;NO ERROR, GET DISPATCH ADDR
	  JRST	REV1		;ERROR, GO AGAIN
	TLNE	F,FL.WAT	;WAIT FOR OUTPUT TO FINISH?
	  PUSHJ	P,TTYWAT	;YES, DON'T RETURN 'TILL DONE
	TLZ	F,FL.CTP	;CLEAR ^C TRAP
	CAIN	P1,$TYPE	;IF TYPE
	  JRST	REV1F		;THEN GO AGAIN
	CAIN	P1,$REN		;IF COMMAND WAS EXPLICIT RENAME
	  JRST	REV1B		;THEN SEE IF FILE IS STILL AROUND
	CAIE	P1,$DEL		;IF WE DELETED IT
	  JRST	REV2		;WE DIDN'T, JUST CONTINUE
REV1A:	MOVE	RP,SAVERP	;THEN IT FOR SURE ISN'T AROUND
	SKIPN	T1,OLDRP	;ARE WE UP ON THE STACK NOW?
	  JRST	REV1E		;NO, JUST CONTINUE
	MOVEI	T2,1(RP)	;YES, GET ADDRESS WE JUST REMOVED
	HRLI	T2,3(RP)	;AND THE ONE FOLLOWING THAT
	BLT	T2,(T1)		;MOVE THE STACK DOWN ONE ENTRY
	SUB	T1,[2,,2]	;ADJUST SAVED RPDL
	MOVEM	T1,OLDRP	;AND REPLACE IT
REV1E:	TLNE	F,FL.UP		;IF NOT ASKING TO GO UP
	TLNN	RP,-1		;OR CAN'T GO UP BECAUSE STACK EMPTY
	  JRST	REV3		;THEN DON'T TRY
	JRST	REV2A		;ELSE EDGE UP
REV1B:	MOVE	T1,NFLAGS	;GET SCNNER FLAGS
	TLNE	T1,(1B3)	;SKIP IF DIRECTORY SPECIFIED
	  JRST	REV1D		;NONE, THEREFORE PATH DIDN'T CHANGE
	MOVSI	T1,-6		;UP TO SIX LEVELS OF NESTING
REV1C:	MOVE	T2,NEWPTH##+2(T1)	;GET LEVEL OF OLD PATH
	SKIPN	T3,NPTH+2(T1)		;AND LEVEL OF NEW PATH
	  JUMPE	T2,REV1D	;IF BOTH ZERO, HAVE SCANNED WHOLE DIRECTORY
	CAMN	T2,T3		;HERE IF NOT BOTH ZERO -- MATCH?
	AOBJN	T1,REV1C	;LOOP FOR ALL OR UNTILNO MATCH
	JUMPL	T1,REV1A	;REMOVE THIS FROM STACK IF NEW DIRECTORY
REV1D:	HRLI	T1,NFIL+.RBNAM	;PICK UP NEW NAME
	HRRI	T1,-1(RP)	;AND POINT TO WHERE NAME IS ON STACK
	BLT	T1,(RP)		;FIX UP NAME ON STACK
REV2:	TLNN	F,FL.UP		;GOING UP?
	  JRST	REV3		;NO, SKIP ON
	MOVE	RP,SAVERP	;TAKE CURRENT ENTRY OFF REV STACK
	TLNN	RP,-1		;IS THERE ANYTHING PREVIOUS?
	  JRST	REV4		;NO, DO THIS FILE AGAIN
	SKIPN	OLDRP		;GOING UP FOR THE FIRST TIME?
	  MOVEM	RP,OLDRP	;YES, KEEP OUR PLACE
REV2A:	POP	RP,NEWFIL##+.RBEXT	;FIX UP OLD FILE
	POP	RP,NEWFIL##+.RBNAM	; ..
	JRST	REV1		;AND GO LIST IT

REV3:	SKIPN	T1,OLDRP	;HAVE WE SEEN THIS FILE BEFORE?
	  POPJ	P,		;NO, JUST RETURN TO WILDER
	CAMN	RP,T1		;AT THE TOP OF THE STACK?
	  SETZM	OLDRP		;YES, WILDER FROM HERE ON IN
REV4:	MOVSI	T1,1(RP)	;ADDR OF NEXT FILE
	HRRI	T1,NEWFIL##+.RBNAM	;WHERE TO STORE NAME
	BLT	T1,NEWFIL##+.RBEXT	;SAVE NAME AND EXTENSION
	JRST	REV1		;DO THIS FILE
$EXIT:	TLNN	F,FL.REV	;SKIP IF IN REV MODE
	  EXIT	1,		;STAR MODE, SO GO TO MONITOR
	JRST	MLOOP		;REV MODE, SO GO TO STAR MODE


$DEL:	PUSHJ	P,CHKEQ		;MAKE SURE COMMAND LEGAL
	MOVEI	T1,.RBEXT	;SET UP FOR SHORT RENAME
	MOVEM	T1,NFIL		; ..
	SETZM	NFIL+.RBNAM	;CLEAR NAME FOR DELETE
	SETZM	NFIL+.RBEXT	;AND EXTENSION
	JRST	REN1		;NOW DO RENAME

$PROT:	PUSHJ	P,CHKEQ		;MAKE SURE COMMAND LEGAL
	TLNE	F,FL.REV	;REV MODE?
	  SKIPA	T1,NFIL		;YES, INFO IS IN NFIL BLOCK
	  SKIPA	T1,OFIL		;NO, IT'S OLD
	  SKIPA	T2,NFIL+.RBPRV	;GET OLD PRIV BITS
	  MOVE	T2,OFIL+.RBPRV	; ..
	MOVEI	T3,.RBPRV	;NEED EXTENDED RENAME
	MOVEM	T3,NFIL		;SET UP
	MOVEM	T3,NEWFIL##	;ASSURE LOOKUP GETS OLD INFO
	CAIGE	T1,.RBPRV	;ALREADY SPECIFY PRIV BITS?
	  MOVSI	T2,155000	;NO, GET DEFAULT
	MOVEM	T2,NFIL+.RBPRV	;SAVE AWAY
	MOVE	T1,[NEWFIL##+1,,NFIL+1]	;GET SET
	BLT	T1,NFIL+.RBEXT	;DON'T CHANGE NAME,EXT,PPN
	JRST	REN1		;GO DO IT

$REN:	PUSHJ	P,FILDEF	;FILL DEFAULTS IN NFIL, LEAVE FLAGS IN T1
	MOVEI	T2,NEWPTH##	;GET POINTER TO OLD PATH
	TLNN	T1,(1B3)	;NEW PATH SPECIFIED?
	  MOVEI	T2,NPTH		;YES, USE IT INSTEAD
	MOVEM	T2,NFIL+.RBPPN	;SAVE IN NEW BLOCK
	TLNN	T1,(1B4)	;DEVICE SPECIFIED FOR NEW FILE?
	  JRST	[PJSP	T1,RENDIE	;YES, YOU CAN'T DO THAT
		   ASCIZ/? Device specification illegal for RENAME
/
				]

;CONTINUED
REN1:	TLO	F,FL.FST	;FLAG FAST LIST
	PUSHJ	P,LSTFIL	;LIST FILE NAME
	  POPJ	P,		;FILE WAS REJECTED
	MOVEI	T1,.RBPRV	;GET READY TO READ PRIV BITS
	TLNE	F,FL.SUP	;ONLY IF SUPER RENAME NEEDED
	  MOVEM	T1,NEWFIL##	;YES, READ THEM
	TLNE	F,FL.REV	;IF IN REV MODE
	  JRST	REN1A		;THEN ALREADY HAVE FILE LOOKED UP
	LOOKUP	WLD,NEWFIL##	;LOOKUP FILE
	  JRST	REN3		;CAN'T
REN1A:	HRRZ	T1,NEWFIL##+.RBEXT	;GET DATA IN RH OF EXT WORD
	HRRM	T1,NFIL+.RBEXT	;DON'T CHANGE THIS
	LDB	T1,[POINT 27,NEWFIL##+.RBPRV,35]	;GET OLD DATE, ETC.
	IORM	T1,NFIL+.RBPRV	;SAVE SO WE WON'T CHANGE THIS STUFF
	TLNN	F,FL.SUP	;DOING SUPER RENAME?
	  JRST	REN2		;NO, SKIP THIS CHECK
	MOVEI	P1,T2		;POINT TO T2
	LDB	T2,[POINT 9,NEWFIL##+.RBPRV,8]	;GET FILE PROTECTION
	HRLI	T2,.ACREN	;LH GET FUNCTION -- RENAME
	MOVE	T3,NEWFIL##+.RBPPN	;NEXT WORD GETS PPN OF FILE
	TLNN	T3,-1		;IF A POINTER
	  MOVE	T3,2(T2)	;THEN USE IT TO GET REAL PPN
	MOVE	T4,MYPPN	;MY PPN IN T4
	CHKACC	P1,		;CHECK ACCESS
	  SETZ	P1,		;DON'T KNOW, ASSUME OK
	JUMPE	P1,REN2		;IF NO RENAME NEEDED, DON'T DO IT
	MOVSI	T1,700000	;TURN OFF FIRST PROTECTION DIGIT
	ANDCAM	T1,NEWFIL##+.RBPRV	;IN RENAME BLOCK
	RENAME	WLD,NEWFIL##	;DO THE RENAME
	  JFCL			;DON'T WORRY ABOUT FAILURE
	LOOKUP	WLD,NEWFIL##	;RE-ESTABLISH CHANNEL
	  HALT	.		;SNH
	MOVE	T1,NFLAGS	;GET COMMAND FLAGS
	TLNN	T1,(1B5)	;SKIP IF USER DIDN'T GIVE NEW PROTECTION
	  JRST	REN2		;PROTECTION SPECIFIED
	MOVEI	T1,.RBPRV	;MAKE SURE WE FIXUP PROTECTION
	MOVEM	T1,NFIL		;WITH LARGE RENAME
	DPB	T2,[POINT 9,NFIL+.RBPRV,8]	;REPLACE OLD PROTECTION
REN2:	RENAME	WLD,NFIL	;DO RENAME
	  JRST	REN4		;CAN'T, GIVE ERROR
	AOS	(P)		;ASSURE SKIP RETURN
	TLNE	F,FL.REV!FL.CON	;IF IN REV MODE OR CRLF ALREADY TYPED
	  POPJ	P,		;THEN DON'T TYPE ANYTHING
	PJRST	TTCRLF		;SEND CRLF AFTER FILE NAME

;CONTINUED
;FATAL ERROR ROUTINES

REN3X:	CLOSE	OCHN,CL.RST	;MAKE SURE WE DON'T WRITE AN OUTPUT FILE
REN3:	PUSHJ	P,STROUT##	;LOOKUP ERROR
	  ASCIZ/? LOOKUP Error/
	HRRZ	T1,NEWFIL##+.RBEXT	;GET ERROR CODE FROM LOOKUP
	JRST	REN7		;GIVE REST

REN4:	TLNN	F,FL.SUP	;DID WE THINK ABOUT CHANGING PROTECTION?
	  JRST	REN5		;DIDN'T TRY, SO JUST SKIP ON
	JUMPE	P1,REN5		;JUMP IF NO SUPER RENAME TO LOWER PROT
	LOOKUP	WLD,NEWFIL##	;MAKE SURE FILE IS LOOKED UP
	  JRST	REN5		;CAN'T
	DPB	T2,[POINT 9,NEWFIL##+.RBPRV,8]	;RESTORE ORIGINAL PROTECTION
	RENAME	WLD,NEWFIL##	;DO RENAME
	  JFCL			;WE TRIED
REN5:	PUSHJ	P,STROUT##	;RENAME ERROR
	  ASCIZ/? RENAME Error/

REN6:	HRRZ	T1,NFIL+.RBEXT	;GET ERROR CODE
REN7:	MOVE	T1,ERRBLK##(T1)	;GET DESCRIPTIVE ASCII PTR
	PUSHJ	P,LINOUT##	;TYPE IT
	PJRST	TTCRLF		;THEN TYPE CRLF AND RETURN
;HERE IF WE GET AN ERROR THAT WILL HAPPEN EVERY TIME WILDER
; DISPATCHES TO US.  GIVE ERROR MESSAGE IN T1

RENDIE:	PUSHJ	P,LINOUT##	;GIVE SAD MESSAGE
	TLNE	F,FL.REV	;IF IN REV MODE
	  POPJ	P,		;THEN MERELY GIVE ERROR RETURN
	JRST	MLOOP		;ELSE ABORT ENTIRE COMMAND


;HERE TO SEE IF EQUALS SIGN IN COMMAND.  DIE IF SO.

CHKEQ:	TLNN	F,FL.EQ		;EQUALS SIGN IN?
	  POPJ	P,		;NO, RETURN
	PJSP	T1,RENDIE	;YES, QUIT
	  ASCIZ/? Equals sign illegal in command
/


;HERE TO GIVE ERROR IF WILD CARD OR FILE NAME SPECIFIED

CHKWLD:	MOVSI	T1,-10		;ROOM FOR PATH AND NAME MASKS
	SKIPN	OFMSK(T1)	;SKIP IS MASKED
	AOBJN	T1,.-1		;LOOP FOR ALL
	JUMPGE	T1,CPOPJ##	;NO, RETURN IF NO MASKS
	PJSP	T1,RENDIE	;ERROR
	  ASCIZ/? Wild cards illegal
/


CHKNAM:	MOVEI	T1,[ASCIZ/? File name illegal
/]
	SKIPN	OFIL+.RBNAM	;FILE NAME IN?
	SKIPE	OFIL+.RBEXT	;OR EXTENSION?
	  JRST	RENDIE		;YES, QUIT
	POPJ	P,		;NO, OK


CHKALL:	PUSHJ	P,CHKWLD	;FIRST CHECK FOR WILD CARDS
	PUSHJ	P,CHKNAM	;NONE, CHECK FOR NAME
	PJRST	CHKEQ		;NONE, CHECK EQUALS SIGN
;HERE TO DO /HELP:SWITCHES

$HLPSW:	AOS	(P)		;THIS CANNOT FAIL
	PUSHJ	P,STROUT##	;INSTRODUCTION
	  ASCIZ/Switches are:  /
	MOVE	P1,SWCWRD	;GET AOBJN WORD
	PUSHJ	P,HLPTYP	;TYPE THEM ALL
	PUSHJ	P,STROUT##	;AND REV SWITCHES
	  ASCIZ/
REV switches are:  /
	MOVE	P1,SWRWRD	;GET REV'S AOBJN WORD
	PUSHJ	P,HLPTYP	;TYPE THEM
	PJRST	TTCRLF		;FINISH WITH CRLF


HLPTYP:	MOVEI	P2,6		;FIT 6 SWITCHES ON FIRST LINE
HLPTP1:	MOVE	T1,(P1)		;GET A SWITCHES
	PUSHJ	P,WRDOUT##	;TYPE IT
	AOBJP	P1,CPOPJ##	;GO IF DONE
	PUSHJ	P,STROUT##	;ELSE SEND COMMAND AND SPACE
	  ASCIZ/, /
	SOJG	P2,HLPTP1	;TYPED A FULL LINE OF SWITCHES?
	PUSHJ	P,STROUT##	;YES, SEND CRLF AND SPACE OVER
	  ASCIZ/
        /
	MOVEI	P2,^D8		;AND RESET COUNTER TO 8
	JRST	HLPTP1		;LOOP FOR ALL
$HELP:	MOVE	T1,[HLPDEV]	;GET DEVICE FOR HELP
	MOVEM	T1,NEWDEV##+1	;SAVE AS DEVICE FOR LOOKUP
	MOVE	T1,[[EXP .RBEXT,NEWPTH##,HLPNAM,HLPEXT],,NEWFIL##]
	BLT	T1,NEWFIL##+.RBEXT	;FAKE LOOKUP BLOCK
	MOVE	T1,[EXP HLPPPN]	;GET PPN FOR HELP
	MOVEM	T1,NEWPTH##+2	;SET UP
	SETZM	NEWPTH##+3	;NO SFD'S
	JRST	$TYPE		;NOW TYPE HELP FILE

$COPY:	PUSHJ	P,FILDEF	;PUT OLD DEFAULTS IN NEW FILE
	MOVEI	T1,NPTH		;GET NEW PATH OR DEFAULT IF NONE SPECIFIED
	MOVEM	T1,NFIL+.RBPPN	;WRITE NEW FILE THERE
	MOVE	T1,NDEV+1	;GET DEVICE FOR OUTPUT
	DEVCHR	T1,		;GET CHARACTERISTICS
	SETCA	T1,		;COMPLEMENT T1
	TLNE	T1,(DV.TTA!DV.AVL!DV.TTY)	;IF CONTROLLING TTY AVAIL
	  JRST	COPY0		;NOT TRUE, CAN'T BE OUR OWN TTY

$TYPE:	MOVEI	P1,1		;1 IN P1 AS FLAG
	TLO	F,FL.FST!FL.CTP!FL.WAT	;FLAG SHORT LISTING AND ^C TRAPS
	PUSHJ	P,LSTFIL	;TYPE FILE NAME
	  POPJ	P,		;FILE IS A REJECT
	PUSHJ	P,TTCRLF	;SEND CRLF
	MOVEI	T1,.IOASL	;ASCII MODE FOR OUTPUT
	JRST	COPY0A		;AND GO DO IT

COPY0:	SETZ	P1,		;P1 IS A TEMP FLAG
	TLO	F,FL.FST	;FLAG SHORT LISTING
	PUSHJ	P,LSTFIL	;TYPE FILE NAME
	  POPJ	P,		;REJECT FILE
	TLNE	F,FL.MRG	;DON'T OPEN OUTPUT IF MERGING
	  JRST	COPY0B		;GO DIRECTLY TO INPUT FILE
	SKIPN	NFMSK		;IF NO MASKS
	SKIPE	NFMSK+1		; ..
	  SKIPA			;NOT THE CASE, DON'T DO IT
	  TLO	F,FL.MRG!FL.CLS	;THEN ONLY WRITING ONE FILE
	HRRZ	T1,NEWDEV##	;GET DEVICE FOR INPUT MODE
	CAMGE	T1,NDEV		;TRY RULE OF THUMB -- TAKE LOWER MODE
	  HRRM	T1,NDEV		;AND USE THAT FOR TRANSFER
	MOVSI	T1,OBUF		;SET UP OUTPUT BUFFER HEADER
	MOVEM	T1,NDEV+2	;PUT IN BLOCK
	MOVE	T1,[OCHN,,NDEV]	;CHANNEL,,BLOCK
	PUSHJ	P,OPNDEV##	;DO THE OPEN
	  JRST	COPY4		;CAN'T, ERROR RETURN
	ENTER	OCHN,NFIL	;ENTER OUTPUT FILE
	  JRST	COPY3		;ENTER FAILED
	MOVSI	T1,(POINT 36,0,35)	;WE USE 36 BITS BYTES
	HLLM	T1,OBUF+1	; EVEN IF THE DEFAULT IS DIFFERENT
	TLNE	F,FL.MRG	;MERGING?
	  OUTBUF OCHN,0		;YES, GET DEFAULT # BUFFERS EARLY

;CONTINUED
COPY0B:	HRRZ	T1,NDEV		;GET MODE OF OUTPUT DEV
COPY0A:	TLO	T1,(UU.PHS)	;WE KNOW WHERE INPUT DEVICE IS!
	MOVE	T2,NEWDEV##+1	;GET PHYSICAL INPUT DEVICE
	MOVEI	T3,IBUF		;BUFFER HEADER
	OPEN	ICHN,T1		;GET INPUT DEVICE
	  HALT	.		;SNH
	LOOKUP	ICHN,NEWFIL##	;FIND WILDER'S FILE
	  JRST	REN3X		;LOOKUP FAILED
	MOVSI	T1,(POINT 36,0,35)	;MAKE SURE WE DO INPUT
	HLLM	T1,IBUF+1	; USING 36 BIT BYTES
	TLNE	F,FL.PSW	;IF DOING CODING
	  PUSHJ	P,SETPSW	;THEN SET UP PASSWORD STUFF
	PUSH	P,.JBFF##	;SAVE BUFFER START
	JUMPLE	P1,COPY1	;IF NOT TYPING ON TTY, NO EXTRA CRLF
	TLNN	F,FL.REV!FL.CON	;IF USER DID NOT TYPE CRLF
	  PUSHJ	P,TTCRLF	;THEN SEND ANOTHER
	MOVSI	T1,(POINT 36,0,35)	;SET UP BYTE POINTER FOR 36 BIT BYTES
	HLLM	T1,TOBUF+1	;WANT TTY TO USE THIS FOR TRANSFER
	PUSHJ	P,TTYOUT	;DO OUT TO MAKE BUFFER BYTE COUNT RIGHT

COPY1:	PUSHJ	P,GETCHR	;GET A CHARACTER
	  JRST	COPY2		;EOF
	TLNE	F,FL.PSW	;IF DOING CODING
	  PUSHJ	P,CODCHR	;THEN CODE THIS WORD
	PUSHJ	P,@[EXP PUTCHR,PUTTTY](P1)	;DISPATCH TO PROPER OUTPUT
	JRST	COPY1		;LOOP

COPY2:	JUMPLE	P1,COPY2A	;SKIP ON IF DIDN'T TYPE ON TTY
	PUSHJ	P,TTYOUT	;CLEAR OUTPUT BUFFER
	MOVSI	T1,(POINT 7,0,35)	;SWITCH BACK TO 7 BIT BYTES
	HLLM	T1,TOBUF+1	;  (WE USED 36 BIT BYTES FOR TRANSFER)
COPY2A:	TLNE	F,FL.MRG	;IF MERGING FILES
	  SETOM	KEPCOR##	;THEN WILDER BETTER NOT DEALLOCATE CORE
	RELEAS	ICHN,		;RELEASE CHANNELS
	POP	P,.JBFF##	;FIX UP .JBFF
	AOS	(P)		;ASSURE SKIP RETURN
	PJUMPG	P1,TTCRLF	;IF TYPING, JUST OUTPUT TO TTY AND RETURN
	TLNN	F,FL.REV	;MERGE IS MEANINGLESS IN REV MODE
	TLNN	F,FL.MRG	;DON'T CLOSE IF MERGING MANY FILES
	  RELEAS OCHN,		;THEN RELEASE IT
	TLNE	F,FL.REV!FL.CON	;IF IN REV MODE OR CRLF TYPED
	  POPJ	P,		;THEN TYPE NO MORE
	PJRST	TTCRLF		;TYPE CRLF SINCE WE TYPED FILE NAME


COPY3:	TLNN	F,FL.REV	;IF NOT IN REV MODE
	  PUSHJ	P,TTCRLF	;GIVE CRLF
	MOVE	T1,[NDEV,,NFIL]	;POINT TO OPEN AND ENTER BLOCKS
	PUSHJ	P,ENTFA##	;GIVE ERROR MESSAGE
	TLNE	F,FL.MRG	;IF MERGING
COPY4:	TLNE	F,FL.REV	;AND NOT IN REV MODE
	  POPJ	P,		;NOT THE CASE, JUST RETURN
	JRST	MLOOP		;THEN QUIT EARLY
;HERE FOR SPECIAL CODING FUNCTIONS

;HERE TO SET UP PASSWORD IN T3 AND MASK IN T2
;THE PASSWORD WILL BE READ IN FROM THE TTY IF NONE EXISTS

SETPSW:	SKIPE	T3,PASSWO	;PICK UP PASSWORD, IF ANY
	  JRST	SETPS3		;GOT IT
	SETSTS	TTY,IO.SUP!.IOASL	;KILL ECHO ON TTY
SETPS2:	PUSHJ	P,STROUT##	;ASK FOR PASSWORD
	  ASCIZ/
PS:/
	PUSHJ	P,TTYOUT	;TYPE IT
	PUSHJ	P,WRDINZ	;GET PASSWO FROM TTY
	MOVEM	T3,PASSWO	;STORE SIXBIT PASSWO
	PUSHJ	P,STROUT##	;GET CONFIRMATION
	  ASCIZ/
PX:/
	PUSHJ	P,TTYOUT	; ..
	PUSHJ	P,WRDINZ	;GET CONFIRMATION
	PUSHJ	P,TTCRLF	;SEND CRLF
	CAME	T3,PASSWO	;SAME THING?
	  JRST	SETPS2		;NO, LOOP BACK TO GET AGAIN
	SETZ	T2,		;CLEAR MASK
	MOVEI	T4,^D10		;WANT TO MUNGE PASSWO A BIT
	PUSHJ	P,CHGMSK	;GO DO IT
	SOJG	T4,.-1		;A FEW TIMES
	MOVE	T3,T2		;SAVE THIS MASK AS PASSWO
	MOVEM	T3,PASSWO	;STORE FOR RE-USE
	SETSTS	TTY,.IOASL	;ECHO TTY AGAIN
SETPS3:	SETZ	T2,		;CLEAR MASK
	POPJ	P,		;RETURN


;HERE TO CODE THE CHARACTER IN T1

CODCHR:	PUSHJ	P,CHGMSK	;FIX OUR MASK
	XOR	T1,T2		;NOW XOR THE CHARACTER TO MASK IT
	POPJ	P,		;DONE


;HERE TO FIX UP MASK

CHGMSK:	PUSHJ	P,MCHMSK	;GO MUNCH MASK
	TLNN	T2,1B33		;IF RANDOM BIT IS SET
	  POPJ	P,		;THEN DON'T JUST RETURN
;	PJRST	MCHMSK		;MUNCH MASK AGAIN INSTEAD

MCHMSK:	XOR	T2,T3		;XOR TO FIX
	LDB	T4,[POINT 4,T2,34]	;GRAB A FEW BITS FROM PSW
	ROT	T2,(T4)		;ROTATE RANDOMLY
	IMUL	T2,[^D134217827]	;MULTIPLY
	ADD	T2,[^D212885833]	;AND ADD
	POPJ	P,		;THAT OUGHT TO DO IT
$DIR:	JSP	P1,SETOUT	;SET UP OUTPUT DEVICE
	TLNN	F,FL.CTP	;TYPING ON OUR TTY?
	  SETOM	KEPCOR##	;NO, SO WORRY ABOUT OUTPUT BUFFERS
	PUSHJ	P,LSTFIL	;SHOW FILE SPECS
	  POPJ	P,		;ERROR, JUST RETURN
	TLNN	F,FL.ACC	;DOING ACCESS?
	  PJRST	TTCRLF		;NO, DONE
	SKIPE	NEWFIL##+.RBSIZ	;IF ANYTHING IN FILE
	IN	WLD,[IOWD 1,TEMP;THEN READ A WORD
			Z]	;(WILDER OPENED CHANNEL IN DUMP MODE)
	SKIPA			;GOOD RETURN
	SETSTS	WLD,.IODMP	;CLEAR ERROR
	CLOSE	WLD,		;UPDATE ACCESS DATE
	PJRST	TTCRLF		;AND FINISH UP


$FAST:	JSP	P1,SETOUT	;SET UP OUTPUT DEVICE
	TLNN	F,FL.CTP	;TYPING ON OR TTY?
	  SETOM	KEPCOR##	;NO, KEEP OUTPUT BUFFERS FROM LEAVING
	TLO	F,FL.FST!FL.TRL	;THESE LISTINGS ARE FAST, KEEP TRAILING SPACES
	TLZ	F,FL.CON	;CAN'T CONFIRM THIS
	MOVE	T1,FCOUNT	;HOW MANY FILES IN THIS LINE?
	CAIN	T1,3		;IF THIS IS THE LAST ONE
	  TLZ	F,FL.TRL	;THEN DON'T KEEP TRAILING SPACES
	PUSHJ	P,LSTFIL	;GO DO IT
	  POPJ	P,		;REJECTED
	MOVEI	T1," "		;SET UP ASCII SPACE
	AOS	T2,FCOUNT	;BUMP FILE COUNT
	CAIE	T2,4		;4 YET?
	  PJRST	CHROUT##	;TYPE SPACE AND RETURN
	SETZM	FCOUNT		;CLEAR COUNT
	PJRST	TTCRLF		;AND DO A CRLF
;HERE TO SET UP OUTPUT DEVICE IN PLACE OF TTY


SETOUT:	TLOE	F,FL.OUT	;OUTPUT DEVICE SET UP YET?
	  JRST	(P1)		;YES, RETURN FAST
	TLO	F,FL.CTP!FL.WAT	;ASSUME WE WANT TO TRAP ^C'S
	TLNN	F,FL.EQ		;EQUALS SIGN IN COMMAND?
	  JRST	(P1)		;NO, JUST TYPE ON TTY
	MOVE	T1,NDEV+1	;GET DEVICE
	DEVCHR	T1,		;CHARACTERISTICS
	SETCA	T1,		;COMPLEMENT T1
	TLNN	T1,(DV.TTA!DV.AVL!DV.TTY)	;SKIP IF IT'S NOT OUR TTY
	  JRST	(P1)		;OUIR TTY IS DEFAULT
	MOVEI	T1,.IOASL	;SET UP ASCII
	HRRM	T1,NDEV		;IN OPEN BLOCK
	MOVE	T1,NFLAGS	;PICK UP SCNNER FLAGS
	MOVSI	T2,'REV'	;DEFAULT FILE NAME
	TLNE	T1,(1B1)	;FILE NAME SPECIFIED?
	  MOVEM	T2,NFIL+.RBNAM	;NO, FILL IT IN
	MOVSI	T2,'DIR'	;DEFAULT EXTENSION
	TLNE	T1,(1B2)	;EXTENSION SPECIFIED?
	  MOVEM	T2,NFIL+.RBEXT	;NO, FILL IT IN
	MOVSI	T1,OBUF		;SET UP BUFFER
	MOVEM	T1,NDEV+2	;STORE IN OPEN BLOCK
	MOVE	T1,[OCHN,,NDEV]	;CHANNEL,,OPEN BLOCK
	PUSHJ	P,OPNDEV##	;OPEN THE CHANNEL
	  JRST	COPY4		;CAN'T, ERROR
	ENTER	OCHN,NFIL	;ENTER THE FILE
	  JRST	COPY3		;CAN'T, ERROR
	MOVEI	T1,PUTCHR	;ADDR TO PUT A CHAR
	MOVEM	T1,OUTADR##	;SET UP
	TLO	F,FL.CLS	;FLAG SO FILE WILL GET CLOSED WHEN DONE
	TLZ	F,FL.CTP!FL.WAT	;SINCE NOT TYPING ON TTY, DON'T TRAP ^C
	JRST	(P1)		;AND RETURN
LSTFIL:	TLNE	F,FL.REV	;IF IN REV MODE
	  JUMPL	F,CPOPJ1##	;AND SHORT LISTING, IGNORE REQUEST
	TLZ	F,FL.BAD	;ASSUME NO KNOWLEDGE OF FILE
	SKIPE	T2,SNCWRD	;PICK UP /SINC ARG
	JRST	[MOVEI  T1,.RBTIM	;IF DATE/TIME LIMIT, GET
		 JRST   LSTF0A]		; LONG LOOKUP HEADER
	JUMPL	F,LSTF0		;IF SHORT LISTING, NO LOOKUP NEEDED
	MOVEI	T1,.RBSPL	;GET HEADER FOR LOOKUP FOR NORMAL LIST
LSTF0A:	MOVEM	T1,NEWFIL##	;SAVE LOOKUP HEADER
	MOVEM	T2,NEWFIL##+.RBTIM	;SHOW FILE IF LOOKUP FAILS
	LOOKUP	WLD,NEWFIL##	;DO THE LOOKUP
	  TLO	F,FL.BAD	;REMEMBER ERROR
	JUMPE	T2,LSTF0	;GO IF NO DATE LIMIT
	CAMLE	T2,NEWFIL##+.RBTIM	;DOES THIS FILE MEET DATE?
	  POPJ	P,		;NO, IGNORE IT
LSTF0:	TLZN	F,FL.AFT	;/AFTER SPECIFIED?
	  JRST	LSTF0B		;NO, SKIP
	SETZM	OFIL+.RBNAM	;ZERO OLD NAME
	SETOM	OFMSK		;AND MAKE EVERY FILE AFTER THIS
	SETZM	OFIL+.RBEXT	; A MATCH
	SETOM	OFMSK+1		; ..
LSTF0B:	MOVE	T1,NEWDEV##+1	;GET SIXBIT DEVICE IN T1
	CAME	T1,LSTDEV	;SAME AS LAST DEVICE?
	  JRST	LSTF1		;NO, LIST DEVICE AND PPN
	MOVSI	T2,-6		;GET SET TO COMPARE PATHS
	MOVE	T1,NEWPTH##+2(T2)	;GET NEW PATH
	CAMN	T1,LSTPTH(T2)	;COMPARE WITH OLD PATH
	  AOBJN	T2,.-2		;LOOP IF THE SAME
	JUMPGE	T2,LSTF2	;JUMP IF PATH NOT CHANGED
LSTF1:	SKIPE	FCOUNT		;IF IN THE MIDDLE OF ALINE
	  PUSHJ	P,TTCRLF	;GIVE CRLF FOR NEW DIRECTORY
	SETZM	FCOUNT		;CLEAR COUNT FOR FAST OUTPUT
	MOVE	T1,NEWDEV##+1	;GET SIXBIT DEVICE
	MOVEM	T1,LSTDEV	;SAVE AS LAST DEVICE
	PUSHJ	P,WRDOUT##	;TYPE IT
	MOVE	T1,NEWDEV##+1	;GET SIXBIT DEVICE
	DEVCHR	T1,		;GET CHARACTERISTICS
	TLNN	T1,(DV.TTY)	;CATCH THE NULL DEVICE
	TLNN	T1,(DV.DIR)	;DIRECTORY?
	  JRST	CPOPJ1##	;NO, GOOD RETURN NOW
	MOVE	T1,[NEWPTH##+2,,LSTPTH]	;OK, SET UP BLT POINTER
	PUSHJ	P,STROUT##	;SEND COLON AND TAB
	  ASCIZ/:	/
	BLT	T1,LSTPTH+5	;SAVE PATH AS OLD PATH
	MOVEI	T1,NEWPTH##	;POINT TO PATH
	PUSHJ	P,PPNOUT##	;TYPE PATH
	PUSHJ	P,TTCRLF	;TYPE CRLF
	MOVEI	RP,RDL-1	;SET UP ADDRESS OF REV PDL

;CONTINUED
LSTF2:	MOVE	T1,NEWFIL##+.RBNAM	;GET NAME
	HLRZ	T2,NEWFIL##+.RBEXT	;AND EXT
	PUSHJ	P,[CAIE   T2,'UFD'	;IF A NORMAL FILE
		     JRST SIXOUT##	;THEN DO SIXBIT OUTPUT
		   JRST   PPNOUT##]	;BUT TYPE A PPN FOR UFD'S
	HLLZ	T1,NEWFIL##+.RBEXT	;GET EXTENSION
	JUMPN	T1,LSTF2A	;IF THERE IS AN EXTENSION, MUST TYPE IT
	TLNN	F,FL.TRL	;IF NO EXT, AND WE DON'T TYPE TRAILING SPACE
	  JUMPL	F,CPOPJ1##	;AND THIS IS A SHORT LISTING, RETURN NOW
LSTF2A:	PUSHJ	P,STROUT##	;NOW SEND TWO SPACES
	  ASCIZ/  /
	TLNN	F,FL.TRL	;IF NOT DOING TRAILING SPACES
	  JUMPL	F,[AOS   (P)	;AND SHORT LIST, ASSURE GOOD RET
		   PJRST WRDOUT##]	;AND FINISH WITHOUT TRAILING
	PUSHJ	P,SIXOUT##	;TYPE EXTENSION WITH FINAL BLANKS
	JUMPL	F,SHRTLD	;RETURN NOW IF SHORT LISTING
	TLNN	F,FL.BAD	;LOOKUP FAILED?
	  JRST	LSTF4		;NO, SKIP ON
	PUSHJ	P,STROUT##	;GIVE SAD NEWS
	  ASCIZ/Error /
	HRRZ	T1,NEWFIL##+.RBEXT	;GET ERROR CODE
	MOVE	T1,ERRBLK##(T1)	;GET POINTER TO ASCII MSG
	PUSHJ	P,LINOUT##	;TYPE IT
	PJRST	TTCRLF		;SEND CRLF AND RETURN

LSTF4:	TLNN	F,FL.REV	;IN REV MODE?
	  JRST	LSTF4B		;NO, NO NEED TO KEEP UP REV STACK
	HLRZ	T1,RP		;HOW MANY NAMES HAVE BEEN PUSHED?
	CAIGE	T1,RDLSIZ-1	;MORE THAN STACK SIZE YET?
	  JRST	LSTF4A		;NO, SKIP ON
	MOVE	T1,[RDL+2,,RDL]	;WANT TO MOVE ENTIRE STACK DOWN ONE
	BLT	T1,RDL+RDLSIZ-3	;TO MAKE ROOM FOR ONE MORE
	SUB	RP,[2,,2]	;AND DISGARD THE OLDEST ENTRY
LSTF4A:	PUSH	RP,NEWFIL##+.RBNAM	;SAVE THE FILE NAME
	PUSH	RP,NEWFIL##+.RBEXT	;AND EXTENSION
LSTF4B:	MOVE	T2,NEWFIL##+.RBSIZ	;GET SIZE IN WORDS
	MOVEI	T2,177(T2)	;TAKE CARE OF REMAINDER -- TXR
	LSH	T2,-7		;DIVIDE BY 200
	MOVEI	T1," "		;SET UP SPACE TO RIGHT JUSTIFY
	CAIGE	T2,^D1000	;JUSTIFY
	  PUSHJ	P,CHROUT##	; ..
	CAIGE	T2,^D100	; ..
	  PUSHJ	P,CHROUT##	; ..
	CAIGE	T2,^D10		; ..
	  PUSHJ	P,CHROUT##	; ..
	MOVEI	T1,(T2)		;GET SIZE
	PUSHJ	P,DECOUT##	;TYPE IT
	PUSHJ	P,STROUT##	;PROTECTION COMING
	  ASCIZ/  </
	MOVE	T2,[POINT 3,NEWFIL##+.RBPRV]	;BYTE PTR TO PROTECTION
	MOVEI	T3,3		;3 DIGITS

;CONTINUED
LSTF5:	ILDB	T1,T2		;GET BYTE
	MOVEI	T1,"0"(T1)	;MAKE ASCII
	PUSHJ	P,CHROUT##	;TYPE
	SOJG	T3,LSTF5	;LOOP
	PUSHJ	P,STROUT##	;FINISH
	  ASCIZ/>  /
	LDB	T1,[POINT 12,NEWFIL##+.RBPRV,35]	;GET LOW ORDER DATE
	LDB	T2,[POINT 3,NEWFIL##+.RBEXT,20]		;GET HIGH ORDER
	DPB	T2,[POINT 3,T1,35-12]			;MERGE
	PUSHJ	P,TYPDAT##	;TYPE DATE
	TLNE	F,FL.REV	;IF IN REV MODE
	  JRST	CPOPJ1##	;THEN DON'T GIVE EXTRAS
	SKIPN	T1,NEWFIL##+.RBVER	;PICK UP  VERSION
	  JRST	LSTF6		;NONE, SKIP
	PUSHJ	P,STROUT##	;INDENT A BIT
	  ASCIZ/   /
	PUSHJ	P,TYPVER##	;TYPE VERSION
LSTF6:	SKIPN	T1,NEWFIL##+.RBSPL	;PICK UP SPOOLING WORD
	  JRST	CPOPJ1##	;NONE, JUST RETURN
	PUSHJ	P,STROUT##	;INDENT A BIT
	  ASCIZ/   /
	PUSHJ	P,WRDOUT##	;TYPE SPOOLING NAME
	JRST	CPOPJ1##	;AND SKIP RETURN


;HERE WHEN DONE WITH SHORT LISTING TO CHECK IF CONFIRMATION NEEDED

SHRTLD:	TLNN	F,FL.CON	;NEED TO CONFIRM?
	  JRST	CPOPJ1##	;NO, GOOD RETURN
	TLO	F,FL.CTP	;TRAP ^C DURING THE INTERIM
	PUSHJ	P,STROUT##	;ASK
	  ASCIZ/Confirm: /
	PUSHJ	P,TTYOUT
	PUSHJ	P,WRDINZ	;READ A WORD FROM TTY
	MOVSS	T3		;SWAP HALVES OF SIXBIT RETURNED
	JUMPE	T3,CPOPJ##	;NULL ANSWER MEANQ "NO"
	CAIE	T3,'N  '	;CHECK ABBREVIATIONS FOR "NO"
	CAIN	T3,'NO '	; ..
	  POPJ	P,		;ERROR RETURN IF SO
	CAIE	T3,'Y  '	;"YES" ABBREVIATIONS
	CAIN	T3,'YE '	; ..
	  JRST	CPOPJ1##	;GOOD RETURN
	CAIN	T3,'YES'	;"YES"?
	  JRST	CPOPJ1##	;YES
	JRST	SHRTLD		;UNRECOGNIZED
;HERE TO DO PATH STUFF
;SOME OF THE PATH FUNCTIONS ARE NOT VERY WELL DOCUMENTED.

$LIB:	PUSHJ	P,CHKALL	;ERROR IF WILD STUFF
	MOVE	T1,[3,,T2]	;GET SET
	HRROI	T2,.PTFRL	;TO READ OLD LIB AND FLAGS
	PATH.	T1,		;DO IT
	  POPJ	P,		;CAN'T
	HRROI	T2,.PTFSL	;SET LIBRARY FUNCTION
	MOVE	T4,LSTCH	;GET SCANNER FLAGS
	TLNN	T4,(1B3)	;PPN SPECIFIED?
	  SKIPA	T4,OPTH+2	;YES, GET LIBRARY PPN
	    TDZA T4,T4		;NO, MAKE ZERO LIB
	SKIPN	OPTH+3		;ERROR RETURN IF SFD'S SPECIFIED
	PATH.	T1,		;SET LIBRARY
	  POPJ	P,		;CAN'T DO IT
	JRST	CPOPJ1##	;RETURN

$PATH:	PUSHJ	P,CHKALL	;ERROR IF WILD STUFF
	HRROI	T2,.PTFRL	;SET UP TO FIND LIB AND FLAGS
	MOVE	T1,[3,,T2]	;JUST WANT TO READ FLAGS
	PATH.	T1,		;DO IT
	  POPJ	P,		;PATH. MUST NOT BE IMPLEMENTED
	IOR	T3,PTHWRD	;LIT BITS THAT WERE SET BY COMMAND
	TSZ	T3,T3		;CLEAR BITS THAT WERE TURNED OFF
	HRROI	T2,.PTFSL	;SET LIB
	PATH.	T1,		;DO IT
	  POPJ	P,		;CAN'T
	HRROI	T1,.PTFSD	;GET NEW PATH FUNCTION
	MOVEM	T1,OPTH		;PUT IN BLOCK
	MOVE	T1,[10,,OPTH]	;POINT TO NEW PATH (NOTE THAT IF NO PATH
	PATH.	T1,		; WAS SPECIFIED, SCNNER RETURNED DEFAULT)
	  POPJ	P,		;CAN'T DO IT
	JRST	CPOPJ1##	;RETURN
;HERE WHEN ^C TYPED


CTRAP:	PUSH	P,CTLCBK+2	;SAVE INTERRUPTED PC
	SETZM	CTLCBK+2	;ENABLE TRAPS AGAIN
	TLNN	F,FL.CTP	;SKIP IF WE DON'T GO TO MONITOR
	  JRST	CTRAP1		;WE WANT TO QUIT NOW
	MOVEI	T1,ICHN		;INPUT CHANNEL
	RESDV.	T1,		;RESET IT IF IT WAS IN USE
	  JFCL			;IGNORE ERROR
REPEAT 0,<	;UNNECESSARY NOW, AS WE DON'T TRAP ON OUTPUT
	MOVEI	T1,OCHN		;GET OUTPUT CHANNEL
	RESDV.	T1,		;RESET IT
	  JFCL			;IGNORE ERROR
>
	CLRBFO			;CLEAR OUTPUT BUFFER
	HLLZS	TOBUF+1		;ZERO ADDR OF CURRENT BP
	SETZM	TOBUF+2		;AND BYTE COUNT
	PUSHJ	P,TTYOUT	;SO WE THROW AWAY CURRENT BUFFER
	MOVSI	T1,(POINT 7,0,35)	;MAKE SURE HAVE 7 BITS BYTES
	HLLM	T1,TOBUF+1	;IN OUR TTY
	PUSHJ	P,TTCRLF	;CRLF
	TLNN	F,FL.REV	;REV MODE?
	  JRST	MLOOP		;NO, GO TO COMMAND MODE
	MOVE	P,SAVEP		;RESTORE OLD PDL POINTER
	JRST	RLOOP		;YES, RETURN TO REV

CTRAP1:	EXIT	1,		;RETURN TO MONITOR
	POPJ	P,		;HE CONTINUED, SO RETURN
	SUBTTL	I/O ROUTINES

;HERE TO SEND CHARACTER TO TTY

PUTTTY:	SOSG	TOBUF+2		;ANY ROOM?
	  PUSHJ	P,TTYOUT	;NO, SEND ALL
	IDPB	T1,TOBUF+1	;SEND CHARACTER IN T1
	POPJ	P,		;RETURN

TTCRLF:	PUSHJ	P,TCRLF##	;SEND A CRLF
;	PJRST	TTYOUT		;AND OUTPUT THE BUFFER

TTYOUT:	OUT	TTY,		;SEND OUTPUT
	  POPJ	P,		;RETURN
	SETSTS	TTY,.IOASL	;SET TTY BACK TO ASCII
	POPJ	P,		;AND RETURN


;HERE TO INPUT A CHAR FROM INPUT DATA CHANNEL
;SKIP RETURN IF GOOD, NON-SKIP IF EOF

GETCHR:	SOSGE	IBUF+2		;ANY ROOM?
	  JRST	GETBUF		;NO, FILL BUFFER
	ILDB	T1,IBUF+1	;GET CHAR
	JRST	CPOPJ1##	;SKIP RETURN

GETBUF:	IN	ICHN,		;GET INPUT
	  JRST	GETCHR		;GOT IT
	STATO	ICHN,IO.ERR	;MAJOR ERROR?
	  POPJ	P,		;NO, MUST JUST BE EOF
	PUSHJ	P,STROUT##	;SEND SAD MESSAGE
	  ASCIZ/? Read error/
	EXIT			;QUIT


;HERE TO OUTPUT A CHARACTER FROM T1 TO OUTPUT CHANNEL

PUTCHR:	SOSG	OBUF+2		;ANY ROM?
	  JRST	PUTBUF		;NO, SEND BUFFER
PUTCH1:	IDPB	T1,OBUF+1	;SEND CHAR
	POPJ	P,		;RETURN

PUTBUF:	OUT	OCHN,		;SEND BUFFER
	  JRST	PUTCH1		;RETURN
	PUSHJ	P,STROUT##	;GIVE SAD MESSAGE
	  ASCIZ/? Output error/
	EXIT			;QUIT
	SUBTTL	SUBROUTINES

;CALL THIS RIGHT AFTER CALLING SCNNER
;SCNNER FLAGS AND DATA ARE SAVED

NSPECS:	HLLZM	T1,NFLAGS	;SAVE THE FLAGS
	MOVE	T2,[DEVSPC##,,NDEV]	;GET SET
	BLT	T2,NDEV+27	;TRANSFER THE WHOLE BLOCK
	TLNE	T1,(1B1)	;WAS NAME SPECIFIED?
	  SETOM	NFMSK		;NO, ZAP MASK
	TLNE	T1,(1B2)	;HOW ABOUT EXT?
	  SETOM	NFMSK+1		;NO, ZAP EXT MASK
	MOVEI	T1,NPTH		;GET POINTER TO PATH IN NEW BLOCK
	MOVEM	T1,NFIL+.RBPPN	;SET UP HERE
	MOVE	T1,[NFIL+.RBNAM,,CNFIL]	;SAVE SPECIFIED
	BLT	T1,CNFIL+1	; NAME AND EXTENSION
	MOVE	T1,[NPTH+2,,CNPTH]	;GET SET
	BLT	T1,CNPTH+5	;SAVE ORIGINAL SPECIFIED PATH
	POPJ	P,		;RETURN


;HERE TO FILL IN DEFAULTS FROM OLD TO NEW FOR COPY AND RENAME

FILDEF:	MOVEI	T1,[ASCIZ/? Command must have input file specs
/]
	TLNN	F,FL.EQ!FL.REV	;WERE THERE ANY OLD FILE SPECS?
	  JRST	RENDIE		;NO, GIVE THAT MESSAGE AND QUIT
	MOVSI	T2,-2		;LOOP TWICE
FILD1:	MOVE	T1,NEWFIL##+.RBNAM(T2)	;GET OLD FILE NAME
	AND	T1,NFMSK(T2)	;WHAT IS MASKED WE KEEP
	IOR	T1,CNFIL(T2)	;OR WITH SPECIFIED NAME
	MOVEM	T1,NFIL+.RBNAM(T2)	;AND SAVE
	AOBJN	T2,FILD1	;SAME FOR EXTENSION
	MOVSI	T2,-6		;SIX LEVELS OF NESTING
FILD2:	MOVE	T1,NEWPTH##+2(T2)	;PICK UP PATH
	AND	T1,NPMSK(T2)	;KEEP MASKED PARTS
	IOR	T1,CNPTH(T2)	;USE USER-SPECIFIED PARTS
	MOVEM	T1,NPTH+2(T2)	;AND SAVE THE RESULT
	AOBJN	T2,FILD2	;LOOP FOR ENTIRE PATH
	HLLZS	NFIL+.RBEXT	;GUARD AGAIN JUNK IN EXT WORD
	MOVSI	T1,777000	;GET PROTECTION FIELD IN T1
	ANDM	T1,NFIL+.RBPRV	;CLEAR JUNKY BITS IN PRV WORD
	MOVE	T1,NFLAGS	;SET UP SCANNER FLAGS IN T1 FOR RETURN
	POPJ	P,		;RETURN
;HERE TO READ IN A WORD FROM THE TTY
;WORD READ INTO T3 IN SIXBIT, T1-T4 DESTROYED

WRDINZ:	MOVEI	0,1B27!1B32	;SCANNER FLAGS TO READ NEW COMMAND AND TAKE ALL
	MOVE	T2,[POINT 6,T3]	;BUILD WORD IN T3
	SETZB	T3,T4		;CLEAR AC'S
WRDIN1:	PUSHJ	P,GETCH##	;GET A CHAR
	JUMPE	T1,CPOPJ##	;LEAVE IF BREAK
	MOVEI	T1,-40(T1)	;MAKE SIXBIT
	TLNE	T2,770000	;SKIP IF ALREADY TOO MANY
	  IDPB	T1,T2		;ELSE LOAD INTO T3
	JRST	WRDIN1		;LOOP


;HERE TO WAIT FOR TTY TO STOP PRINTING
;RETURN WHEN DONE

TTYWAT:	MOVE	T1,[2,,TRMBLK]	;SET UP TRMOP PTR
	TRMOP.	T1,		;IS TTY STILL TYPING?
	  POPJ	P,		;NO, DONE
	MOVE	T1,[HB.RWJ+^D250]	;WAIT 1/4 SECOND
	MOVEI	T2,1		;OR A SECOND IF NO HIBER
	HIBER	T1,		;TRY TO WAIT
	  SLEEP	T2,		;BY ANY MEANS
	JRST	TTYWAT		;LOOP

	END	REV