;[I4-TENEX]<MFEXEC>X4CMD.MAC;20204,  4-DEC-79 11:15:32, Ed: RLWSSD
; FIXED ..NUMB TO ACCEPT & REPORT IN ERRMSG 0-13 (DEC) VERSIONS
;[I4-TENEX]<MFEXEC>X4CMD.MAC;20203, 22-OCT-79 15:37:49, Ed: RLWSSD
;[I4-TENEX]<MFEXEC>X4CMD.MAC;20202, 22-OCT-79 14:56:12, Ed: RLWSSD
; IAC MODS
;<MFEXEC>X4CMD.MAC;20201    19-JUL-79 16:13:23    EDIT BY WEISSMAN
; MODS TO ^EHALT
;<MFEXEC>X4CMD.MAC;20200  25-SEP-78 15:35:44  EDIT BY B-SMITH
;Changed references to EXEC to be to MFEXEC
;<MFEXEC>X4CMD.MAC;20101  27-DEC-77 16:19:38  EDIT BY B-SMITH
;2.01
;<MFEXEC>X4CMD.MAC;20000  25-SEP-76 05:33:53  EDIT BY DALE
; ^E EDDT reads symbols from file
; ^E QUIT goes directly to MINI EXEC
; General clean up
;2.00

;1.53
;1.52
;"NO MAILBOX" SUBCOMMAND FOR "^E CREATE"
; USE SYSTEM DEFAULTS FOR DIRECTORY PROTECTION AND DEFAULT
;   FILE PROTECTION.  CHANGE DIRPNT TO CORRESPOND
; "CREATE" AND "PRINT" DO AUTOMATIC "BREAK" AND "REFUSE"
; ALLOW FOR CRDIR TO SKIP
; ADD NETWIZARD CAPABILITY

;1.51
; CHANGE .NOT TO ..NOT TO ELIMINATE CONFLICT WITH MAIN .NOT

;1.50
; END CONDITIONAL ON DST10X
; REMOVE END SO X5 WILL GET ASSEMBLED

;1.49
; 1B16 TO CRDIR FOR KILL

;1.48
; ^E PRINT TYPES PASSWORD ONLY IN "VERBOSE" MODE

;1.47
;1.46
; MAINTENANCE CAPABILITY ADDED TO PRINT AND CREATE

PRINTX Entering X4CMD


;X4CMD.MAC -
;  Privileged commands (preceeded with ^E):
;    CREATE, PRINT
;    
;    
;    
;    
;    
;    
;    

;^E PRINT (NAME) <DIRECTORY NAME> [VERBOSE]

;PRINTS ALL OF THE CHARACTERISTICS ASSOCIATED WITH A DIRECTORY:
; PASSWORD, PRIVILEGES, MODE, SPECIAL RESOURCE INFO, DIRECTORY NUMBER,
;     DEFAULT FILE PROT, DIREC PROT, FILE RETENTION SPECS,
;     DIRECTORY & USER GROUPS.
;ADD'L KEYWORD "VERBOSE" OR SUBCOMMAND "VERBOSE" CAUSES ALL TO
;BE PRINTED, OTHERWISE ONLY NON-DEFAULT FIELDS.

.PRINT:	NOISE (name)
	CALL DIRNAM		;INPUT DIRECTORY NAME, GET # AND BITS IN A
	ALLOW TALT+TSPC+TEOL+TCOM
	ALTYPE ( )
	CALL SPRTR		;ANALYZE & CHECK TERMINATOR
	 JRST [		;R1: MORE ARG: ALLOW "PRINT NAME VERBOSE"
		KEYWD $PRINT
		 0		;NULL CAN'T GET HERE
		 JRST CERR##
		CALL (KWV)
		JRST .+2]
	 TLO Z,F1		;R2: COMMA, SAY GET SUBCOMMANDS
		;R3: END OF COMMAND
	CONFIRM
	PUSH P,A		;SAVE USER # THRU SUBCOMMANDS
	TLNE Z,F1
	SUBCOM $PRINT		;INPUT SUBCOMMANDS
	POP P,A
	MOVEI A,(A)		;MASK USER #
	MOVEI B,1(P)		;BLOCK WILL BE IN PUSHDOWN
	HRRO C,CSBUFP		;PUT PASSWORD IN STRING STORAGE AREA
	MOVEI D,20		;ALLOCATE 20-WORD BLOCK IN PD (INCLUDES SPARE
	PUSH P,[0]		;...WORDS, BECAUSE ADDITIONS ARE LIKELY)
	SOJG D,.-1
	GTDIR		;GET ALL THE INFO INTO THAT BLOCK
	MOVEI E,(B)		;BLOCK LOCATION
	PUSH P,[CMDIN4]		;SET RETURN FOR "DIRPNT" & FALL IN

;DIRPNT
;PRINT DIRECTORY DESCRIPTION FROM GTDIR-FORMAT BLOCK THAT E POINTS TO.
;OMITS DEFAULT VALUES UNLESS BIT F3 IN LH Z IS ON.
;FOR "PRINT" COMMAND AND FOR "LIST" SUBCOMMAND OF "CREATE".
;CLOBBERS B.

DIRPNT:	SKIPN A,(E)		;NAME IS NOT IN BLOCK FOR "PRINT".
	JRST PR1
	TYPE < Name >
	CALL CTYPE		;NAME FOR "CREATE" CASE
	PRINT EOL
PR1:	SKIPN A,1(E)
	JRST [	TLNE Z,F3
		UTYPE [ASCIZ / No password
/]
		JRST PR2]
	TLNN Z,F3		;DON'T PRINT PASSWORD IF NOT VERBOSE
	JRST PR2
	LDB	B,[POINT 6,A,11];GET BYTE SIZE OF PASSWORD
	CAIN	B,^D36		;HASHED PASSWORD?
	JRST	PR2		;YES, CANNOT BE PRINTED
	TYPE < Password >
	CALL CTYPE
	PRINT EOL
PR2:	MOVE B,2(E)		;DISK LIMIT
	TLNN Z,F3
	CAIE B,750		;DEFAULT VALUE
	ETYPE < Disk limit %2Q
>
;PRIVILEGES
	MOVE B,3(E)
	TRNN B,1B18
	CALL F3NOT
	TRZE B,1B18
	TYPE < Wheel
>
	TRNN B,1B19
	CALL F3NOT
	TRZE B,1B19
	TYPE < Operator
>
	TRNN B,1B20
	CALL F3NOT
	TRZE B,1B20
	TYPE < Confidential information access
>
	TRNN B,1B21
	CALL F3NOT
	TRZE B,1B21
	TYPE < Maintenance
>
	TRNN B,1B22
	CALL F3NOT
	TRZE B,1B22
	TYPE < Netwizard
>
	TRNN	B,1B23
	CALL	F3NOT
	TRZE	B,1B23
	TYPE < Absolute socket
>
IAC <	TRNN	B,1B30
	CALL	F3NOT
	TRZE	B,1B30
	TYPE	< Tenex Development
>
	TRNN	B,1B32
	CALL	F3NOT
	TRZE	B,1B32
	TYPE	< Diagnostician
>
	TRZE	B,1B31
	TYPE	< ACL-only
>
> ; END IAC CONDITIONAL
	TLNN Z,F3
	JUMPE B,.+2		;NO MORE PRIVILEGES
	ETYPE < Other privilege bits %2O
>

;DIRPNT...
;MODE
	MOVE B,4(E)
	TLNN B,B0
	CALL F3NOT
	TLZE B,B0
	TYPE < Files only
>
	TLNN B,B1
	CALL F3NOT
	TLZE B,B1
	TYPE < Alphanumeric accounts
>
	TLNN B,B2
	CALL F3NOT
	TLZE B,B2
	TYPE < Repeat login messages
>
	TLNN Z,F3
	JUMPE B,.+2		;TEST FOR ADDITIONAL MODE BITS
	ETYPE < Other mode bits %2O
>

	SKIPN B,5(E)
	TLNE Z,F3
	ETYPE < Special resource information %2O
>
	SKIPN B,6(E)
	JRST [	TLNE Z,F3
		UTYPE [ASCIZ / No directory number
/]		;0: NOT ASSIGNED YET ("CREATE" CASE)
		JRST .+2]
	ETYPE < Directory number %2O
>
	SKIPN B,7(E)
	 JRST [	TLNE Z,F3
		 TYPE < Default file protection: System default
>
		JRST DIRP10]
	ETYPE < Default file protection: %2O
>


DIRP10:	SKIPN B,10(E)
	 JRST [	TLNE Z,F3
		 TYPE < Directory protection: System default
>
		JRST DIRP11]
	ETYPE < Directory protection: %2O
>

;DIRPNT...
DIRP11:	LDB B,[POINT 4,11(E),35]	;DEFAULT # VERSIONS TO KEEP
	TLNN Z,F3
	CAIE B,2		;2 IS DEFAULT
	ETYPE < Default # file versions to keep %2Q
>
	MOVE B,11(E)
	TRZ B,17		;MASK OFF DEFAULT # VERSIONS
	TLNN Z,F3
	CAME B,[5B2]		;SEEMS TO BE NORMAL VALUE 11/11/70
	ETYPE < Other file retention specifications %2O
>
	SKIPN A,12(E)
	JRST [	TLNE Z,F3
		UTYPE [ASCIZ / Never logged in
/]		;CAN'T USE REG CASE CAUSE %D TYPES CURRENT
		;DATE FOR 0
		JRST .+2]
	ETYPE < Last login %1D %1E
>
	SKIPN A,13(E)
	TLNE Z,F3
	ETYPE < User groups %1U
>
	SKIPN A,14(E)
	TLNE Z,F3
	ETYPE < Directory groups %1U
>
	PRINT EOL
	RET

;SUBROUTINE TO TYPE " NOT" AND SKIP IF F3 ON

F3NOT:	TLNN Z,F3
	RET
	TYPE < not>
	JRST [	AOS (P)
		RET]

;"PRINT" SUBCOMMAND TABLE AND ROUTINES

$PRINT:	TABLE
	T VERBOSE,,ONEWD,..VERB
	TEND

..VERB:	TLO Z,F3
	RET

;^E CREATE (NAME) <DIRECTORY NAME> (PASSWORD) --
;EITHER FIELD CAN BE TERMINATED WITH COMMA TO INITIATE SUBCOMMANDS.
;CAN CREATE NEW DIRECTORIES OR MODIFY INFO ASSOCIATED WITH OLD ONES.
;E HOLDS FLAGS AND BLOCK POINTER WHICH WILL BE IN B FOR CRDIR.
;BLOCK IS IN PUSHDOWN.
;FLAGS IN LH E ARE SET ONLY FOR FIELDS EXPLICITLY INPUT BY USER,
;  BUT ALL INFO IS IN BLOCK FOR "LIST" SUBCOMMAND.

.CREAT:	NOISE (name)
	MOVEI E,1(P)		;RH E POINTS TO...
;ALLOCATE CRDIR PARAMETER BLOCK IN PUSHDOWN.
;INITIALIZE MOST WORDS TO THE SYSTEM DEFAULT VALUES SO THAT IN THE
;NEW NAME CASE THE SUBCOMMAND "LIST" WON'T PRINT IF THE VALUE
;HASN'T BEEN EXPLICITLY SPECIFIED.
	PUSH P,[0]
	PUSH P,[0]
NOIAC <	PUSH P,[750]		;DISK LIMIT >
IAC <	PUSH	P,[^D50]	; DEFAULT DISK LIMIT AT I4-TENEX >

	PUSH P,[0]
	PUSH P,[0]
	PUSH P,[0]
	PUSH P,[0]
	PUSH P,[0]		;DEFAULT FILE PROTECTION
	PUSH P,[0]		;DIRECTORY PROTECTION
	PUSH P,[500000000002]		;FILE RETENTION SPECS
	PUSH P,[0]		;DATE AND TIME OF LAST LOGIN
	PUSH P,[0]		;USER GROUP BITS
	PUSH P,[0]		;DIRECTORY GROUP BITS
	PUSH P,[0]
	PUSH P,[0]		;EXTRAS, BECAUSE ADDITIONS ARE LIKELY
	PUSH P,[0]
	PUSH P,[0]

;CREATE...
;INPUT NAME AND TYPE [OLD/NEW] AND GET CURRENT INFO FOR OLD.
	TLO Z,PUNCF
	CALL CSTR
	ALLOW TCOM+TALT+TSPC
	CALL BUFFF
	ALTYPE ( )
	PUSH P,A		;PTR TO NAME TEXT FOR USE IN AC1 FOR CRDIR
	MOVE B,A
	SETZ A,
	STDIR
	 JRST [	U$TYPE [ASCIZ /[New] /]
		TLO Z,F2		;LOCAL FLAG FOR "NEW NAME"
		JRST CRET1A]
	 CALL SCREWUP
	PUSH P,A		;SAVE FOR LATER
	$TYPE <[Old] >;
	POP P,A			;GET DIRECTORY NUMBER
	HRRZS A			;FLUSH LH BITS
	MOVE B,E
	MOVE C,CSBUFP
	GTDIR			;GET CURRENT INFO FOR OLD DIR
	IBP C
	MOVEM C,CSBUFP
		;AT THE END OF THE NAME FIELD COMMA MEANS "GO DIRECTLY
		;TO SUBCOMMAND INPUT".
		;BUT WE CAN'T CALL "SPRTR" HERE BECAUSE IT MIGHT READ AHEAD,
		;WHICH IS BAD BECAUSE A NOISE WORD FOLLOWS.
CRET1A:	TRNE CBT,TCOM
	JRST CRSUB
	TRNE CBT,TEOL		;EOL ENDS COMMAND, DON'T INPUT PASSWORD.
	JRST CREAT8		;(ERROR IF NEW, NOP IF OLD, BUT ANYWAY...)

;CREATE...
;INPUT PASSWORD.
;FOR OLD DIRECTORY, THIS PASSWORD REPLACES OLD ONE - IS THAT GOOD?
	NOISE (password)
	TLO Z,PUNCF
	CALL CSTR
	ALTYPE ( )
	CALL BUFFF
	CAIG CNT,1
	JRST CREAT3		;NULL INPUT MEANS "NO CHANGE"
		;CAIN CNT,2
		;JRST [	MOVE B,.BFP		;1 CHAR INPUT, IS IT "-" ?
		;	ILDB B,B
		;	CAIN B,"-"	;JUST "-" MEANS MAKE IT NULL.
		;	MOVE A,[POINT 7,[ASCIZ //],-1]
		;	JRST .+1]
	MOVEM A,1(E)		;PASSWD STRING PTR TO PARAMETER BLOCK
	TLO E,B1		;TELL CRDIR TO SET PASSWORD
CREAT3:	CALL SPRTR		;TEST TERMINATING CHARACTER(S)
	 JRST CERR##		; R1: MORE ARGS ON THIS LINE. ERROR.
	 JRST CRSUB		; B2: COMMA, GET SUBCOMMANDS.
		; R3: END OF COMMAND.
;CHECK, CONFIRM, EXECUTE

CREAT8:	TLZA Z,F1
CREAT9:	TLO Z,F1
	TLNE Z,F2		;NEW NAME
	TLNE E,B1		;PASSWORD SPECIFIED?
	JRST CRET9A
	MOVE A,4(E)
	TLNN A,B0
	ERROR < Password required for new name unless files-only>
CRET9A:		;CHECK FOR GIVING PRIVILEGES TO FILES-ONLY DIRECTORY & WARN?
	CONFIRM
	POP P,A		;POINTER TO NAME STRING
	TLNE Z,F2
	TLOE E,B0
	JRST .+2
	MOVEM A,(E)		;SUPPLY NAME IF NEW & NOT GIVEN WITH SUBCOMMAND
	MOVE B,E		;XWD FLAGS, PARAMETER BLOCK ADDRESS
	CRDIR		;CREATE DIRECTORY !
	 CALL JERR##
	TLNN Z,F2		;NEW DIRECTORY, OR
	TLNE E,(1B16)		;KILL EXISTING DIRECTORY?
	CAIA
	 JRST CRET9X
	SKIPL 4(E)		;YES. SKIP IF FILES ONLY
	 JRST [	TYPE < [Don't forget to update user-account data]>
		JRST CRET9X]
	MOVSI A,(1B2!1B17)	;OLD, SHORT, STRING
	HRROI B,[ASCIZ /<SYSTEM>ARCHIVE-FILES-ONLY.TXT/]
	GTJFN			;TEST IF IT EXISTS
	 JRST CRET9X		;NO. SKIP MESSAGE
	RLJFN
	 JFCL
	TYPE < [Don't forget to update <SYSTEM>ARCHIVE-FILES-ONLY.TXT]>
CRET9X:	JRST CMDIN4

;CREATE...
;SUBCOMMAND LOOP

CRSUB:	CONFIRM
	SUBCOM $CREAT		;INPUT AND DISPATCH ON SUBCOMMANDS
	TLO KWV1,CONFRC		;FORCE CONFIRMATION
		;NOTE: CONFRC CAN'T BE USED IN NON-SUBCOMMAND CASE
		;BECAUSE SPRTR CAN READ CONFIRMING CHARACTER BEFORE "CONF"
		;GETS ITS CHANCE TO TYPE "[CONFIRM:]".
	JRST CREAT9

;CREATE...
;SUBCOMMAND DISPATCH TABLE
;FLAG B5 INDICATES "NOT" MAY PRECEDE THE SUBCOMMAND.

$CREAT:	TABLE
	TE ABORT,,ONEWD
	TE ABSOLUTE,,B5+LPROK,..ABSO
	TE ALPHANUMERIC,,B5+LPROK,..ALPH
	TE CONFIDENTIAL,,B5+LPROK
	T DEFAULT
	T DIRECTORY,,B5+LPROK,...DIR
	T DISK,,LPROK,..DISK
	TE FILES,,B5+LPROK
	TE KILL,,B5+LPROK+CONMAN
	TE LIST,,,..LIST
	TE MAINTENANCE,,B5,.MAINT
	T MODE,,B5
	T NAME
	TE NETWIZARD,,B5,.NETWI
	T NO,,,....NO
	T NOT,,,..NOT
	T NUMBER,,,...NUM
	TE OPERATOR,,B5
	T PASSWORD
	T PRIVILEGES,,B5
	T PROTECTION,,LPROK,...PRO
	TE REPEAT,,B5+LPROK
	T RETENTION,,B5+LPROK
	T SPECIAL,,B5+LPROK
	T USER,,B5+LPROK,.USER
	TE WHEEL,,B5
	TEND


....NO:	KEYWD $$$$NO
	 0			;NO DEFAULT
	 JRST CERR##
	JRST 0(KWV)

$$$$NO:	TABLE
	TE MAILBOX
	TEND

.MAILB:	ALLOW TSPC+TALT+TEOL
	CONFIRM
	TLO E,(1B15)		;"NO MSG FILE" FOR CRDIR
	RET

;CREATE...
;"NOT" CAN PRECEDE THOSE SUBCOMMANDS WHICH HAVE B5 SET IN TABLE.
;DISPATCH IS TO SAME ROUTINE BUT WITH "F1" SET TO REVERSE EFFECT.

..NOT:	KEYWD $CREAT
	 0
	 JRST CERR##
	TLNN KWV,B5
	 JRST CERR##
	MOVE KWV1,KWV
	TLO Z,F1
	JRST (KWV)

;ROUTINES FOR THE INDIVIDUAL SUBCOMMANDS

;NAME <NAME>. FOR CHANGING A DIRECTORY'S NAME.

.NAME:	TLO Z,PUNCF
	CALL CSTR
	CALL BUFFF
	ALLOW TALT+TSPC+TEOL
	CONFIRM
	JRST NIYE		;NOT IMPLEMENTED AS OF 6/28/70 __________
	MOVEM A,(E)
	TLO E,B0
	RET

;PASSWORD
;CURRENTLY REDUNDANT EXCEPT THAT IT ALLOWS TYPIN IN A FORMAT MORE LIKE
; WHAT "PRINT" PUTS OUT AND ALLOWS GIVING A NULL STRING (USEFUL?).
;LATER I CLAIM PASSWORD FOR OLD DIRECTORY SHOULD BE TESTED FOR
; ACCESS PERMISSION BY NON-WHEELS (AND BE IGNORED FOR WHEELS), AND THIS
; COMMAND BE USED TO CHANGE PASSWORD. ____

.PASSW:	TLO Z,PUNCF
	CALL CSTR
	CALL BUFFF
	ALLOW TALT+TSPC+TEOL
	CONFIRM
	MOVEM A,1(E)
	TLO E,B1
	RET


;"CREATE" SUBCOMMANDS...

;DISK (STORAGE LIMIT) <DECIMAL>

..DISK:	NOISE (storage limit)
	CALL DECIN		;DECIMAL INPUT TO A
	 JRST CERR##		;NULL
	ALLOW TALT+TEOL+TSPC
	CONFIRM
	MOVEM A,2(E)
	TLO E,B2
	RET

;SUBCOMMANDS FOR SPECIFIC PRIVILEGES AND MODES.
;F1 ON AT ENTRY IF PRECEDED BY "NOT".

;AC USE: A: MASK INDICATING BITS TO SET (F1 OFF), OR CLEAR (F1 ON).

..ABSO:	NOISE (socket capability)
	MOVEI	A,1B23
	JRST	CPRIV
.NETWI:	SKIPA 1,[1B22]
.MAINT:	MOVEI A,1B21
	JRST CPRIV
.WHEEL:	SKIPA A,[1B18]
.OPERA:	MOVEI A,1B19
	JRST CPRIV

.CONFI:	NOISE (information access)
	MOVEI A,1B20
CPRIV:	CONFIRM
	IORM A,3(E)		;SET BITS IN QUESTION
	TLNE Z,F1		;BUT IF SUBCOMMAND PRECEDED BY "NOT",
	ANDCAM A,3(E)		;CLEAR THE BITS.
	TLO E,B3
	RET

.FILES:	NOISE (only)
	HRLZI A,B0
	JRST CCMODE

..ALPH:	NOISE (accounts)
	HRLZI A,B1
	JRST CCMODE

.REPEA:	NOISE (login messages)
	HRLZI A,B2
CCMODE:	CONFIRM
	IORM A,4(E)		;SET BIT
	TLNE Z,F1		;PRECEDED BY "NOT"?
	ANDCAM A,4(E)		;YES, CLEAR BIT.
	TLO E,B4
	RET

;"CREATE" SUBCOMMANDS...

;COMMANDS TO ENTER PRIVILEGES AND MODES IN OCTAL.
;THESE ALLOW ENTERING VALUES WHICH WEREN'T DEFINED WHEN THE CODE FOR
; "CREATE" WAS LAST UPDATED.
;CAN BE PRECEDED BY "NOT" TO TURN OFF RATHER THAN TURN ON THE GIVEN
; BITS.

.PRIVI:	CALL OCTCOM		;36-BIT OCTAL INPUT, LH,,RH ETC ACCEPTED.
	 JRST CERR##
		;ALLOW TALT+TEOL+TSPC	;"OCTCOM" CHECKS TERMINATOR
	JRST CPRIV

.MODE:	CALL OCTCOM
	 JRST CERR##
		;ALLOW TALT+TEOL+TSPC
	JRST CCMODE

;SPECIAL (RESOURCES INFORMATION) <OCTAL>. IRRELEVANT AT PRESENT.

.SPECI:	NOISE (resources information)
	CALL OCTCOM
	 JRST CERR##
		;ALLOW TALT+TSPC+TEOL
CSPEC:	CONFIRM		;FUTURE SUBCOMMANDS FOR INDIV BITS CAN COME HERE
	IORM A,5(E)
	TLNE Z,F1
	ANDCAM A,5(E)
	TLO E,B5
	RET

;NUMBER <OCTAL>. SPECIFIES DIRECTORY NUMBER

...NUM:	CALL OCTAL
	 JRST CERR##
	ALLOW TALT+TSPC+TEOL
	TLNN Z,F2
	JRST [	CAME A,6(E)
	 UERR [ASCIZ / You can't change the number of an old directory/]
		JRST NUMBE1]
;CHECK THAT THE NUMBER ISN'T IN USE BY TRYING TO CONVERT IT TO STRING.
	MOVE B,A
	MOVE A,CSBUFP
	DIRST
	SKIPA A,B		;NOT IN USE
	ERROR <Number already in use>
NUMBE1:	CONFIRM
	MOVEM A,6(E)
	TLO E,B6
	RET

;"CREATE" SUBCOMMANDS...

;PROTECTION (OF DIRECTORY) <OCTAL>. LATER ALSO ALLOW NAMED PROT?

...PRO:	NOISE (of directory)
	CALL OCTCOM		;OCTAL INPUT SUBR, ACCEPTS LH,,RH ETC.
	 JRST CERR##
		;ALLOW TALT+TSPC+TEOL
	CONFIRM
	MOVEM A,10(E)
	TLO E,B8
	RET

;DEFAULT (FILE) PROTECTION <OCTAL>
;		NUMBER (OF VERSIONS TO KEEP) <DECIMAL>

.DEFAU:	NOISE (file)
	KEYWD $DEFAU
	 0
	 JRST CERR##
	JRST (KWV)

$DEFAU:	TABLE
	T NUMBER,,LPROK,..NUMB
	T PROTECTION,,,....PR
	TEND

....PR:	CALL OCTCOM		;36-BIT OCTAL. OK? _______
	 JRST CERR##
		;ALLOW TALT+TSPC+TEOL
	CONFIRM
	MOVEM A,7(E)
	TLO E,B7
	RET

..NUMB:	NOISE (of versions to keep)
	CALL DECIN
	 JRST CERR##
	CAIL A,0
	CAILE A,15
	ERROR <Must be 0-13>
	ALLOW TALT+TSPC+TEOL
	CONFIRM
	DPB A,[POINT 4,11(E),35]
	TLO E,B9
	RET

;"CREATE" SUBCOMMANDS...
;[NOT] RETENTION (SPECIFICATIONS) <OCTAL>
;OR'S IN AND AND'S OUT, APPROPRIATE FOR BITS ONLY.

.RETEN:	NOISE (specifications)
	CALL OCTCOM
	 JRST CERR##
	CONFIRM
	IORM A,11(E)
	TLNE Z,F1
	ANDCAM A,11(E)
	TLO E,B9
	RET

;[NOT] USER (GROUP) <DECIMAL BIT NUMBER>
;F1 ON IF PRECEDED BY "NOT"

.USER:	NOISE (group)
	CALL BITIN		;INPUT BIT NUMBER
	CONFIRM
	IORM A,13(E)
	TLNE Z,F1
	ANDCAM A,13(E)
	TLO E,B11
	RET

;[NOT] DIRECTORY (GROUP) <DECIMAL BIT NUMBER>

...DIR:	NOISE (group)
	CALL BITIN
	CONFIRM
	IORM A,14(E)
	TLNE Z,F1
	ANDCAM A,14(E)
	TLO E,B12
	RET

;SUBROUTINE TO INPUT DECIMAL BIT NUMBER. RETURNS BIT SET IN A.
;FOR USER AND DIRECTORY GROUP SUBCOMMANDS

BITIN:	INHELP <DECIMAL NUMBER 0-35>
	TLO Z,BAKFF
	CALL DECIN
	 JRST CERR##
	CAILE A,^D35
	 JRST CERR##
	MOVN B,A
	HRLZI A,B0
	LSH A,(B)
	RET

;"CREATE" SUBCOMMANDS...

;KILL (THIS DIRECTORY)

.KILL:	NOISE (this directory)
	CONFIRM
	TLO E,B16
	TLNE Z,F1
	TLZ E,B16		;"NOT KILL" REVERSES EFFECT.
	RET

;ABORT: ABORT THIS CREATE. REDUNDANT FOR ^C.

.ABORT:	MOVEI A,RERET
	MOVEM A,CERET
	JRST CMDIN4		;GO GET NEXT EXEC COMMAND

;LIST. PRINTS WHAT "PRINT" WILL PRINT IF THIS "CREATE" IS COMPLETED.
;"LIST VERBOSE" PRINTS AS "PRINT" WITH VERBOSE SUBCOMMAND

..LIST:	KEYWD $.LIST
	 T <>,,EOLOK,0
	 JRST CERR##
	TLZ Z,F3
	CONFIRM
	TRNE KWV,F3
	TLO Z,F3
	TLNN E,B17
	JRST DIRPNT		;GO ACT LIKE "PRINT" COMMAND
	TYPE < killed
>
	RET

$.LIST:	TABLE
	T VERBOSE,,EOLOK,F3
	TEND

;^E CYCLE (THE NETWORK)

.CYCLE:	NOISE (the network)
	CONFIRM
	MOVE A,['IMPDRQ']
	MOVEI B,1
	OPRFN
	 JRST NIYE
	RET



;^E DISK (PANIC LEVEL FOR) SYSTEM/USERS (IS) <NUMBER OF PAGES>

...DSK:	NOISE (panic level for)
	KEYWD $$$DSK
	 0
	 JRST CERR##
	MOVE A,['USRSPC']	;VALUE IS 0 FOR SYSTEM, 1 FOR USERS
	TRNN KWV,-1
	MOVE A,['SYSSPC']
	PUSH P,A
	NOISE (is)
	CALL DECIN		;INPUT A DECIMAL NUMBER
	 JRST CERR##		;NULL INPUT
	SKIPL A		;MAKE SURE IT IS REASONABLE
	CAILE A,^D2000
	 ERROR <Unreasonable limit>
	PUSH P,A
	ALLOW TSPC+TALT+TEOL
	ALTYPE ( )
	CONFIRM
	POP P,B			;THE NUMBER
	POP P,A			;THE CELL NAME
	OPRFN
	 JRST NIYE		;COME ON CLEMENTS
	RET

$$$DSK:	TABLE
	T SYSTEM,WHEEL+OPER,LPROK,0
	T USER,WHEEL+OPER,LPROK,1
	TEND

;^E EDDT
;TRANSFER CONTROL TO TENEX DDT, GETTING IT IF IT ISN'T ALREADY THERE.

.EDDT:	SKIPE DDTORG
	 JRST EDDT2		;DDT ALREADY THERE
	MOVE B,[POINT 7,[ASCIZ /<SUBSYS>UDDT.SAV/],-1]
	CALL $GTJFN		;ENTRY TO "$LPT" SUBR NEAR "DIRECTORY"
	HRLI A,.FHSLF		;SAY THIS FORK (JFN IS IN RH A)
	GET
	CALL RLJFNS##
	MOVEI A,.FHSLF
	MOVE B,[EVECL,,MFEXEC]	;ENTRY VECTOR
	SEVEC			;MAKE EV POINT AT EXEC, NOT DDT

;If we can find MFEXEC.SYMBOLS, read it into core for DDT..
EDDT2:	HRROI B,MFSYM
	CALL TRYGTJ		;Look for symbols
	 JRST EDDT4		; oh dear..
	MOVE B,[44B5+1B19]	;Take a look
	OPENF
	 CALL JERR##
	BIN			;Defined symbols pointer
	HLRES C,B		;Will want that many
	ADDI B,BPBUF		; before the page buffers..
	ANDI B,777000		; (position to beginning of page)
	HRLI B,(C)		; Give a ptr to DDT
	MOVEM B,@DDTORG+1
	HRLI B,444400
	SKIPGE C
	SIN
	BIN			;Undefined symbols pointer
	JUMPGE B,EDDT3
	HLRE C,B		;We have some, how strange!?
	HRRZ B,@DDTORG+1	;They are put before defined symbols..
	ADD B,C
	ANDI B,777000		; (position to beginning of page)
	HRLI B,(C)		; Give a ptr to DDT
	MOVEM B,@DDTORG+2
	HRLI B,444400
	SIN
EDDT3:	CALL RLJFNS##		;Done with symbols file

;DEASSIGN ^C, SO THAT ^C'S IN DDT WILL GO TO SUPERIOR EXEC.
EDDT4:	CALL INFER		;SKIP IF INFERIOR EXEC
	JRST EDDT5		;AT TOP LEVEL LEAVE ^C ENABLED
	MOVEI A,.FHSLF		;THIS FORK
	RPCAP			;ENABLED CAPS INTO C
	MOVEI A,CTRLC
	TLNE C,B0		;^C SPEC CAP ENABLED?
	DTI			;YES, DEASSIGN ^C
EDDT5:	JRST DDTORG		;ENTER DDT

;DISABLE
;DISABLES PRIVILEGED COMMANDS,
;DISABLES USER (RH) SPEC CAPS IN EXEC AND INFERIOR FORK
; (CAPS POSSIBLE ARE STILL TRANSMITTED, SO INFERIOR CAN USE THEM
; IF IT ENABLES THEM ITSELF)

.DISAB:	SETZM PRVENF		;SAY PRIVILEGED COMMANDS OFF
DISAB1:	MOVEI A,.FHSLF		;"ENABLE" JOINS HERE
	RPCAP
	TRZ C,-1
	SKIPE PRVENF
	HRR C,B
	HRRZ D,C		;SAVE ENABLED CAPS FOR USE W/INFER.
	EPCAP			;EXEC'S CAPABILITIES
	SKIPG A,FORK
	RET			;NO INFERIOR, DONE
	RPCAP
	IOR B,D			;ADD THE SAVED PRIVILEGES
	TRZ C,-1
	SKIPE PRVENF
	HRR C,B
	EPCAP			;INFERIOR'S CAPS
	RET


;ENABLE
;ENABLES OTHER PRIVILEGED COMMANDS IN EXEC, AND ENABLES
;RH (USER) SPECIAL CAPS IN EXEC AND IN INFERIOR FORK, IF THERE IS ONE.

.ENABLE:ALLOW TSPC!TALT!TEOL
	TRNE CBT,TEOL
	JRST [	CONFIRM
		JRST ENABL2]
	HRRZ A,CUSRNO		;THIS USER'S NUMBER
	CALL PASWD		;INPUT PASSWORD
	ALLOW TSPC!TALT!TEOL
	CONFIRM
	MOVE B,A
	ILDB C,A		;GET FIRST CHARACTER OF PASSWD
	JUMPE C,ENABL2		;NO PASSWORD JUST ENABLE
	HRRZ A,CUSRNO
	TLO A,(1B0)		;JUST CHECK PASSWORD
	CNDIR
	 CALL [	CAIN A,CNDIX1
		ERROR <Incorrect password>
		JRST JERR]
ENABL2:	SETOM PRVENF		;ENABLE PRIVILEGED COMMANDS AND CAPS.
	JRST DISAB1

;^E HALT (the system)

..HALT:	CALL SPRTR		;ANALYZE SEPARATOR
	 JRST CERR##		;R1: MORE FOLLOWS
	 TLO Z,F1		;R2: SUBCOMMANDS FOLLOW
	 CONFIRM		;R3: END OF COMMAND
	HRLZ A,CUSRNO		;SET "WHO" DEFAULT TO ME
	MOVEM A,WHYHLT
	MOVEI A,.FHSLF		;THIS FORK
	RPCAP
	TRNN C,WHEEL+OPER	;MAINT ONLY CAN'T ENABLE IN OLD EXEC
	TRNE B,MAINT		;SO MAKE IT COMPATIBLE WITH OLD
	JRST .+2
	 JRST CERR##
	PUSH P,C		;ENABLED CAPS
	PUSH P,B		;POSSIBLE CAPS
	TLNN Z,F1		;SUBCOMMANDS?
	JRST HALT2		;NO.

HALT0:	MOVE 1,['SYSTAT']
	CALL $SYSGT
	JUMPE B,CERR##		;NO SUCH TABLE??
	MOVSI 1,27
	HRR 1,2
	GETAB			;GET ANY CURRENTLY SET DOWN TIME
	 CALL JERR##
	MOVEM 1,DOWNTM		;USE AS DEFAULT
	SKIPE 1
	TYPE < [Note: There is a shutdown already set]>
	MOVSI 1,30
	HRR 1,2
	GETAB
	 CALL JERR##
	MOVEM 1,UPTIME		;DEFAULT UP TIME
	SUBCOM $HALT		;DO SUBCOMMANDS TO MODIFY THESE
	JRST HALT3		;GO MAKE ABSOLUTE

HALT2:	MOVEI 1,5		;NO SUBCOM'S.  DOWN IN 5 MIN.
	MOVEM 1,DOWNTM
	SETZM UPTIME		;WHO KNOWS WHEN IT WILL BE UP AGAIN?


HALT3:	MOVE 1,UPTIME
	IOR 1,DOWNTM
	JUMPE 1,HALT4		;BOTH 0 ==> RETRACT
	SKIPN 2,DOWNTM		;SKIP IF ABSOLUTE OR REL.
	MOVEI 2,5		;NOT SET. DEFAULT TO 5 MIN.
	GTAD			;WHAT TO ADD REL. TO
	TLNE 2,-1		;DOWNTM IS ABS?
	JRST .+3		;YES
	CALL TIMPMN		;ABS IN 1 PLUS MINS IN 2
	MOVEM 1,DOWNTM		;THAT'S THE DOWN TIME

	SKIPE 2,UPTIME		;IF UPTIME IS NOT SET...
	TLNE 2,-1		;OR IS ABSOLUTE,
	 JRST HALT4		;THEN TAKE AS IS.
	MOVE 1,DOWNTM		;OTHERWISE IT IS RELATIVE TO DOWN TIME
	CALL TIMPMN		;TIME IN 1 PLUS MINUTES IN 2
	MOVEM 1,UPTIME

HALT4:	TYPE < [Confirm] >
	CALL TCONF
	 U.$ERR
	NOINT
	MOVEI A,.FHSLF		;THIS FORK
	SETO B,
	POP P,C			;POSSIBLE CAPS
	EPCAP

	MOVE 1,DOWNTM
	MOVE 2,UPTIME
	MOVE 3,WHYHLT		;REASON FOR HALTING
IAC <	HRRZ	4,3
	SKIPN	4		; A REASON GIVEN?
	HRRI	3,15		; NO, SAY UNSPECIFIED
>
	HSYS
	 TLOA Z,F1		;REMEMBER HSYS FAILED
	TLZ Z,F1		;HSYS WAS OK
	MOVEI A,.FHSLF		;THIS FORK
	SETO B,
	POP P,C			;ENABLED AT TIME OF ENTRY
	EPCAP			;RESTORE
	OKINT
	TLNE Z,F1		;DID HSYS FAIL?
	 ERROR <HSYS failed>
	RET			;NO

$HALT:	TABLE
	T AT,,LPROK,..HLTA
	T BY,,LPROK,..HLTB
	T DUE,,LPROK,..HLTD
	T FOR,,LPROK,..HLTF
	T IN,,LPROK,..HLTI
	T RETRACT,,ONEWD,..HLTR
	T TODAY,,LPROK,..HLT0
	T TOMORROW,,LPROK,..HLT1
	T UNTIL,,LPROK,..HLTU
	TEND


..HLTA:	NOISE (date and time)
	CALL DATEIN
	MOVEM A,DOWNTM
	RET


..HLTB:	NOISE (user)
	CALL DEFDIR		;INPUT DIRECTORY NUMBER WITH DEFAULT ME
	ALLOW TALT+TSPC+TEOL
	CONFIRM
	HRLM A,WHYHLT
	RET


..HLTD:	NOISE (to reason)
	KEYWD $HLTDU
	 0
	 JRST CERR##
	ALLOW TALT+TEOL
	ALTYPE ( )
	CONFIRM
	HRRM KWV,WHYHLT
	RET

$HLTDU:	TABLE
	TE EMERGENCY,,,8
IAC <	TE ENVIRONMENTAL-PROBLEMS,,,11 >
NOIAC <	TE HARDWARE,,,6 >
IAC <	TE HARDWARE-FAILURE,,,13
	TE HARDWARE-WORK,,,6 >
	TE PM,,,5
	TE PREVENTIVE-MAINTENANCE,,,5
IAC <	TE SCHEDULED-DOWN,,,14 >
	TE SOFTWARE,,,7
	TEND


..HLTF:	NOISE (number of minutes)
	CALL DECIN
	 JRST CERR##
	JUMPL A,CERR##
	ALLOW TALT+TSPC+TEOL
	CONFIRM
	HRRZM A,UPTIME		;A RELATIVE TIME
	RET


..HLTI:	NOISE (number of minutes)
	CALL DECIN
	 JRST CERR##
	JUMPLE A,CERR##
	ALLOW TALT+TSPC+TEOL
	CONFIRM
	HRRZM A,DOWNTM		;A RELATIVE TIME
	RET


..HLTR:	NOISE (any pending shutdown request)
	SETZM DOWNTM		;NO KNOWN DOWN TIME
	SETZM UPTIME		;OR UPTIME
	SETZM WHYHLT		;OR REASON
	RET

..HLT0:	NOISE (at time)
	JRST NIYE

..HLT1:	NOISE (at time)
	JRST NIYE


..HLTU:	NOISE (date and time)
	CALL DATEIN
	ALLOW TALT!TEOL
	CONFIRM
	MOVEM A,UPTIME
	RET

;ADD THE MINUTES IN 2  TO THE TAD IN 1

TIMPMN::IMULI 2,^D60		;MAKE IT SECONDS


;ADD THE SECONDS IN 2  TO THE TAD IN 1

TIMPSC::ADDI 2,0(1)		;ADD IN SECONDS FROM TAD
	IDIVI 2,^D<60*60*24>	;NUMBER OF SECONDS IN A DAY
	MOVSS 2			;0 FOR TODAY, 1,,0 FOR TOMORROW, ETC
	ADD 1,2			;BUMP DAY
	HRR 1,3			;INSERT SECONDS
	RET

;^E INITIALIZED ACCOUNTS/HOSTS


.INITI:	KEYWD $INITI
	 0
	 JRST CERR##
	MOVE A,(KWV)
	CONFIRM
	OPRFN
	 CALL [	CAIN A,OPRFX1
		JRST NIYE		;FUNCTION NOT DEFINED
	 	JRST JERR##]		;OTHER FAILURE
	RET

$INITI:	TABLE
	TE ACCOUNTS,WHEEL+OPER,,['ACTINI']
	TE HOSTS,WHEEL+OPER,,['HSTINI']
ISI <	TE MAGTAPES,WHEEL+OPER,,['XMTAIN']
	TE MLP,WHEEL+OPER,,['XMLPIN']
>
	TEND

;^E K (FACTOR IS) <FLOATING NUMBER>

.KFACT:	NOISE (factor is)
	CALL FPIN		;INPUT A FLOATING POINT NUMBER
	SKIPL A
	CAMLE A,[1.0]
	 JRST CERR##
	ALLOW TSPC!TALT!TEOL
	CONFIRM
	MOVE B,A
	MOVE A,['KFACT ']
	OPRFN
	 CALL JERR##
	RET




;^E LOAD (EDDT)

.LOAD:	NOISE (EDDT)
	CONFIRM
	MOVE A,['DDTRCL']
	OPRFN
	 CALL JERR##
	RET



;^E NETWORK OFF/ON

.NETWO:	KEYWD $NETWO
	 0
	 JRST CERR##
	CONFIRM
	HRRE B,KWV
	MOVE A,['NETON ']
	OPRFN
	 CALL JERR##
	RET

$NETWO:	TABLE
	TE OFF,,,0
	TE ON,,,-1
	TEND

; ^E OFFLINE (CORE FROM PAGE) ... (THROUGH PAGE) ...
; ^E ONLINE (CORE FROM PAGE) ... (THROUGH PAGE) ...


.OFFLI:	TLZA Z,F1		;REMEMBER WHICH COMMAND
.ONLIN:	TLO Z,F1
	NOISE (core from page)
.ONLI1:	CALL OCTAL
	 JRST [	ALLOW TALT	;NO NUMBER, THINK ABOUT DEFAULT
		TLNN Z,F1	;"OFFLINE" HAS NO DEFAULT
		 JRST [	CALL DING
			JRST .ONLI1]
		MOVEI A,0
		U$TYPE [ASCIZ /0 /]
		JRST .+1]
	ALLOW TSPC+TALT+TLPR
	CAILE A,3777		;MAKE SURE IT'S A GOOD PAGE NUMBER
	 JRST CERR##
	PUSH P,A		;SAVE FOR LATER
	NOISE (through page)
	CALL OCTAL
	 JRST [	ALLOW TALT
		MOVEI A,3777
		U$TYPE [ASCIZ /3777 /]
		JRST .+1]
	ALLOW TSPC+TALT+TEOL
	CAIG A,3777		;CHECK FOR REASONABLE PAGE NUMBER
	CAMGE A,0(P)		;AND ORDER
	 JRST CERR##
	POP P,B			;FIRST PAGE
	MOVE C,A		;LAST PAGE
	CONFIRM
	TLNN Z,F1		;WHICH COMMAND
	SKIPA A,['MKPGSU']	;"OFFLINE"
	MOVE A,['MKPGSA']	;"ONLINE"
	OPRFN
	 CALL JERR##
	RET

;^E PAUSE

..PAUS:	NOISE (at BUGCHKs)
	CONFIRM
	MOVEI B,1
	MOVE A,['DCHKSW']
	OPRFN
	 CALL JERR##
	RET


;^E PERMIT

.PERMI:	NOISE (logins)
	CONFIRM
	MOVE A,['ENTFLG']
	SETO B,
	OPRFN
	 CALL JERR##
	RET


;^E PROCEED

.PROCE:	NOISE (at BUGCHKs)
	CONFIRM
	MOVE A,['DCHKSW']
	SETZ B,
	OPRFN
	 CALL JERR##
	RET


;^E PROHIBIT

.PROHI:	NOISE (logins)
	CONFIRM
	MOVE A,['ENTFLG']
	SETZ B,
	OPRFN
	 CALL JERR##
	RET

;^E SET (DATE AND TIME)

.SET:	NOISE (date and time)


;SUBROUTINE TO INPUT AND SET DATE AND TIME
;FOR MAIN LOOP AND ^E SET COMMAND.

INDT:	CALL DATEIN		;INPUT DATE AND TIME
	PUSH P,1
	CALL CHKDAT		;SKIP IF IT LOOKS OK
	 JRST [	TYPE < Please reconfirm: >
		MOVE 1,COJFN	;PRIMARY OUTPUT JFN
		MOVE 2,0(P)	;DATE TYPED IN
		SETOM 3		;VERBOSE FORMAT
		ODTIM
		TLO KWV1,CONMAN
		CONFIRM
		JRST .+1]
	POP P,A
	STAD			;SET TIME AND DATE
	 CALL [	CAIN A,STADX1	;SPEC CAP NOT ENABLED ERROR?
		RET		;YES. GO QUIETLY AWAY
		JRST JERR##]
	RET


;CHECK TYPED IN TIME TO BESURE IT IS OK FOR STAD
; CURRENTLY THIS MEANS WITHIN 11 HRS. AFTER LAST FACT FILE WRITE

CHKDAT:	PUSH P,1
	NOINT			;BE SURE JFN WILL GET STACKED
	MOVSI 1,(1B2!1B17)
	HRROI 2,[ASCIZ /<ACCOUNTS>FACT./]
	GTJFN
	 JRST [	OKINT		;CAN'T GET JFN, FORCE RECONFIRMATION
		JRST CHKDA9]	;NO-SKIP RETURN
	MOVE 2,JBUFP		;JFN STACK PTR
	PUSH 2,1		;SAVE FOR RELEASE AT ^C OR ERROR
	MOVEM 2,JBUFP
	OKINT
	MOVE 1,0(2)		;GET THE JFN BACK
	MOVE 2,[1,,FDBWRT]
	MOVEI 3,3
	CALL $GTFDB		;DON'T SKIP IF ACCESS LACKING
	 JRST CHKDA8
CHKDA4:	CAML 3,0(P)		;DATE TYPED MUST BE AFTER FILE WRITE
	 JRST CHKDA8		;NOT SO
	MOVE 1,3
	MOVEI 2,^D<11*60*60>	;TIME LIMIT = 11 HRS.
	CALL TIMPSC		;GTAD IN 1 PLUS SECONDS IN 2, TO 1
	CAML 1,0(P)		;11HRS AFTER FILE WRT BEFORE INPUT ?
	 AOS -1(P)		;DATE LOOKS GOOD, SKIP

CHKDA8:	CALL RLJFNS##
CHKDA9:	POP P,1
	RET

;^E SYSTEM (IS) ...

.SYSTE:	NOISE (is)
	KEYWD $SYSTE
	 0
	 JRST CERR##
	CONFIRM
	MOVE A,['DBUGSW']
	MOVEI B,(KWV)
	OPRFN
	 CALL JERR##
	RET

$SYSTE:	TABLE
	TE ATTENDED,,,1
	TE DEBUGGABLE,,,2
	TE UNATTENDED,,,0
	TEND


; ^E TRAPS OFF/ON

.TRAPS:	NOISE (of JSYS's)
	KEYWD $TRAPS
	 0
	 JRST CERR##
	CONFIRM
	MOVE A,['JTRPON']
	HRRE B,KWV
	OPRFN
	 CALL JERR##
	RET

$TRAPS:	TABLE
	TE OFF,,,0
	TE ON,,,-1
	TEND


;^E UNLOAD EDDT

..UNLO:	NOISE (EDDT)
	CONFIRM
	MOVE A,['DDTFSH']
	OPRFN
	 CALL JERR##
	RET


	END MFEXEC
