Google
 

Trailing-Edge - PDP-10 Archives - bb-d549g-sb - login.mac
There are 15 other files named login.mac in the archive. Click here to see a list.
UNIVERSAL LGNUNV - Parameter file for LOGIN version 61(751) - 3-Jun-80

	SUBTTL	Larry Campbell /TW/DJB/DAL/RCC/JSL/DAL/LC/HRB/BAH/WCL/KPY/MSL/WSM

;	LOGIN - The program for gaining access to the
;		DECsystem-10 Timesharing System




;COPYRIGHT (C) 1969, 1974, 1978, 1979, 1980 BY
;DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
;
;
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH LICENSE AND WITH THE
;INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY  OTHER
;COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
;OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE  SOFTWARE  IS  HEREBY
;TRANSFERRED.
;
;THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT  NOTICE
;AND  SHOULD  NOT  BE  CONSTRUED  AS A COMMITMENT BY DIGITAL EQUIPMENT
;CORPORATION.
;
;DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY  OF  ITS
;SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.

IF1, <PRINTX [Searches UUOSYM, MACTEN, SCNMAC, ACTSYM]> 
	SEARCH	UUOSYM,MACTEN,SCNMAC,ACTSYM

IF2, <	PRINTX
	PRINTX [Loads with REL:SCAN, REL:WILD, REL:HELPER, REL:FACTOR]>
	.REQUEST REL:SCAN,REL:WILD,REL:HELPER
	.REQUEST REL:FACTOR

	SALL

	TWOSEG

	LGNVER==61
	LGNMIN==0
	LGNEDT==751
	LGNWHO==0

	LOC	137
	VRSN.	(LGN)

;CONDITIONAL ASSEMBLY SWITCHES

ND SUPNOT,1		;SUPPRESS NOTICE.TXT IF / IN PPN
ND FASTLG,1		;INCLUDE DIRECTORY OF ACCT.SYS IN HI SEG
ND TTYSLP,2		;NO. OF MINS TO SLEEP AWAITING TTY INPUT BEFORE DYING
ND PDLSIZ,60		;DEPTH OF STACK
ND SETTTY,1		;INCLUDE CODE TO SET TTY CHARACTERISTICS
ND DVICES,20		;[470] NUMBER OF DEVICES ASSIGNABLE BY /ASSIGN
ND BATMAX,0		;[505] INCLUDE CODE TO CHECK BATMAX (REQUIRES
			;[505] EDIT 1055 OF BATCON)
ND NCRYPT,0		;[557] PASSWORD ENCRYPTION
ND PSWCHG,0		;[557] ALLOW USER TO CHANGE OWN PASSWORD
ND FTCMPR,1		;[667] ZERO COMPRESS UFDS WHEN RECOMPUTING QUOTA
ND FTUSAG,1		;DO USAGE ACCOUNTING
ND VALDSW,1		;ACCOUNT VALIDATION IS TO BE DONE
ND FACTSW,1		;DO FACT FILE ACCOUNTING (7.01 ONLY)
ND FAILOG,1		;LOG LOGIN/ATTACH FAILURES IN FACT FILE
IFE FTUSAG,<
	VALDSW==0
	FACTSW==0
> ;END OF IFE FTUSAG
IFE FACTSW,<FAILOG==0>	;NO POINT IF NO FACT FILE

IF1,<
DEFINE	LGNDCL,<
	.XCREF
	LALL
;



;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1969, 1974, 1978, 1979, 1980 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
	TWOSEG
	RELOC	400000
	IFNDEF	BIGLST,<SALL>
	LOWVAR
	GLOBS
	.CREF
>>
	SUBTTL	Edit history

;316)	FIX TEST FOR WEEKEND TO PREVENT NON-PRIME-TIME USERS FROM
;	LOGGING IN DURING PRIME TIME (SPRS 10-14,021 AND 10-14,046)

;317)	ENLARGE PARAMETER BLOCK FOR STRUUO SO POINTER TO AUXACC
;	ENTRY (RDHED) DOESN'T GET OVERWRITTEN.
;		SPRS 10-14,219 AND 10-14,083

;320)	MAKE LOGIN PREFIX EACH STR.TXT TYPEOUT WITH THE NAME OF THE
;	FILE STRUCTURE FROM WHICH IT CAME.  SPR 10-14,031

;321)	REALLY IMPLEMENT /HELP	(SPR 10-14,031)

;322)	CHANGE PREFIX FOR WARNING ERROR MESSAGES FROM ? TO %
;	TO PREVENT BATCH JOBS FROM FLUSHING.
;		SPRS 10-14,145 AND 10-14,172.

;323)	FIX SECURITY BREACH WHERE BOTH NAME AND PSWD ARE REQUIRED AND
;	NEITHER IS ASKED FOR.	SPR 10-14,306.

;324)	PUT IN TEST SO SETUUO IS SKIPPED IF NO BITS WANT TO BE SET.
;		SPR 10-14190.

;325)	FIX ?LGNIPS IF NO SPACE BETWEEN PPN AND SWITCHES.
;		SPR 10-14,031


;326)	MOVE MISPLACED CLOSE CONDITIONAL	(SPR 10-14,244)

;327)	MAKE LOGIN LOOK AT PHYSICAL CORE LIMIT EVEN IN KA MONITORS.
;		SPR 10-14,264.

;330)	ALLOW PPN TO BE ENCLOSED IN SQUARE BRACKETS ON LOGIN.

;331)	REMOVE ALL REFERENCES TO FL.BRK -- OBSOLETE BATCH HACK.
;		SPR 10-14,021.

;332)	IMPLEMENT /NOWATCH	SPR 10-14,145

;333)	FIX EDITS 221 AND 226 SO LOGIN REALLY WON'T PRINT NOTICE.TXT
;	TO AN OPSER SUBJOB.

;334)	MAKE LOGIN SLEEP BETWEEN RETRIES AFTER BAD PASSWORDS ONLY
;	ONLY ON PTY'S.  SPR 10-14,021.

;335)	CLEAR TMPCOR AT BEGINNING OF FLOW RATHER THAN END
;		SO /TMPCOR SWITCH WORKS.

;336)	FIX EDIT 332, WHICH ONLY DID HALF THE JOB.

;337)	FIX EDIT 333, WHICH COMPLETELY MADE NOTICE.TXT GO AWAY, OPSER
;		SUBJOB OR NOT!
;340)	MAKE ISOPSR ONLY LOOK AT IMMEDIATELY CONTROLLING JOB SO
;		NOTICE.TXT WILL GET PRINTED FOR BATCH JOBS.

;341)	ANOTHER FIX TO THE INFAMOUS EDIT 333, WHICH SOMETIMES
;		TURNED THE TTY INTO A LOCAL COPY TERMINAL
;		(SUPER NO-ECHO).

;342)	WHEN SETTING UP TEMP SEARCH LIST TO READ SWITCH.INI, ONLY LOOK
;		AT STRS WHOSE NAMES BEGIN WITH DSK (DSKA, DSKB, ETC.).

;343)	EXIT ON ^Z.

;344)	IMPLEMENT SWITCHES TO SET TERMINAL CHARACTERISTICS.

;345)	FIX TO EDIT 344 WHERE JOBS WHICH DIDN'T NEED PASSWORDS
;		DIDN'T GET TTY CHARACTERISTICS SET.

;346)	WHEN SETTING UP TO READ SWITCH.INI, ENABLE SYS (IN CASE
;		OF SYSTEMS WITH FUNNY-NAMED FILE STRUCTURES).

;347)	PRINT NOTICE.TXT AND /NOTE:FILE EVEN IF CAN'T LOG IN
;		(SYS NOT AVAILABLE, BATCH ONLY, ETC.)


;350)	MAKE LOGIN GET NAME IF REQUIRED ON ATTACH
;		(SPR 10-14,593)

;351)	MISCELLANEOUS CODE CLEANUP AND SPEEDUP.

;352)	ADD CODE TO SET ENQ/DEQ QUOTAS.

;353)	MAKE SURE RP.LOG GETS SET WHEN RECOMPUTING DISK USAGE.

;354)	ADD "SYSTEM IS UNATTENDED" MESSAGE

;355)	MAKE /NAME LOGIC WORK RIGHT.

;356)	ADD CHECK FOR ACCT.SYS FORMAT VERSION 4 AND DON'T
;		SET ENQ/DEQ QUOTAS IF NOT VERSION 4.

;357)	MISCELLANEOUS CODE CLEANUP ON SUGGESTIONS BY DAL.

;360)	MORE CODE CLEANUP.

;361)	IF DEVPPN ON SYS FAILS, WE USE GARBAGE.  LET'S USE [1,4].

;362)	MAKE /NOTE PRINT OUT BEFORE NOTICE.TXT.

;363)	DO ALL NON-PRIV. SETUUO'S AFTER PRINTING NOTICES.  THIS IS SO
;		THE TRMOP.'S (LIKE SPEED) WON'T SCREW UP PRINTING NOTES.

;364)	DON'T SETUUO THE SPOOL BITS IF SYSTEM DOESN'T HAVE SPOOLING.

;365)	ADD /DEFER AND /NODEFER SWITCHES, AND PREVENT /SPOOL:ALL FROM
;		SETTING BIT FOR DEFERRED SPOOLING.
;366)	FIX BUG INTRODUCED BY EDIT 324 WHERE /DSKFUL:PAUSE NO LONGER
;		WORKS.

;367)	ADD CODE TO SLEEP UNTIL OUTPUT BUFFER EMPTY BEFORE DOING
;		TRMOP.S WHICH MIGHT GARBLE TTY OUTPUT.

;370)	REMOVE ALL REFERENCES TO DATE75 CONDITIONAL

;371)	CODE CLEANUP.

;372)	MAKE LGNUNV INTO A SEPARATE (UNIVERSAL) FILE TO SPEED ASSEMBLY.

;373)	ADD ERROR MESSAGE IN CASE SETUUO FOR DEFER BIT FAILS.

;374)	CHECK ST%GAL (GALAXY) BIT IN 2ND STATES WORD AND DON'T TRY
;	TO SET DEFER BIT IF ZERO.

;375)	IMPROVE ERROR MESSAGE IF TRMOP. FAILS TO TELL FUNCTION CODE.

;376)	IF USER TYPES BAD PATH OR PSWD AND RETRIES, HIS PATH
;	IS SCREWED UP.  FIX: CLEAR PATH BLOCK EACH TIME AROUND.

;377)	DON'T DOUBLE-SPACE /NOTE OR /STR TYPEOUT

;400)	ADD FTINHOUSE CONDITIONAL AND ENCLOSE IN IT THE CODE
;	WHICH WILL ONLY ALLOW FILE STRUCTURES WHOSE NAMES BEGIN WITH
;	'DSK' TO GO INTO YOUR SEARCH LIST WHEN READING SWITCH.INI.
;	THIS CODE FIXES THE BUG IN WHICH SWITCH.INI WAS NOT READ
;	IF 7 OR 8 PRIVATE PACKS PRECEDE THE PUBLIC PACKS IN THE
;	RETURNS FROM SYSSTR.  SINCE THIS IS ONLY A PROBLEM IN
;	SYSTEMS WITH 9 OR MORE FILE STRUCTURES, THE CODE WILL BE
;	CONDITIONED OUT IN FIELD-IMAGE.

;401)	PREVENT /MESSAGE:ALL FROM TURNING ON RANDOM WATCH BITS

;402)	RANDOM CODE CLEANUP -- ALSO REMOVE CODE FOR ENQ/DEQ SO IT
;	CAN BE PUT INTO V57 ALONG WITH SCHED. STUFF IN
;	ONE FELL SWOOP

;403)	IMPROVE LOGIC FOR READING AUXACC.SYS

;404)	(SIGH) FIX EDIT 333 AGAIN.  

;405)	REMOVE EDIT 372.

;406)	SLEEP ON DATASETS AS WELL AS PTY'S FOR RETRIES.

;****	RELEASE VERSION 56 -- -- START VERSION 57  ****
;	  NEXT EDIT NUMBER WILL BE 420 TO LEAVE ROOM FOR
;	  MAINTENANCE EDITS.

;420)	CHECK LINE NUMBER JUST BEFORE ATTACH UUO SO JOB WHICH
;	BECOMES DETACHED DURING ATTACH COMMAND CAN'T STEAL TTY0
;					[SPR 15329]
;421)	FIX TEST FOR DETACHED LINE.  [SPR 15330]

;422)	FIX BUG IN RECOMPUTING LOGIC.  [SPR 15396]

;423)	ADD /RTCOMPATABILITY SWITCH.

;424)	MAKE LOGIN USE ALL OF HIGH SEG FOR ACCT.SYS (LOGIN
;	USED TO ALWAYS EXPAND CORE EVEN IF NOT NECESSARY)

;425)	ADD CODE TO READ SCDMAP.SYS AND SET SCHEDULER CLASSES.

;426)	FIX ENQ/DEQ QUOTA ROUTINE.

;427)	CHECK FOR END OF STR LIST IN SYSTEMS WITHOUT FENCE AT USRST1.

;430)	MAKE A -1 ENQ QUOTA ENTRY MEAN DON'T SET THE QUOTA SO ON THE
;	FIRST ENQ UUO MONITOR WILL SUPPLY SYSTEM-WIDE DEFAULT QUOTA

;431)	JUMP AROUND ABOUT 30 INSTRUCTIONS IF NON-6.02 MONITOR
;	WHICH ONLY APPLY TO 6.02.  AREA AFFECTED: PRVSET, PRSET3.

;432)	DO A CRLF AFTER TYPING "NO OPERATOR COVERAGE."

;433)	FIX POSSIBLE BUG IN SCHED. TABLE BUILDING LOGIC, AND CLEAN
;	UP SOME CODE AND ERROR MESSAGES.

;434)	ALLOW /HELP TO BE TYPED WITHOUT A PPN

;435)	ALLOW CR IN RESPONSE TO # PROMPT WITHOUT NASTY ERROR MESSAGE

;436)	ADD CODE TO CALL TSKCHK MODULE.  THIS IS USED ON OUR IN-HOUSE
;	TIMESHARING SYSTEM TO ASK FOR AND RECORD IN THE FACT FILE
;	A COST CENTER AND TASK FOR ACCOUNTING PURPOSES.  THIS CODE
;	IS UNDER THE FTTASK SWITCH WHICH WILL REMAIN 0 IN FIELD IMAGE.
;	THIS CODE IS FOR INFORMATIONAL PURPOSES ONLY AND IS NOT
;	SUPPORTED.  [NOTE SWITCH REMOVED AS PART OF EDIT 716]

;437)	WHEN LOGIN BELIEVES IN ENQ/DEQ AND SCHED. CLASSES, IT
;	FORGETS ALL ABOUT VM.  FIX - SET NEWACT=-1 IF ACCT.SYS
;	VERSION NUMBER IS 3 OR GREATER (NOT JUST 3).

;440)	WHEN SAYING "OTHER JOBS SAME PPN", TELL HIM WHAT JOBS.

;441)	MAKE START ADDRESS AND PROGRAM NAME WORK RIGHT.

;442)	MOVE CALL TO .OSCAN SO A) USER HAS SEARCH LIST WHEN IT IS
;	CALLED AND B) /NAME SWITCH WORKS CORRECTLY WITHOUT THE
;	NECESSITY OF HACKS LIKE EDIT 355.

;443)	FINISH THE JOB OF EDIT 442 BY REMOVING (AT LAST!) SETTMP
;	AND CLRTMP.
;444)	ADD TWO ROUTINES: LOCK TO WRITE-ENABLE HI SEG AND LOCK
;	OUT CTRL-C AND OTHER JOBS WHO WANT TO MODIFY HI SEG, AND
;	UNLOCK TO DO THE REVERSE.

;445)	DON'T TELL [1,2] JOBS WHICH JOBS ARE ALSO LOGGED IN UNDER
;	[1,2] - THERE'RE USUALLY VERY MANY AND YOU DON'T WANT TO KNOW

;446)	FIX SPURIOUS ERROR MESSAGE IN TINY MONITOR, AND DO SOME
;	RANDOM CODE CLEANUP

;447)	MAKE .LOGIN [PROJ,PROG,SFD,SFD,..]/SWITCH WORK

;450)	ADD /NOTICE:ARG SWITCH TO CONTROL PRINTING OF NOTICE.TXT
;	ARG=ALWAYS TO ALWAYS SEE NOTICE
;	ARG=SOMETIMES TO WORK LIKE PROJ/PPN
;	ARG=NEVER TO NEVER SEE IT

;451)	ALLOW USER TO SPECIFY DIFFERENT DEFAULT PATH THEN LOGGED-IN
;	PPN

;452)	USE SECOND 512 ENTRIES OF SCDMAP.SYS FOR BATCH JOBS.

;453)	MAKE DEFAULT FOR /NOTICE BE SOMETIMES.

;454)	FIX BUG IN SFD LOGIC AND TYPO IN /NOTICE LOGIC.

;455)	MAKE /VERBOSITY WORK RIGHT.

;456)	USE BUFFERED TTY OUTPUT.  THIS WILL SPEED UP LOGIN IN
;	REAL TIME ON HEAVILY-LOADED DUAL-CPU SYSTEMS.

;457)	ADD /PATH SWITCH TO DO THE OBVIOUS THING.  THIS WILL OVERRIDE
;	A PATH TYPED ON THE LOGIN COMMAND LINE - I.E.,
;	.LOG [34,35,FOO]/PATH:[24,25,BAR] WILL LOG THE USER IN
;	TO [34,35] WITH A PATH OF [24,25,BAR].

;460)	WHEN RECOMPUTING DISK USAGE, DO AN OUTPUT TTY AFTER EACH
;	STR SO USER THINKS SYSTEM IS STILL ALIVE

;461)	SPRINKLE A FEW OUTPUT TTY,S THROUGHOUT LOGIN SO STUFF
;	GETS TYPED A LITTLE AT A TIME, RATHER THAN A LONG
;	WAIT AND THEN A GUSH OF TTY OUTPUT.  ALSO, RELEASE TTY
;	BEFORE ATTACH SO 2,5 JOBS DON'T GET LEFT LYING AROUNG
;	IN TO WAIT.

;462)	WHEN ATTACHING TO A JOB WHOSE PPN REQUIRES NAME, ONLY ASK
;	NAME IF THERE IS ONE IN ACCT.SYS TO CHECK IT AGAINST

;463)	FIX POSSIBLE BUG IN SCHED. TABLE LOGIC

;464)	REMEMBER TO RESERVE BATMIN JOBS FOR BATCH - I.E., FOR A T/S JOB,
;	ALLOW LOGIN ONLY IF LOGMAX-BATMIN-LOGNUM+BATNUM>0 [SPR 10-15847]

;465)	ADD OUTPUT TTY, TO TYPE RTN TO KEEP USERS PATIENT.
;466)	SAVE ERROR CODE OVER CALL TO UFDSMB AT LGNCAS. [SPR 10-15873]

;467)	MAKE /PATH IN SWITCH.INI WORK.

;470)	ADD /ASSIGN:PHYS:LOG SWITCH TO DO THE OBVIOUS.

;471)	IN EDIT 467, AT NOZAP-1, THE BLT DIDN'T HAVE A -1 AFTER IT
;	SO IT BLT'ED THE SPOOL BITS.  FIX: ADD A -1.

;472)	SPLIT TRMOP.S INTO TWO CLASSES - THOSE WHICH SHOULD BE DONE
;	BEFORE PRINTING NOTICE.TXT, AND THOSE WHICH SHOULD BE DONE
;	AFTER.  CURRENTLY ONLY SPEED IS SET AFTER PRINTING NOTICES.

;473)	/ASSIGN:DEV (NO LOG. NAME) MAKES SCAN HALT.  FIX: IF EOL IS
;	SEEN WHILE PROCESSING /ASSIGN, SET FLAG (R.EOL) SO NO MORE
;	INPUT WILL BE DONE AND REEAT ONE CHAR SO SCAN WILL SEE EOL.

;474)	FIX POSSIBLE STACK PHASE PROBLEM IN PARSE.

;475)	ADD TIMEOUT TO WAITO ROUTINE IN LGNSET & CLEAN UP SOME CODE

;476)	FIX BAD RETURN FROM ERROR RECOVERY ROUTINE IN LGNDSK (UFDSE3)

;477)	CHECK LOGMAX FOR BATCH JOBS AND ADD A NEW CLASS OF ERROR MESSAGE
;	FOR BATCON: REQUE, ERROR CODE 5, MEANING REQUE THIS JOB AND
;	DON'T SCHEDULE ANYBODY ELSE FOR A LITTLE WHILE

;500)	REMOVED BY EDIT 505.

;501)	WHEN SCANNING THRU ALL JOB NUMBERS, SCAN UP TO HIGHJOB, NOT
;	LOGNUM.

;502)	IN A SEQUENCE OF /ASSIGNS, THE LAST ONE IS NOT DONE.
;	CURE: CHANGE AOJL TO AOJLE.

;503)	WHEN LOGMAX IS EXCEEDED LOGIN TELLS YOU AND THEN CLEVERLY
;	PROCEEDS TO LOG YOU IN.  FIX: TREAT REQUE AS A FATAL ERROR.

;504)	EQACT WAS MISTAKENLY PUT IN THE LOW SEG. PUT IT IN THE HI SEG.

;505)	REMOVE EDIT 500, AND CHECK BATMAX RATHER THAN LOGMAX FOR BATCH
;	JOBS.  LOGMAX IS NOW DEFINED TO MEAN THE GREATEST NUMBER OF
;	INTERACTIVE, USER JOBS LOGGED IN.  ALSO ADD CONDITIONAL ASSEMBLY
;	SWITCH BATMAX WHICH WILL TURN ON THE NEW BATMAX/LOGMAX
;	CODE.  THIS REQUIRES EDIT 1055 IN BATCON.

;506)	MAKE .LOG 3,4[5,6] WORK.

;507)	ADD AN ERROR MESSAGE IF THE ENQC. UUO FAILS.

;510)	CLEAN UP SOME ERROR MESSAGES AND ADD SOME HUMAN ENGINEERING.

;511)	FIX BUG IN /CORE LOGIC; ADD SOME ERROR MESSAGES FOR 'THIS
;	CAN NEVER HAPPEN' TYPE STUFF; DO SOME CODE CLEANUP.
;512)	ADD A CHECK IN TYPE ROUTINE TO POPJ RIGHT OUT IF NAME
;	OF FILE IS 0 (NO NAME, NO WILDCARDS) TO AVOID AN
;	INCREDIBLY BIZARRE BUG IN WILD.

;513)	DON'T TURN ECHO OFF UNTIL ENTIRE COMMAND LINE(S) TYPED,
;	SO CONTINUATION LINES WILL ECHO.

;514)	IF UFD INTERLOCK IS BUSY TOO LONG GET NASTY AND BREAK
;	THE DOOR DOWN.

;515)	MAKE SURE RP.LOG ALWAYS GETS SET [QAR 3638]

;516)	CODE CLEANUP.

;517)	DON'T TYPE 'NO OPERATOR COVERAGE' ON EVERY RETRY.

;520)	DON'T BOTHER CLEARING TMPCOR, CLEAN UP SOME COSMETICS.
;	ALSO LOCK OUT CTRL-C WHILE WE HAVE UFD INTERLOCK.

;521)	FIX HANDLING OF /CORE.
;	THIS WILL BE LAST EDIT IN VERSION 57.  NEXT EDIT NUMBER
;	WILL BE 540 TO LEAVE ROOM FOR MAINTENANCE EDITS.

;540)	CHECK CREATION DATE-TIME OF ACCOUNTING FILES AND REBUILD
;	HIGH SEGMENT DATA BASE IF THEY HAVE CHANGED.

;541)	IF NOT JACCTED, GIVE WARNING MESSAGE.

;542)	FIX /VERB AND /MESSAG.

;543)	MOVE CALL TO RNMAIL TO BEFORE THE LOGIN UUO SO IT HAS
;	JACCT AND CAN RENAME MAIL TO USER'S AREA.

;544)	.REQUEST SCAN, WILD, AND HELPER TO SIMPLIFY ASSEMBLY & LOADING

;545)	FIX ONE MORE BUG IN /CORE.

;546)	DETERMINE WHETHER TTY IS A 2741 EARLIER SO IF WE DO THE
;	NUMBER-SIGN PROMPT WE GO INTO TI WAIT RATHER THAN
;	HIBERNATING SO THE KEYBOARD UNLOCKS.

;547)	ALLOW /QUOTA TO FORCE RECOMPUTING EVEN IF OTHER JOBS SAME PPN.

;550)	ADD /SFDPROT:055 SWITCH TO DO THE OBVIOUS.

;551)	REWROTE CODE AT NSPOOL+1 SO /CORE WILL FINALLY WORK CORRECTLY

;552)	REORDERED CODE AROUND ACCT1 THRU ACCT3 AND MOVED
;	CODE FOR TYPING DATE AND TIME TO DAYMES,
;	WHERE IT BELONGS

;553)	FIX BUG IN WAITO ROUTINE.

;554)	ADD /UFDPROT:N SWITCH TO DO THE OBVIOUS.
;555)	DON'T ALLOW ATTACHES AFTER KSYS UNLESS OPR OR SON-OF-OPR

;556)	CLEAN UP THE LISTING

;557)	ADD 2 SECURITY FEATURES.  ASSEMBLY SWITCH NCRYPT CAUSES CODE TO
;	BE GENERATED TO ENCRYPT PASSWORDS BEFORE COMPARING THEM TO THE
;	PASSWORD IN ACCT.SYS (WHICH WAS ENCRYPTED BY REACT ALREADY).
;	THE ENCRYPTION FUNCTION IS A NON-INVERTIBLE FUNCTION SO HACKERS
;	CAN READ ACCT.SYS ALL THEY WANT AND NOT GET INTO SOMEONE'S PPN.
;	ASSEMBLY SWITCH PSWCHG ALLOWS USERS TO CHANGE THEIR OWN PSWDS
;	AT LOGIN TIME BY SPECIFYING THE /PASSWORD SWITCH IN THE LOGIN
;	COMMAND LINE.  THIS CAUSES LOGIN TO PROMPT FOR A NEW PASSWORD
;	AND WRITE IT INTO ACCT.SYS.  NOTE: THE ENCRYPTION FEATURE
;	REQUIRES VERSION 32 OF REACT.

;560)	REMOVE THE SIGNIFICANCE OF SLASH IN PPN (REPLACED BY /NOTICE)

;561)	DO AN EXTENDED LOOKUP OF THE FACT FILES SO WE ALWAYS GET
;	THE FILE'S LENGTH IN WORDS AND DON'T MAKE FACT.SYS SEEM
;	TO BE MESSED UP (HIATUS RECORDS).

;562)	IF WE GET THE SKIP RETURN FROM THE IN UUO THAT READS
;	ACCT.SYS, CHECK THE ERROR CODE RATHER THAN ASSUMING THAT IT
;	IS END-OF-FILE.  IF IT ISN'T, GIVE A MORE ILLUMINATING ERROR
;	MESSAGE THAN "INVALID ENTRY - TRY AGAIN".

;563)	DON'T ENABLE CONTROL-C IF THE USER IS LOCKED INTO RUNNING
;	A PROGRAM BY ACCT.SYS.

;564)	CLEAN UP THE EXIT SEQUENCE.

;565)	RE-INIT STACK EVERY TIME THROUGH LOGIN3.

;566)	TURN RP.LOG OFF IF USER CONTROL-C'S DURING RECOMPUTING
;	SO HE WON'T RECOMPUTE NEEDLESSLY NEXT TIME.

;567)	IF EITHER HALF OF LIB PPN IS ZERO, USE USER'S HALF AS DEFAULT.

;570)	CLEAN UP THE CODE.

;571)	REMOVE FACT FILE CODE FROM LOGIN.  MOVE IT TO A SEPARATE MODULE
;	CALLED FACTOR AND CALL THIS MODULE FROM LOGIN.

;572)	ADD CHECK TO BYPASS BLANK AUXACC.SYS ENTRIES.

;573)	FIX ?LGNSND ERROR IN MONITORS WITH LIMLVL=5.

;574)	SAVE M, N, AND CH OVER STUFBS IF THE MESSAGE IS TYPED
;	SO GARBAGE QUOTAS ARE NOT TYPED.

;575)	MAKE BATCH JOBS WAIT TWICE AS LONG ON UFD INTERLOCKS
;	AS INTERACTIVE JOBS, AND DON'T LET THEM BREAK IT DOWN.

;576)	FIX ?ILL MEM REF WHEN CUSP-TO-RUN DOESN'T EXIST
;577)	ALLOW LOGIN WITH NO AUXACC.SYS IF OPR OR HIS OFFSPRING

;600)	DON'T TYPE ERROR SEVERITY TO ANYTHING BUT A BATCH JOB.

;601)	ADD TWOSEG TO LGNDCL MACRO SO LOGIN COMPILES WITH
;	MACRO V.51

;602)	CHECK JBTLIM TO SEE IF BATCH JOB SO WE DON'T DEPEND
;	ON BATCON BEING CALLED BATCON

;603)	CHECK TIMES-TO-LOG IN FOR BATCH JOBS AND P.LGBT

;604)	FIX PROBLEM WITH 2ND TRY AT LOGGING IN WITH /ASSIGN
;	GIVES ? NULL DEVICE ILLEGAL FROM SCAN

;605)	REWRITE CODE AT NOJBMS THRU TTYDET TO FIX BUG
;	INTRODUCED BY EDITS 602 AND 603

;606)	ALLOW ATTACH AND LOGIN AFTER KSYS FROM LOCAL TTY'S

;607)	FIX PROBLEM IN EDIT 605.

;610)	PASSWORDS IN ACCT.SYS ENTRIES WHICH SPAN DISK BLOCKS CANNOT
;	BE CHANGED.  CURE: REMEMBER ONLY POINTER TO PASSWORD,
;	DON'T WORRY IF WHOLE ENTRY CAN'T BE READ IN ONE DSK READ

;611)	PREVENT STRANGE RACES IN ATTACHES

;612)	MAKE ?MAY NOT LOGIN REMOTE/DATASET/BATCH/BATCH SUBJOB
;	ERRORS FATAL SO BATCON WON'T WASTE TIME
;	TRYING TO LOG THE JOB IN

;613)	CLEAN UP THE LISTING; REMOVE UNREACHABLE CODE AND
;	UNREFERENCED DATA

;614)	EDIT 573 IS MISSING A POPJ. CURE: YES.

;615)	SETNAM TO LOGIN RATHER THAN FLUSH TO EVADE KLUDGE IN STOP1C.

;616)	DON'T CHANGE UFD PROTECTION UNLESS /UFDPROTECT SPECIFIED.

;617)	MORE CHANGES TO CONFORM TO MACRO 52.

;620)	IMPLEMENT /DEFPROT:NNN TO SET DEFAULT FILE PROTECTION.

;621)	DON'T PRINT STRANGE GARBAGE IF USER TYPES .R LOGIN

;622)	DON'T LOG IN A USER WHOSE SCHEDULER CLASS HAS A ZERO
;	CPU QUOTA IF THE CLASS SCHEDULER IS RUNNING.

;623)	ENTRY POINT TO FACTOR IS NOW CALLED .FACTR

;624)	PICK UP WHERE EDIT 610 LEFT OFF AND REALLY FIX /PASSWORD.
;625)	SLEEP BEFORE TYPING ?LGNIET TO MAKE IT HARDER TO BREAK
;	SECURITY (EASIER THAN SLEEPING BEFORE ASKING FOR PASSWORD
;	AND TRAPPING FOR CONTROL-C'S WHILE SLEEPING)

;626)	IF WE DON'T HAVE JACCT, WE'RE BEING DEBUGGED - SO DON'T
;	RECOMPUTE DISK USAGE

;627)	/ASSIGN:PHYS-NAME WITH NO LOGICAL NAME LOSES.  FIX IT.

;630)	MAKE "NO OPR COVERAGE" INFORMATIONAL RATHER THAN WARNING.

;631)	LAST-MINUTE CODE CLEANUP.  THIS WILL BE THE LAST EDIT
;	IN VERSION 60.

;632)	DON'T TRY TO SET SCHEDULER CLASS QUOTAS IF 6.03 SCHEDULER
;	RUNNING IN WMU MODE

;633)	LOCATE USER AT CENTRAL SITE IF LOGGING IN ON A NODE WITHOUT
;	AN LPT
;634)	SEE EDIT HISTORY FOR 672 EDIT

;%60A(634)	SHIPPED WITH 6.03A

;635-637) RESERVED FOR DEC 6.03 SUPPORT

;640)	DO PHYSICAL-ONLY RUN UUO FOR CUSP-TO-RUN (SECURITY)

;641)	DISABLE CONTROL-C JUST BEFORE LOGIN UUO AND ENABLE ONLY IF
;	NO CUSP-TO-RUN SPECIFIED

;642)	IF A LINE OF SWITCH.INI ENDS WITH A /ASSIGN, AND THE NEXT LINE
;	CONTAINS A /ASSIGN, YOU GET ?SCNILC ILLEGAL CHAR IN CMD
;	FIX: CLEAR R.EOL EACH TIME THROUGH ASSIGN

;643)	ENQ QUOTA DOESN'T GET SET UP; SENSE OF TEST INSTRUCTION IS BACKWARDS
;	AT PRSET3+5

;644)	FIX YET ANOTHER CASE OF OFF-BY-ONE ARITHMETIC AT UFDEX1-2

;645)	DELETE SEARCH LIST IF USER TYPES ^C WHILE LOGGED OUT

;646)	?LGNCWR UNDESERVEDLY - WRONG GETTAB VALUE BEING USED

;647)	FIX SWITCH.INI NOT BEING READ IF FACTSW TURNED OFF

;650)	RESERVE BATMIN JOB SLOTS FOR BATCON'S USE

;651)	FIX BUG IN /PASSWORD (BUG ONLY IF NCRYPT TURNED ON)

;652)	DON'T ATTEMPT TO CREATE SFD'S ON STRS THAT ARE WRITE-LOCKED

;653)	REMOVE EDIT 547 WHICH ALLOWS USERS TO AVOID QUOTAS

;654)	FIX EDIT 650 SO ATTACH WORKS DESPITE BATMIN.  SPR#10-23336

;655)	SUPPORT "<" AS PPN DELIMITER ON ATTACH.  THIS IS FOR 2741.
;	SPR #10-23335

;656)	TEACH LOGIN ABOUT FIXED VS. UNFIXED CLASS QUOTAS.  SPR#10-23094.

;657)	DON'T PERMIT DATA-SET LOGINS AFTER KSYS.

;660)	PERMIT DETACHED [1,2] JOB TO LOGIN PTY SUBJOBS. SPR #10-23725.
;	NOTE: ONLY PERMITS SON OF [1,2] NOT SON OF DETACHED OPR OR CTY.

;661)	MOVE LOGIN UUO AFTER MESSAGE TYPE-OUT TO PERMIT PROPER /STR
;	OPERATION.  SPR #10-23847

;662)	EDIT 661 WAS NOT VERY GOOD.  REMOVE IT AND TRY AGAIN.

;663)	FIX UP ALL DATES AND COPYRIGHT STATEMENTS

;664)	DON'T PERMIT MORE THAN LOGMAX JOBS IF BATMAX TESTING
;	IS DISABLED.  SPR #10-24354.

;665)	LOGMAX+1 JOBS CAN LOGIN; SHOULD BE LOGMAX.  SPR #10-24354

;666)	IMPLEMENT ACCOUNT AND REMARK PROMPTS TO ENTER AN ACCOUNT STRING
;	AND A REMARK

;667)	DO UFD ZERO COMPRESSION WHEN RECOMPUTING QUOTA.
;	THIS USES THE DISK. UUO FUNCTION CODE 7 WHICH IS NEW FOR
;	7.01.  THE EFFECT OF UFD COMPRESSION IS TO SPEED UP
;	LOOKUPS AND ENTERS.

;670)	FIX BAD POPJ ON ERROR RETURN FROM CTLJOB UUO. SPR #10-24481

;671)	FIX SOME PROBLEMS INTRODUCED BY EDIT 666.

;672)	ADD BACKROUND BATCH SUPPORT.

;673)	IMPLEMENT ACCOUNT VALIDATION

;674)	PUT IN TEMPORARY FIX SO BATCH JOBS CAN RUN WITH ACCOUNT VALIDATION

;675)	IMPLEMENT /TYPE SWITCH TO SET TERMINAL TYPE.

;676)	SPR # 10-25342  WCL  JUNE-27-78
;	Fix code that checks for necessary job slots for Batch so it checks
;	how many Batch jobs are already logged in
;	Areas affected: PPNGO
;677)	FIX BUG IN 675.  AT NOTTYP INSERT  POP	T,T1.
;700)	FIX BUG WHERE CODE AT BACHEK NEVER GETS EXECUTED.
;701)	IMPLEMENT USAGE ACCOUNTING, SPECIFICALLY ACCOUNT VALIDATION (LGNUSG MODULE)
;702)	FIX A VALIDATION ERROR. ALSO MAKE THE LOGIN MESSAGE REPORT THE TIME
;	AS HH:MM INSTEAD OF HHMM.
;703)	FIX BUGS INTRODUCED WITH 702
;704)	DON'T LOSE OWNER PPN FOR NESTED PTY SUBJOBS. SPR #10-27223
;705)	MAKE  /PATH[,,SFD] USE LOGGED-IN PPN AS DEFAULT. SPR #10-27073
;706)	/BAH
;	1)  ADD ATTACH, LOGIN, AND SESSION IPCF MESSAGES SO THE ACCOUNT
;	DAEMON CAN DO USAGE ACCOUNTING WITH SESSION ENTRIES. 
;	2)  ADD /BATSEQ, /BATNAM, AND /REQID SWITCHES SO BATCON CAN PASS
;	BATCH JOB INFORMATION TO THE ACCOUNT DAEMON VIA LOGIN IPCF MESSAGES
;707)	/BAH ADD SETUUO FUNCTION TO SET OPERATOR PRIVILEGES FOR GALAXY 4 SUPPORT
;	3)  FIX UP EDIT 701'S ERROR MESSAGES
;710	REPEAT LOGMAX CHECK JUST PRIOR TO LOGIN UUO
;	SPR 10-27195
;711	CHECK THAT STR NAME IN AUXACC IS "FULL FILE STRUCTURE NAME"
;	SPR 10-27402
;712	/MSL/BAH 22-MAY-79 Display SEARCH, .REQUEST info during compilation
;713)	/MSL/BAH 22-MAY-79 Limit /DSKPRI value by ACCT.SYS
;714)	/MSL/BAH 22-MAY-79 Warn user if account expires within one month
;715)	/MSL/BAH 22-MAY-79 Let user logging in attach if PPN already has detached job
;716)	/MSL/BAH 22-MAY-79 Set up search list before calling OSCAN (for SWITCH.INI), thus
;	allowing account switches, UFD defaults, etc. in SWITCH.INI
;	This rewrite completely changes the order of things (such as 
;	where account validation and accounting is done).  As a result,
;	the FTTASK switch (an unsupported switch used by our in-house
;	systems) no longer applied as written and has been removed.
;717)	/MSL/BAH 22-MAY-79 No NOTICE.TXT if Job Capacity Exceeded
;720)	/MSL/BAH 22-MAY-79 Clear search list before LOGOUT when flushing (c.f. ed.645)
;721)	/MSL/BAH 22-MAY-79 Fix so last error try also gets a FACT entry
;722)	/MSL/BAH 22-MAY-79 Make ENCODE global (SPR 10-23055)
;723)	/MSL/BAH 22-MAY-79 Clear FL.ACC when done with ACCT instead of waiting for AUXACC
;724)	/MSL/BAH 22-MAY-79 Fill AUXACC pointer table, even if early EOF
;725)	/BAH 31-MAY-79 IF A JOB REQUIRES AN ACCOUNT AND/OR REMARK AND THE
;	TERMINAL IS A PTY AND AN ACCOUNT/REMARK WAS NOT SUPPLIED, USE THE
;	CONTROLLING JOB'S ACCOUNT (IF IT EXISTS) AND ALLOW A NULL REMARK.
;726	IF A USER HAS ZERO LOGGED-IN QUOTA ON A STR IN HIS SEARCH LIST
;	DON'T TRY TO CREATE AN SFD ON IT.
;727	COMMAND LIST IS ONE TOO LONG.  ALSO FIX A PJRST P,.USAGE
;730	SEARCH OF AUXACC.SYS FOR PPN IS OFF BY 1.
;	SPR 10-28333.
;731	REMOVE EDIT 730
;732	20-SEP-79/BAH CORE UUO TO EXPAND HIGH SEGMENT CAN FAIL IF 1) SOMEONE
;	IS SAVING LOGIN OR IF 2) IN AN SMP ENVIRONMENT, ANOTHER CPU IS
;	EXECUTING THE SAME CODE WITH THE HIGH SEGMENT WRITE-ENABLED.
;	TO GIVE THE MONITOR TIME TO CATCH UP, SLEEP A SECOND AND TRY AGAIN
;	(3 TIMES) IF THE CORE UUO FAILS.
;733	4-OCT-79/BAH  ADD ATTACH:ARG SWITCH.  IF ATTACH:IGNORE IS IN SWITCH.INI OR TYPED,
;	THEN DON'T PROMPT USER FOR ATTACH MESSAGE IF ANY DETACHED
;	JOBS UNDER HIS PPN.  IF ATTACH:ASK IS IN SWITCH.INI OR TYPED, THEN
;	ASK USER IF HE WANTS TO ATTACH OR LOGIN.  THE DEFAULT IS
;	ALWAYS ASK IF ANY DETACHED JOBS.  SEE EDIT 715.
;734	22-OCT-79/BAH SET U.ACTS AND U.RMRK TO -1 FOR SCAN.  ALSO ZERO  THEM
;	BEFORE FILLING IN THE CHARACTERS SO THE USAGE FILES GET THEM RIGHT.
;735	7-NOV-79/BAH  MAKE LOGIN SEARCH ACTSYM.UNV INSTEAD OF ACCSYM.UNV.
;736	25-JAN-80/BAH  EDIT 723 CLEARED FL.ACC TOO SOON CAUSING PASSWORDS
;	NOT TO BE CHANGED.  ALSO EDIT 716 DELETED THE CALL TO .USAGE THAT
;	SENT A LOGIN MESSAGE TO THE ACCOUNT DAEMON.  ALSO CHANGE THE CALL TO
;	.SIXSW FOR THE /BATNAM SWITCH TO .SIXQW.
;737	14-FEB-80/BAH IF A USER TRIES TO LOGIN WITH AN ILLEGAL PROGRAMMER
;	NUMBER, THEN LOGIN GOES INTO A LOOP READING ACCT.SYS AND REBUILDING
;	ITS TABLE.
;740	SPR 10-28750 Edit 627 caused SCAN to read the slash after a name
;	twice in an /ASSIGN switch if there were more switches.
;741	11-Apr-80/BAH QAR 10-03985 Don't type out error message setting
;	operator privileges if the monitor version number is earlier than
;	7.00.
;742	24-Apr-80/BAH LOGIN doesn't send the terminal designator in its
;	LOGIN and ATTACH IPCF messages to the account daemon.  Include
;	a common routine to find the terminal designator, line number and
;	node name of the job -- SETTNL.  Also include a switch to defer
;	TTY output /TTDEFER.
;743	29-april-80/FRS SPR 10-28831
;	Change put in FACTOR to check to see if job being attached to
;	is DAEMON and [1,2].  If so, skip trying to write FACT entry.
;744	5-May-80/WSM Allow new form for specifing settty switches for LOGIN.
;	ie /TERMINAL:(NOPAGE,SPEED:300,WIDTH:80,TYPE:VT52) instead of a
;	random set of several switches. Also, cleanup some SCAN switch
;	handling. Use standard version macro from MACTEN.
;	Fix recovery from %LGNTTI Terminal type invalid errors
;745	6-May-80/WSM Improve command scanning especially for SESSION
;746	6-MAY-80/WSM Fix the bug that didnt set path to area that
;	already existed if user had no login quota or software write-locked
;	Also, type warning if any PATH. uuo fails.
;747	Complete implementation of /TERMINAL by adding keywords [no]UC,
;	NOFILL and [no]TIDY. Also, dont prompt with password if the user
;	types it on the same line.
;750	Include debugged DDT patch for testing LOGIN under 7.01 
;	(QAR 10-04145) Add /DEFBUFFER:n switch to set default number
;	of disk buffers, like .SET DEFAULT BUFFER n command
;751	(QARs 10-42046, 10-04172) LOGIN loops if invalid PPN given.
;	Edit 737 didnt fix the problem as reported.



;***END OF REVISION HISTORY

;This patch will allow you to debug LOGIN under normal timesharing
; The patch is executed via FILDDT and causes your terminal to 
; run LOGIN from HAKSTR/HAKPPN while all other terminals use SYSPPN. 

;This patch has been tested under the 7.01 monitor


	REPEAT 0,<

PATCH/	HAKPPN:	10,,3146
PATCH+1/	0	HAKSTR:	$"/DSKQ/
PATCH+2/	0	LOGHAK:	PUSHJ P,.+2
LOGHAK+1/	0	JRST MSTART
LOGHAK+2/	0	LGHAK1:	PUSHJ P,SAVE1
LGHAK1+1/	0	MOVEI P1,(U)
LGHAK1+2/	0	LOGLDB:	CAIE P1,-1
LOGLDB+1/	0	POPJ P,
LOGLDB+2/	0	MOVE P1,SGANAM+.JDAT
LOGLDB+3/	0	CAME P1,LOGTXT
LOGLDB+4/	0	POPJ P,
LOGLDB+5/	0	MOVE P1,JBTSTS(J)
LOGLDB+6/	0	TLNE P1,JLOG
LOGLDB+7/	0	POPJ P,
LOGLDB+10/	0	MOVE P1,HAKSTR
LOGLDB+11/	0	MOVEM P1,SGADEV+.JDAT
LOGLDB+12/	0	MOVE P1,HAKPPN
LOGLDB+13/	0	MOVEM P1,SGAPPN+.JDAT
LOGLDB+14/	0	POPJ P,

COMCON$:
SGST1B-FTMP/	JRST MSTART	JRST LOGHAK
GJOB2 5/	SETZM 0(P)	JFCL
CLOGIN 1/	JRST LOGDET	JRST RUNAME

.C0JOB[	70	$Q<JOBNOX:
TTYTAB JOBNOX[	150022
$Q DDBLDB[	711622	$Q<LDB:
LOGLDB/	CAIE P1,-1	CAIE P1,LDB

>>>;END REPEAT 0
;ERROR CODES FOR TYPES OF LOGIN ERRORS (FOR PTY JOBS)
;**** NOTE ERROR COMMENTS SHOULD ALL BEGIN WITH A QUESTION MARK
;**** AND FOR PTY JOBS INCLUDE AN ERROR TYPE OF THE FORM
;**** (#) WHERE # IS ONE OF THE FOLLOWING:

ERR.NF==1	;NON FATAL
ERR.SF==2	;SEMI FATAL
ERR.FT==3	;FATAL
ERR.SS==4	;STOP SCHEDULING (E.G. NO ACCT.SYS)
ERR.RQ==5	;[477] REQUE JOB AND QUIT SCHEDULING FOR A WHILE

;SEE SUBROUTINE ERRLIN

;AC ASSIGNMENTS

F=0	;FLAGS

T1=1	;TEMP AC'S
T2=2
T3=3
T4=4

P1=5	;PRESERVED
P2=6	; ..
P3=7	; ..
N=7	;NUMBERS INPUT
C=10	;CHARACTERS (THIS AC IS READ-ONLY, EDIT 102)
E1=11	;TEMP FOR ERROR MESSAGE TYPEOUT
PP=12	;PROJECT PROGRAMMER PAIR
M=13	;MESSAGE ADDRESSES
CH=14	;CHARACTER FOR TYPE-OUT OR ANALYSIS
EF=15	;FLAGS FOR ERROR MESSAGES
WD=16	;WORDS
P=17	;PUSHDOWN POINTER

;MAY NEED TO RE-ARRANGE AC'S FOR SCAN/WILD COMPATIBILITY

;IO CHANNELS

;0	;USED BY SCAN & WILD
TTY==1	;TELETYPE
UFD==2	;FOR DISK IO
USR==3	;FOR CHECKING USER FILES
US1==4	;THESE TWO USED BY UFDSET
FCT==6	;FOR THE FACT FILE
	SUBTTL	Parameters

;ALL RIB ERROR BITS:
SHFWAT==^D12	;BITS TO SHIFT WATCH BITS TO POSITION FOR SET UUO
;FLAGS - LH OF F

L.PEND==1	;STUFF IN TTY OUTPUT BUFFER
L.MANY==2	;ON IF MORE THAN ONE CONTROLLING JOB IN CHAIN
FL.WKD==4	;ON IF THIS IS A WEEKDAY
FL.FDX==10	;ON IF THIS IS A FULL-DUPLEX LINE
FL.RAS==20	;READ ACCOUNT FILE SYNC (I.E., TO RD 1ST WD)
L.WRTL==40	;SET IF WRITE LOCK FOR STR
FL.ACC==200	;SET IF READING ACCT.SYS, NOT IF AUXACC.SYS
FL.BSJ==1000	;SET IF BATCH JOB SUBJOB
FL.ERR==2000	;SET TO WATCH FOR ERRORS IN UFD SCAN
FL.BAT==4000	;SET IF THIS JOB IS A BATCH JOB
L.NCR==10000	;SET IF NO CREATE FOR AN STR
L.OPR==20000	;SET IF MY TTY IS OPR OR CTY
L.SOPR==40000	;SET IF I AM ON PTY UNDER OPR, CTY OR A 1,2 JOB
FL.ATT==100000	;SET IF ATTACH COMMAND
FL.WLD==200000	;WILD CARD PROGRAMER

;RH OF F

R.ACRE==1	;SET IF ANY CREATES ALLOWED ON ANY STR'S
R.ASTR==2	;SET IF ANY STR'S IN THIS JOB'S SEARCH LIST
R.FMT==4	;WHEN SET, ANY PPN ERROR IS FORMAT ONLY
R.PTYJ==10	;PTY JOB
R.COMA==20	;[440] COMMA HAS BEEN TYPED WHEN TELLING OTHER JOBS
R.2MNY==40	;[470] TOO MANY DEVICES MESSAGE HAS BEEN TYPED
R.EOL==100	;[473] END OF LINE SEEN WHILE DOING /ASSIGN
R.UIB==200	;[514] UFD INTERLOCK WAS BUSY TOO LONG & WE'RE
		;[514] GETTING IMPATIENT
R.UIBM==400	;[514] WE HAVE ALREADY TYPED A WAIT PLS MSG FOR THIS STR
R.DBUG==1000	;[626] WE'RE BEING DEBUGGED
R.NXSW==2000	;[627] NEXT SWITCH SEEN (DURING /ASSIGN PROCESSING)
R.SESS==4000	;SESSION COMMAND
R.RCOM==10000	;SET IF WE HAVE RECOMPUTED ALREADY

;SPECIAL PPN CHARACTERS

UNISYM=="#"	;CHARACTER FOR CREATE UNIQUE PPN
UNIPRG==777776	;INTERNAL VALUE FOR UNIQUE PPN

;PARAMETERS

TRANSZ==10	;MAX SIZE OF FACT.SYS ENTRY
MAXENT==20	;MAX SIZE OF ENTRY IN ACCT.SYS

ACC506==2	;VERSION NUMBER OF OLD ACCT.SYS
ACC601==3	;VERSION NUMBER OF NEW ACCT.SYS
ACC602==4	;[356] VERSION NUMBER OF ACCT.SYS FOR 6.02
AC1FOR==0	;FORMAT VERSION NUMBER FOR AUXACC.SYS

FBMTRY==^D10	;TIMES TO RETRY TO ENTER OR RENAME UFD
IFNDEF	RP.NQC,<	
RP.NQC=2000	;DO NOT INCLUDE FILES WITH THIS BIT SET IN
		; .RBSTS IN LOGGED OUT QUOTA CHECK
>
SCDSIZ==^D1024/4 ;[425] SIZE OF SCHEDULER CLASS TABLE
;WORDS IN ACCT.SYS ENTRY

PPWRD==0	;PROJECT, PROGRAMMER NUMBER
CODWRD==1	;CODE
PRVWRD==2	;PRIVILEGE BITS
NM1WRD==3	;1ST HALF OF USERS NAME
NM2WRD==4	;2ND HALF OF USERS NAME
TIMWRD==5	;LEGAL LOGIN TIMES
VMPWRD==6	;VM PARAMETERS IN LH
		;IPCF PARAMETERS IN RH
PROWRD==7	;USER PROFILE BITS
RCNWRD==11	;NAME OF CUSP TO RUN
RCDWRD==12	;DEVICE FROM WHICH TO RUN CUSP
RCPWRD==13	;DIRECTORY FROM WHICH TO RUN CUSP
CRGWRD==14	;CHARGE NUMBER
XPDWRD==15	;EXPIRATION DATE
;BITS IN LH USER PROFILE WORD

P.SPCR==10000		;SPOOL CDR
P.SPCP==4000		;SPOOL CDP
P.SPTP==2000		;SPOOL PTP
P.SPPL==1000		;SPOOL PLT
P.SPLP==400		;SPOOL LPT
P.WVER==200		;WATCH VERSION
P.WMTA==100		;WATCH MTA
P.WFIL==40		;WATCH FILES

;BITS IN RH USER PROFILE WORD

P.PWBT==1		;PASSWORD REQUIRED FOR BATCH
P.PWTS==2		;PASSWORD REQUIRED FOR TIMESHARING
P.NMBT==4		;NAME REQUIRED FOR BATCH
P.NMTS==10		;NAME REQURED FOR TS
P.LGBT==20		;MAY LOGIN UNDER BATCH
P.LGBS==40		;MAY LOGIN AS BATCH SUBJOB
P.LGRM==100		;MAY LOGIN AT REMOTE (HARDWIRED) TTY
P.LGDS==200		;MAY LOGIN AT DATA SET TTY
P.LGRO==400		;MAY LOGIN AT REMOTE OPR OR CTY
P.LGLC==1000		;MAY LOGIN AT LOCAL TTY
;NOTE MAY ALWAYS LOGIN AT LOCAL OPR OR CTY
P.ACCT==2000		;ACCOUNT IS REQUIRED
P.RMRK==4000		;REMARK IS REQUIRED

MAXFS==9		;MAXIMUM NUMBER OF FILE STRUCTURES PER USER

AC1BLK==5		;NUMBER OF WORDS PER BLOCK IN AUXACC.SYS ENTRIES

EXLLEN==.RBUSD+1	;LENGTH OF ARGUMENT LIST FOR EXTENDED LOOKUP/ENTER/RENAME

	SUBTTL	Message macros
IF1,<
;FLAGS IN LEFT HALF OF EF
EF.SYS==1B1	;SYSTEM ERROR
EF.ERR==1B2	;FATAL ERROR
EF.WRN==1B3	;WARNING
EF.INF==1B4	;INFORMATION LINE (IN [])
EF.REQ==1B5	;[477] TRY AGAIN LATER (LOGMAX EXCEEDED)

;SUPER FATAL ERROR -- NEVER RETURNS
	DEFINE	STOP(PX,TEXT),<
	.ERR.	EF.SYS,PX,<TEXT>
>

;FATAL ERROR (HOWEVER, SYSTEM IS STILL OK)
	DEFINE	FATAL(PX,TEXT),<
	.ERR.	EF.ERR,PX,<TEXT>
>

;WARNING MESSGAE
;CALL WITH:
;	WARN	PREFIX,<TEXT>
;	  RETURN HERE TO SKIP REST OF MESSAGE
;	RETURN HERE TO PRINT REST OF MESSAGE
;NOTE: IF THE INSTRUCTION FOLLOWING THE WARN MACRO IS A JFCL A
;	CRLF WILL BE APPENDED TO THE MESSAGE
	DEFINE	WARN(PX,TEXT),<
	.ERR.	EF.WRN,PX,<TEXT>
>

;[477] SEMI-FATAL ERROR--BATCON SHOULD REQUE JOB AND STOP SCHEDULING
;[477] FOR A LITTLE WHILE
;[477] CALL WITH:
;[477]		REQUE	PREFIX,<TEXT>
;[477]		  NEVER RETURN
	DEFINE	REQUE(PX,TEXT),<
	.ERR.	EF.REQ,PX,<TEXT>
>

;INFORMATION MESSAGE (PRINTED IN [])
;CALL WITH:
;	INFO	PREFIX,<TEXT>
;	  <<SAME AS WARN>>
	DEFINE	INFO(PX,TEXT),<
	.ERR.	EF.INF,PX,<TEXT>
>

	DEFINE	.ERR.	(FLGS,PX,TXT),<
LGN'PX:	MOVEI	E1,''PX''	;LOAD UP SIXBIT PREFIX
;**	MOVE	EF,[FLGS![ASCIZ \TXT\]]	;LOAD TEXT POINTER AND FLAGS
	MOVEI	EF,[ASCIZ \TXT\] ;POINTER TO TEXT
	TXO	EF,FLGS		;TURN ON FLAGS
	PUSHJ	P,ERRMSG	;PRINT THE MESSAGE
>
> ;END IF1
	SUBTTL	Inter-module globals

IF1,<
	DEFINE	GLOBS,<
GLOB <.POPJ,.POPJ1,.TNEWL,ACCT,AD.YN,ALAST,CLRRIB,DATEPR,ATTIGN>
GLOB <W.ACCT,W.AUX,W.SCED>		;[540]
GLOB <BADFOR,BADFRA,BADNAM,BDFRMS>
GLOB <DAYMES,DECPR2,DSKFER,DSKFPA,ENTPTH>
GLOB <ERRLIN,ERRMSG,ETOLO,FLUSH,FRUN,GET2WD,GETCOD>
GLOB <GETACT,.USAGE,LGNATL,LGNICA,ACTVLD,LGNVAL,LGNNAS,USGERR>
GLOB <GETNAM,GIVNBR,HELPR,ISBATC,LAST>
GLOB <LOKBLK,LOKBLN,LOGBLN,LOGBLK,MSG,NOATT,NOMFDP>
GLOB <NOREMT,NOSYS,NOSYS1,NEWLIN,DIEMSG>
GLOB <NOTSMS,NOTSAT,NOTSM1,NOTSM2,NOTSM3,NOTSM4,NOTSM5,NOTSM6>
GLOB <PPERR,PPERR1,PRVSET,PSWOK,PTHERR,RDACCT,RDUFD>
	IFN	PSWCHG,<
GLOB <WTUFD>
	>;END	PSWCHG
GLOB <SNOOZE,SPACE,SPLBTS,STYO,TOLO>
GLOB <TOLO1,TRANSZ,TRYAGN,TTYGET,TTYGO,TYI,TYO>
GLOB <USRSET,POSTMS,WATBTS,WTCHDA>	;[472]
GLOB <ACCTA,CODGET,FLUSHX,LOGIN3,CRLFPD,A2MANY>	;[517]
GLOB <SCDTBL,SCDBLT,BLDSCD,LOK,UNLOCK>		;[425] SCHED STUFF
IFN FASTLG,<GLOB <ENTSIZ,DACCFL,DLOCK,DAUXFL,DACCL,PDACC,NEWACT,EQACT>>

;STUFF IN LGNLOW
GLOB <PDPLST,LGIARG,FCTAHD,FCTHED,FCTFMD,FCTWD,FCTFWD>
	>>
	SUBTTL	Storage definitions
;MACRO TO DEFINE COMMON LOWSEG FOR ALL MODULES
IF1,<
	DEFINE	LOWVAR,<
LBLOCK	LASTX,10	;;LAST PIECE OF CODE
LBLOCK	INTBLK,4	;;CONTROL-C INTERCEPT BLOCK
LWORD	CCWAIT,		;;IF 0 DO CONTROL-C WHEN TYPED.
			;;IF -1 WAIT FOR CRTITICAL CODE TO COMPLETE
LWORD	CCTYPE,		;;-1 IF CONTROL-C TYPED.
LWORD	SAVERG,		;;USED TO SAVE A REGSTER BY LGNDSK
LWORD	HELP,		;;POINTER TO HELP STRING
LWORD	HPOS,		;;POSITION ON LINE
LBLOCK	WILDBK,.FXLEN	;;BLOCK USED BY WILD
LBLOCK	JUNK,4		;;[422] PLACE TO THROW AWAY SHORT LOOKUP BLOCK
LBLOCK	UFDBUF,200	;;[571] BUFFER FOR READING UFD'S
LBLOCK	PTHBUF,11	;;
LBLOCK	CHRBUF,.DCSAJ+1	;;BUFFER FOR DSKCHR
LBLOCK	SRCBUF,EXLLEN	;;
LBLOCK	SECBUF,.RBTIM+1	;;[540]
LWORD	UFDFSN,		;;FILE STRUCTURE NAME
LWORD	UFDMTP,		;;
LWORD	UFDDMJ,		;;
LWORD	UFDDMP,		;;
LBLOCK	UFDDMF,MAXFS*3+1;;[371]
LBLOCK	DATEMP,2	;;
LWORD	OJDFLG		;;Other Job Detached same PPN flag
LBLOCK	SAVAUX,MAXFS*5+1;;Save AUXACC entries while setting S.L.
LBLOCK	FCTDAT,TRANSZ	;;
LBLOCK	RDHED,2		;;
IFN PSWCHG,<		;;[557]
LBLOCK	WTHED,2		;;[557] I/O CMD LIST FOR WRITING ACCT.SYS
LWORD	SAVBLK,		;;[610] BLOCK CONTAINING OUR PSWD
LWORD	SAVPOS,		;;[610] PTR TO WORD WITHIN BLK CONTAINING PSWD
>			;;[557] END IFN PSWCHG
LWORD	FL2741,		;;-1 IF THIS IS A 2741
LBLOCK	TOB,3		;;TTY OUTPUT BUFFER
LBLOCK	TIB,3		;;TTY INPUT BUFFER
LBLOCK	PDL,PDLSIZ+1	;;PUSH DOWN LIST
LWORD	MFDPPN,		;;PPN FOR MFD
LWORD	ALPPPN,		;;ALL PRIVS
LWORD	UFDPRT,		;;[557] STANDARD UFD PROTECTION
LBLOCK	ENTRY,MAXENT	;;DATA FROM ACCT.SYS
LWORD	LOGTRY,		;;TRIES AT LOGGING IN
LWORD	TTBITS,		;;TELETYPE DESCRIPTOR
LWORD	STATES,		;;SYSTEM STATES
LWORD	STATS2,		;;[374] SECOND STATES WORD
IFE FASTLG,<
LWORD	NEWACT,		;;-1 IF NEW ACCT.SYS, 0 IF OLD
> ;END FASTLG

LWORD	NOWBIT,		;;TIME OF DAY AS A BIT

IFE FASTLG,<
LWORD	ENTSIZ,		;;SIZE OF AN ACCT.SYS ENTRY
>

LWORD	ACCTLN,		;;LENGTH OF ACCT.SYS IN BLOCKS
LWORD	ACCKNT,		;;NUMBER OF BLOCKS READ ON ACCT.SYS
LWORD	SAVEDA,		;;SAVED DATE
LWORD	SYSPPN,		;;[1,4]
LWORD	MYTTY,		;;NAME OF MY TTY
LWORD	TTYUDX,		;;UDX OF MY TTY
LWORD	RECFLG,		;;
LWORD	UFDDAT,		;;DATE OF MOST RECENT UFD
LWORD	UFDTIM,		;;AND ITS TIME
LWORD	UFDNDL,		;;0 IF UFD CAN BE RENAMED, -1 IF IT CAN NOT
LWORD	THSJOB,		;;THIS JOB NUMBER
LBLOCK	DEVTAB,DVICES*2	;;[470] TABLE OF DEV PHYS AND LOG NAMES
LWORD	DEVPTR,		;;[470] POINTER TO DEVTAB
LWORD	WLDPNT,		;;TEMP FOR WILD LOOKUPS
LBLOCK	NOTSPC,.FXLEN	;;/NOTE SPEC
LBLOCK	LIBSPC,.FXLEN	;;/LIB SPEC
LBLOCK	TYPSPC,.FXLEN	;;TEMP FOR TYPE
LBLOCK	U.PATH,.FXLEN	;;AREA FOR USER'S PATH SPEC
LBLOCK	PTHSPC,.FXLEN	;;[457] /PATH SWITCH AREA
LWORD	U.SPL,		;;SPOOL REQUEST
LWORD	U.WAT,		;;WATCH REQUEST
LBLOCK	IPS.BL,4	;;IPCF SEND BLOCK
LBLOCK	IPR.BL,6	;;IPCF RECEIVE BLOCK
LBLOCK	PAGBLK,2	;;ARGUMENT BLOCK OF A PAGE. UUO
LWORD	ACTPID,		;;ACCOUNT DAEMON PID
LWORD	ACTMES,		;;TYPE OF ACCOUNTING MESSAGE TO BE SENT
LWORD	MONLNO,		;;LINE NUMBER FOR USAGE ACCOUNTING
LWORD	MONNOD,		;;NODE NAME FOR USAGE ACCOUNTING
LWORD	MONTDE,		;;TERMINAL DESIGNATOR FOR USAGE ACCOUNTING
LWORD	ACTACK		;;UNIQUE MESSAGE IDENTIFIER
;;***START OF BLOCK SET TO -1 ON CALLS TO SCAN

U.STRT==U.ATT		;;START OF BLT FOR SCAN
LWORD	U.ATT		;;ASK OR IGNORE ATTACH MESSAGE IF DETACHED JOB WHEN LOGGING IN
LWORD	U.BNAM		;;BATCH JOB NAME
LWORD	U.BSEQ		;;BATCH SEQUENCE NUMBER
LWORD	U.BREQ		;;BATCH REQUEST ID
LBLOCK	U.ACTS,10	;;ACCOUNT STRING
LBLOCK	U.RMRK,10	;;REMARK
LWORD	U.TYPE,		;;[675] /TYPE
LWORD	U.TIME,		;;TIME LIMIT REQUEST
LWORD	U.CORE,		;;CORE LIMIT
LBLOCK	U.NAME,2,	;;/NAME
LWORD	U.NEW,		;;NEW BIT
LWORD	U.NOTC,		;;[450] /NOTICE
LWORD	U.NWAT,		;;[336] /NOWATCH
LWORD	U.DFER,		;;[365] DEFERRED SPOOLING BIT
LWORD	U.SYS,		;;SYS BIT
LWORD	U.DFUL,		;;DISK FULL CONDTION
LWORD	U.LIMI,		;;1 IF /NOGUIDELINE, 0 IF /GUIDELINE
LWORD	U.GUID,		;;1 IF /GUIDELINE, 0 IF /NOGUIDELINE
LWORD	U.CPPL,		;;CURRENT PHYSICAL PAGE LIMIT
LWORD	U.CVPL,		;;CURRENT VIRTUAL PAGE LIMIT
LWORD	U.SFDP,		;;[550] PROTECTION FOR CREATED SFD'S
LWORD	U.UFDP,		;;[554] PROTECTION FOR CREATED UFD'S
LWORD	U.DFPR,		;;[620] DEFAULT FILE PROTECTION
LWORD	U.DFBU,		;;[750] DEFAULT BUFFERS COUNT
IFN PSWCHG,<		;;[557] IF ALLOWING PASSWORD CHANGING
LWORD	U.NPSW,		;;[557] NEW PASSWORD
> ;;[557] END IFN PSWCHG
IFN	SETTTY,<
LWORD	U.ALTM,		;;[344] ALTMODE CONVERSION
LWORD	U.BLNK,		;;[344] DO NOT TYPE BLANK LINES
LWORD	U.CRLF,		;;[344] FREE CRLF AT RIGHT MARGIN
LWORD	U.DBRK,		;;[344] DEBREAK (2741 TERM.)
LWORD	U.DISP,		;;[743] DISPLAY MODE
LWORD	U.ECHO,		;;[344] GUESS
LWORD	U.FILL,		;;[344] FILLER CLASS
LWORD	U.FORM,		;;[344] TTY HAS FORM FEEDS
LWORD	U.GAG,		;;[344] ALLOW SENDS ONLY AT MON. MODE OR RIGHT MARGIN
LWORD	U.LC,		;;[344] TTY HAS LOWER CASE
LWORD	U.PAGE,		;;[344] ^S-^Q MODE
LWORD	U.PGSZ,		;;[344] PAGE SIZE
LWORD	U.RSPD,		;;[344] RECEIVE SPEED
LWORD	U.RTC,		;;[423] /RTCOMPATABILITY
LWORD	U.SETT,		;;[344] /SETTTY /NOSETTY
LWORD	U.SPED,		;;[344] XMIT/RCV SPEED
LWORD	U.TABS,		;;[344] TTY HAS HARDWARE TABS
LWORD	U.TAPE,		;;[344] XON STARTS PTR
LWORD	U.TIDY,		;;[747] TTY IS TIDY
LWORD	U.TTDE,		;;DEFER TTY OUTPUT
LWORD	U.UC,		;;[747] TTY HAS UPPER CASE
LWORD	U.WDTH,		;;[344] CARRIAGE WIDTH
LWORD	U.XSPD,		;;[344] XMIT SPEED
> ;;[344] END IFN SETTTY
LWORD	U.SCAN,		;;SCAN SWITCH FOR PATH UUO
LWORD	U.STR,		;;STRUCTURE SWITCH
LWORD	U.QTA,		;;NAME OF STRUCTURE TO RECOMP
LWORD	U.STA,		;;STATION NUMBER
U.END==U.STA			;;END OF BLT FOR SCAN
;;***END OF BLOCK SET TO -1 ON CALLS TO SCAN
LWORD	U.DPRI,		;;DISK PRIORITY
LWORD	RPERCT,		;;FLAG FOR FILES FOUND WITH ERRORS
LWORD	SAVKNT,		;;TEMP FOR BUILDING AUX DIR
LWORD	CODE,		;;PASSWORD
LWORD	TDATE,		;;[477] TODAY'S DATE
LWORD	SAVOPR,		;;PLACE TO SAVE NAME OF OPR'S TTY
LWORD	SAOFST,		;;STARTING ADDRESS OFFSET FOR SCAN
LWORD	SVPROT,		;;USED TO SAVE UWP
LWORD	CNTLJT,		;;CONTROLLING JOB'S LINE CHARACTERISTICS
LWORD	CNTLJP,		;;CONTROLLING JOB'S PPN
LWORD	ATTJOB,			;;JOB NUMBER TO ATTACH
LWORD	INISCN,			;;[744] -1 IF IN .OSCAN
;;***ARGUMENT BLOCK FOR LOGIN UUO****
LWORD	PPN,		;;USERS PPN
LWORD	PRIVWD,		;;PRIV WORD
LWORD	NAME,		;;FIRST HALF OF USER NAME
LWORD	NAME2,		;;SECOND HALF OF USER NAME
LWORD	CHGNO,		;;CHARGE NUMBER
;;***END OF LOGIN WORD
IFN FTCMPR, <		;;[667] ARGS FOR ZERO COMPRESSION
LBLOCK	CMPBLK,4	;;[667] UFD COMPRESSION FILE SPEC
LWORD	CMPDSK,		;;[667] DISK. UUO ARGUMENT BLOCK
>			;;[667] END UFD COMPRESSION ARGUMENTS
LBLOCK	ZZMAX,0		;;
>

DEFINE	LWORD(A),<	EXTERNAL A>
DEFINE	LBLOCK(A,B),<	EXTERNAL A>

> ;END IF1


	PRGEND
	TITLE	LOGIN - Initialization for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM

	LGNDCL

;START HERE

LOGIN::	TDZA	17,17		;CLEAR AC17 ON A NORMAL START
	MOVEI	17,1		;SETUP A 1 ON A CCL START
	SETZB	0,LASTX		;PREPARE TO CLEAR CORE
	MOVEI	16,1		;CLEAR THE AC'S
	BLT	16,16		; ..
	MOVE	T1,[LASTX,,LASTX+1] ;CLEAR OUT THE LOWSEG
	BLT	T1,ZZMAX	; ..
	MOVEM	17,SAOFST	;SAVE STARTING OFFSET
	MOVE	T1,[3,,RICC##]	;LOAD UP JOBINT BLOCK
	MOVEM	T1,INTBLK	; ..
	MOVX	T1,ER.ICC	;ASK FOR CONTROL-C
	MOVEM	T1,INTBLK+1	; INTERCEPT
	MOVEI	T1,INTBLK	;CONTROL-C INTERCEPT BLOCK
	MOVEM	T1,.JBINT##	;STORE FOR THE MONITOR
	RESET
	INIT	TTY,IO.SUP	;TURN OFF ECHOING IN CASE FULL DUPLEX
	SIXBIT	/TTY/		;AND THE TELETYPE
	XWD	TOB,TIB
	  LOGOUT		;FORGET IT IF NO TTY
	INIT	UFD,.IODMP	;GET A DISK IN DUMP MODE
	SIXBIT	/SYS/		;LOOKUP ACCOUNTING FILES IN SYS
	XWD	0,0		;NO HEADERS
	  LOGOUT		;THIS IS ALSO UNFIXABLE
	MOVE	P,PDPLST	;GET THE PUSHDOWN STACK
	SETZ	F,		;ALL FLAGS OFF
	SETOM	RECFLG		;SET FLAG FOR RECOMP MESSAGE
	PJOB	T1,		;GET JOB NUMBER
	MOVEM	T1,THSJOB	;[351] SAVE JOB NUMBER
	MOVNI	T3,1		;GET THE TTY CHARACTERISTICS
	GETLCH	T3
	CAMN	T3,[-1]		;IF A NOOP, ASSUME HDX
	MOVX	T3,GL.HDP
	MOVEM	T3,TTBITS
	MOVEM	T3,CNTLJT
	TXNN	T3,GL.ITY!GL.HDP!GL.LCP!GL.PTM	;SKIP IF HALF DUPLEX
	TLO	F,FL.FDX	;SET FULL DUPLEX FLAG
	INBUF	TTY,1
	OUTBUF	TTY,1
	MOVX	T1,%CNSTS	;MAGIC CODES FOR LOC STATES IN SYS
	GETTAB	T1,		;GET TABLE ENTRY
	  SETZ	T1,		;ZERO IF ERROR RETURN
	MOVEM	T1,STATES	;SAVE FOR LATER
	MOVX	T1,%CNST2	;[374] GET SECOND STATES WORD
	GETTAB	T1,		;[374] ..
	  SETZ	T1,		;[374] ..
	MOVEM	T1,STATS2	;[374] SAVE FOR A RAINY DAY
	MOVX	T1,%CNOPR	;GET OPR DEVICE NAME
	GETTAB	T1,		; FROM MONITOR
	  MOVSI T1,(SIXBIT /CTY/)	;ASSUME CTY IF IT WONT TELL US
	MOVEM	T1,SAVOPR	;STORE FOR LATER USE
	GETLIN	T1,		;GET MY TTY NAME
	MOVEM	T1,MYTTY	;SAVE IT
	TXNN	T3,GL.CTY	;IS MY TTY THE CTY?
	CAMN	T1,SAVOPR	;OR THE OPR?
	TLO	F,L.OPR		;YES. REMEMBER THAT IN FLAG AC
	MOVE	T3,THSJOB	;[351] GET OUR JOB NUMBER
	TRMNO.	T3,		;[345] GET TTY UDX
	  SETZ	T3,		;[345] SO WHAT?
	MOVEM	T3,TTYUDX	;[345] SALT AWAY FOR TRMOP. STUFF
	JUMPE	T3,NT2741	;[546] NOT A 2741
	MOVE	T1,[2,,T2]	;[546] ARG POINTER FOR TRMOP.
	MOVX	T2,.TO2741	;[546] READ THE 2741 BIT
	TRMOP.	T1,		;[546] ..
	  SETZ	T1,		;[546] ASSUME NOT 2741
	SKIPE	T1		;[546] IS THIS A 2741?
	SETOM	FL2741		;[546] YES - SET THE FLAG


NT2741:	SETOM	U.STRT		;SET SCAN SWITCH BLOCK TO -1
	MOVE	T1,[XWD U.STRT,U.STRT+1]
	BLT	T1,U.END
	MOVEI	T1,^D5		;LET THE GUY TRY 5 TIMES
	MOVEM	T1,LOGTRY
	MOVX	T1,%LDFFA	;PPN THAT HAS THE PRIVS
	GETTAB	T1,		;GET IT FROM MONITOR
	  MOVE	T1,[1,,2]	;DEFAULT
	MOVEM	T1,ALPPPN	;SAVE IT FOR LATER
	MOVX	T1,%LDMFD	;GET THE MFD PPN
	GETTAB	T1,		; FROM THE MONITOR
	  MOVE	T1,[1,,1]	;DEFAULT
	MOVEM	T1,MFDPPN	;STORE FOR LATER USE
	MOVSI	T1,(SIXBIT .SYS.)
	DEVPPN	T1,		;GET PPN FOR SYS
	  MOVE	T1,[1,,4]	;[361] DEFAULT
	MOVEM	T1,SYSPPN
	MOVX	T1,%LDUFP	;[557] GET STANDARD UFD PROTECTION
	GETTAB	T1,		;[557] ..
	  MOVSI	T1,775000	;[557] EH?
	ROT	T1,^D9		;[557] RIGHT-JUSTIFY IT
	MOVEM	T1,UFDPRT
	DATE	T1,
	MOVEM	T1,TDATE	;[557] SAVE FOR LATER

	PJRST	LGNSCN##	;GO OFF TO COMMAND SCANNER

	PRGEND	LOGIN
	TITLE	LGNSCN - Command scanner for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	LGNDCL

LGNSCN::MOVEI	T1,[ASCIZ /LOGIN/]
	MOVEM	T1,HELP
	TRO	F,R.FMT		;NOTE THAT ERRORS ARE FORMAT ONLY
	MOVE	T1,[XWD 6,SCIBLK]
	PUSHJ	P,.ISCAN##	;CALL SCAN TO GET COMMAND
	MOVE	P1,T1		;SAVE COMMAND VALUE
	CAIN	P1,2		;IS IT A SESSION COMMAND?
	TRO	F,R.SESS	;YES.
	SKIPE	.JBDDT##	;IS DDT LOADED?
	JRST	LGIN2B		;YES--LET IT GO
	MOVN	T1,THSJOB	;MAKE NEGATIVE
	JOBSTS	T1,		;READ JOB STATUS
	  JRST	LOGIN2		;ASSUME OK IF NO JOB STATUS
	TXNE	T1,JB.UJC	;IF JACCT IS CLEAR THERE IS NO HARM TRYING
	TXNN	T1,JB.ULI	;IF JACCT IS SET JLOG MUST BE CLEAR
	JRST	LOGIN2		;OK--EITHER NO PRIVS OR LOGGED OUT
	TRNE	F,R.SESS	;IS IT A SESSION COMMAND?
	JRST	LOGIN2		;YES LET IT GO
	FATAL	KOD,<Please KJOB or DETACH>
LOGIN2:	TXNE	T1,JB.UJC	;[541] JACCT?
	  JRST	LGIN2A		;[541] YES
	WARN	IDJ,<I do not have JACCT.>
	  JFCL			;[541] 
LGIN2B:	TRO	F,R.DBUG	;[626] SET DEBUG FLAG; WE'RE BEING DEBUGGED
LGIN2A:	JUMPLE	P1,LOGDIS	;IF R, RUN, OR  LOGIN COMMAND
	TRNE	F,R.SESS	;SESSION COMMAND?
	JRST	NOJBMS		;YES
;HERE IF ATTACH

	SETZ	T1,		;NO SWITCHES ON ATTACH
	PUSHJ	P,.PSCAN##	;GO SET UP FOR PARTIAL SCAN
	  PJRST	FLUSH		;SHOULD NEVER HAPPEN
	MOVEI	T1,[ASCIZ /a job number/]
	MOVEM	T1,HELP
	PUSHJ	P,.DECNW##	;READ JOB NUMBER TO BE ATTACHED TO
	MOVEM	N,ATTJOB	;SAVE JOB NUMBER
	TLO	F,FL.ATT	;NOTE ATTACH
	SETOM	NOWBIT		;CAN ALWAYS ATTACH
ATTD1:	JUMPLE	C,FLUSH		;MUST BE POSITIVE NUMBER
	CAIE	C,"<"		;[655] CHECK FOR PPN FROM 2741
	CAIN	C,"["		;SKIP IF NOT YET TO PPN
	JRST	ATTD2		;READ PPN
	PUSHJ	P,TYI		;READ NEXT CHAR
	JRST	ATTD1		;AND LOOP TILL [
ATTD2:	PUSHJ	P,.OCTNW##	;READ PROJECT NUMBER
	TLNN	N,-1		;ONLY 6 DIGITS
	CAIE	C,","		;MUST END WITH COMMA
	JRST	PPERR
	JUMPE	N,PPERR		;MUST BE SOMETHING THERE
	HRLZ	PP,N		;SAVE PROJECT NUMBER
	PUSHJ	P,.OCTNW##	;READ PROGRAMMER NUMBER
	JUMPE	N,PPERR		;MUST BE SOMETHING THERE
	TLNE	N,-1		;BUT NOT TOO MUCH
	JRST	PPERR
	HRR	PP,N		;SAVE PROGRAMMER NUMBER
	MOVEM	PP,PPN		;STORE PPN
	MOVEI	N,.GTPPN	;CHECK TO SEE THAT THIS
	HRL	N,ATTJOB	; JOB HAS THE PPN HE
	GETTAB	N,		; CLAIMED IT DOES. THE MONITOR
	  SETZ	N,		; MAKES THIS CHECK BUT LOGIN
	CAME	N,PPN		; COULD HAVE A BUG WHICH WOULD
	JRST	NOATT		; ZAP A USER.
ATTD3:	JUMPLE	C,NOJBMS	;OK, PROCEED WITH ATTACH
	PUSHJ	P,TYI		;NO, IGNORE REST OF LINE
	JRST	ATTD3
	SUBTTL	Type first message, check states bits

;HERE TO TYPE JOB NUMBER, MONITOR NAME, AND TTY NUMBER

LOGDIS:	MOVE	T1,STATES
	TXNN	T1,ST%IMG	;SKIP IF NEW SCANNER SERVICE
	JRST	ONTTY		;OLD SCANNER SERVICE TYPES THIS FOR US

	MOVEI	M,[ASCIZ .JOB .]
	PUSHJ	P,MSG
	MOVE	T1,THSJOB	;GET JOB NUMBER
	PUSHJ	P,.TDECW##
	PUSHJ	P,SPACE
	MOVNI	T3,5
CONFLP:	MOVEI	T1,.GTCNF
	HRLI	T1,5(T3)
	GETTAB	T1,		;GET NEXT WORD OF MONITOR NAME
	  JRST	ONTTY
	MOVEI	M,T1
	SETZ	T2,
	PUSHJ	P,MSG
	AOJL	T3,CONFLP
	PUSHJ	P,SPACE
ONTTY:	MOVE	T1,MYTTY	;GET TTY NAME
	PUSHJ	P,.TSIXN##	;PRINT IT
	PUSHJ	P,.TCRLF##

NOJBMS:	MOVE	T3,TTBITS
	MOVE	T2,STATES	;GET STATES WORD
	TXNN	T3,GL.ITY	;[605] PTY?
	  JRST	TTYGO		;[605] NO: NO SPECIAL CHECKS THEN

	TRO	F,R.PTYJ	;MARK AS A PTY JOB
	MOVE	T1,THSJOB	;[607] GET OUR JOB NUMBER
	PUSHJ	P,ISBATC	;SEE IF WE'RE A BATCH JOB
	  JRST	NOTBAT		;[605] NO
	TLO	F,FL.BAT!L.SOPR	;REMEMBER THIS IS A BATCH JOB
	JRST	TTYGO		;[605] TRUST BATCON AND SKIP CHECKS

;[605] HERE IF NON-BATCH PTY JOB TO CHECK SUPERIOR JOBS

NOTBAT:	PUSHJ	P,FNDCTL	;FIND CONTROLLING JOB NUMBER
	 JRST	TTYDET		;CAN'T
	  JRST	BJSJ		;BATCH JOB SUBJOB
	MOVEM	T2,CNTLJP	;SAVE CONTROLLER'S PPN
	HRLZ	T1,T3		;T1=SIXBIT LINE NUMBER
	CAME	T3,[SIXBIT/CTY/]	;[660] SKIP IF ATTACHED CTY
	CAMN	T3,SAVOPR	;IS IT THE OPR?
	TLO	F,L.SOPR	;FLAG SUBJOB OF OPR.
	SETZ	T3,
	MOVE	T4,[POINT 6,T1]
	JUMPN	T1,ISPTY1	;JUMP IF NOT CTY
	MOVX	T3,%CNPTY
	GETTAB	T3,
	  SETO	T3,
	HLRES	T3		;T3=OFFSET FOR FIRST PTY
	SUBI	T3,1		;-1=LINE NUMBER OF CTY
	JUMPGE	T3,ISPTY2	;JUMP IF HAVE CTY LINE NUMBER
	MOVX	T3,GL.CTY	;NO, FAKE TTBITS
	JRST	ISPTY3		;WE KNOW ITS THE CTY

ISPTY1:	ILDB	WD,T4
	JUMPE	WD,ISPTY2	;JUMP IF NO MORE CHARS
	LSH	T3,3
	ADDI	T3,-20(WD)
	JRST	ISPTY1

TTYDET:	SKIPA	T3,[GL.REM+GL.DSL]	;MAKE HIM NON-LOCAL

ISPTY2:	GETLCH	T3		;GET LINE BITS FOR CONTROL JOB TTY
ISPTY3:	MOVEM	T3,CNTLJT	;SAVE LINE BITS FOR CONTROL JOB TTY
	JRST	TTYGO		;GO DO THE ACCOUNTING

BJSJ:	TLO	F,FL.BSJ	;REMEMBER WE'RE A BATCH JOB SUBJOB
	MOVEM	T2,CNTLJP	;CONTROLLING PPN=PPN OF BATCH JOB
	MOVX	T3,GL.REM	;PRETEND REMOTE
	MOVEM	T3,CNTLJT	;SAVE FAKE TTY BITS
	JRST	TTYGO		;GO DO CHECKING
;ROUTINE TO FIND JOB'S ULTIMATE CONTROLLER FOR PURPOSES OF ACCESS CHECKING
;STOP SCANNING IF REACH: [1,2] JOB, TOP LEVEL JOB, DETACHED JOB, OR BATCH JOB
;CALL:	PUSHJ	P,FNDCTL
;	 CPOPJ IF CAN'T FIND JOB (ASSUME WE'RE DETACHED)
;	  CPOPJ1 IF BATCH JOB SUBJOB (ASSUME REMOTE)
;	    CPOPJ2 WITH AC'S SET UP AS FOLLOWS:
;		T1=CONTROLLING JOB NUMBER
;		T2=CONTROLLING JOB'S PPN
;		T3=CONTROLLING JOB'S PHYSICAL TTY NAME
FNDCTL:	SETO	T1,		;FIRST, GET IMMEDIATE CONTROLLING JOB
	CTLJOB	T1,		;..
	  JRST	CPOPJ		;ASSUME WE'VE BECOME DETACHED
	JUMPL	T1,CPOPJ	;DITTO

FNDCT1:	HRLZ	T3,T1		;GET THIS JOB'S TTY DDB ADDRESS
	HRRI	T3,.GTTTY	;..
	GETTAB	T3,		;..
	  JRST	CPOPJ
	PEEK	T3,		;GET PHYSICAL TTY NAME
				;[660] REMOVED 3 INSTRUCTIONS
	PUSH	P,T1		;SAVE T1
	MOVE	T1,T2		;SAVE LAST PPN IN CASE SON-OF-OPR
	HRLZ	T2,(P)		;GET THIS JOB'S PPN (JOB # ON STACK)
	HRRI	T2,.GTPPN	;..
	GETTAB	T2,
	  SETZ	T2,
	CAMN	T2,ALPPPN	;HAVE WE HIT A [1,2] JOB YET?
	  JRST	SONOPR		;YES: WE'RE SON-OF-OPR
	HRRZ	T1,(P)		;GET JOB NO. BACK AGAIN
	PUSHJ	P,ISBATC	;IS THIS JOB A BATCH JOB?
	  JRST	NOTBSJ
	POP	P,T1		;FIX UP STACK
	JRST	CPOPJ1		;WE'RE A BATCH JOB SUBJOB

NOTBSJ:	MOVE	T1,(P)		;RESTORE T1 FOR A BIT
	CTLJOB	T1,		;ANOTHER LEVEL?
	  JRST	TPOPJ		;[670] RESTORE T1 AND RETURN
	AOJE	T1,TOPLVL	;IF T1=-1 WE'VE HIT TOP LEVEL
	TLO	F,L.MANY	;FLAG MORE THAN ONE SUPERIOR
	POP	P,T3		;[704] ADJUST STACK
	SOJA	T1,FNDCT1	;[704] GO THRU NEXT LEVEL


SONOPR:	TLO	F,L.SOPR	;REMEMBER WE'RE SPAWN OF OPR
	MOVE	T2,T1		;USE LAST NON-[1,2] PPN AS CONTROLLER
	TLNN	F,L.MANY	;UNLESS [1,2] IS IMMEDIATE CONTROLLER
	  MOVE	T2,ALPPPN	;IN WHICH CASE USE [1,2]
TOPLVL:	POP	P,T1		;JOB # WE WANT IS ON STACK
CPOPJ2:	AOS	(P)
CPOPJ1:	AOSA	(P)		;[670]
TPOPJ:	POP	P,T1		;[670] RESTORE T1
CPOPJ:	POPJ	P,
;SUBROUTINE TO PARSE THE LOGIN COMMAND LINE
;CALL WITH:
;	PUSHJ	P,PARSE
;	RETURN HERE IF OK
;
PARSE::	TLZ	F,FL.WLD	;[355]
	TRZ	F,R.EOL		;[604] CLEAR FLAGS WHICH NEED IT
	SETZM	U.PATH		;[376] CLEAR OUT PATH SPECS
	MOVE	T1,[XWD U.PATH,U.PATH+1] ;[376]
	BLT	T1,U.PATH+.FXLEN*2-1 ;[457]
	SETOM	U.STRT		;[355] CLEAR OUT SWITCH BLOCK
	MOVE	T1,[XWD U.STRT,U.STRT+1]	;[355]
	BLT	T1,U.END	;[355]
	MOVE	T1,[IOWD DVICES*2+1,DEVTAB] ;[470] INIT PTR TO DEV TABLE
	MOVEM	T1,DEVPTR	;[470] ..
	MOVE	T1,[LOGBLN,,LOGBLK]	;SETUP UP TO DO A PARTIAL
	TRNE	F,R.SESSION	;[745] SESSION COMMAND?
	 JRST	PARSES		;[745] YES--GO PARSE IT
	PUSHJ	P,.PSCAN##	; SCAN.
	 PUSHJ	P,GIVNBR	;GIVE NUMBER SIGN PROMPT IF NEEDED
	SETZB	PP,RDHED	;[451] THIS IS A GOOD IDEA
LOOP:	PUSHJ	P,.TIAUC##	;[330] GET NEXT CHAR
	JUMPLE	C,PARSE		;[506] ALLOW BLANK LINES
	CAIN	C," "		;[330] EAT SPACES
	JRST	LOOP		;[330]
	CAIL	C,"0"		;[330] NOT SPACE OR BRACKET - IS IT
	CAILE	C,"7"		;[330] AN OCTAL DIGIT?
	  JRST	PTHSWT		;[446] NO - GO GET PPN, PATH, & SWITCHES
	PUSHJ	P,.OCTNC##	;[745][447] GET PROJ NO (HAVE 1ST DIGIT)
	JUMPL	C,[JUMPE N,PARSE ;IGNORE BLANK LINES
		   JRST  PPERR]	;INVALID ENTRY
	CAIE	C,"/"		;SLASH BREAK?
	CAIN	C,","		;ORDINARY COMMA BREAK?
	SKIPN	N		;NON-ZERO NUMBER
	JRST	PPERR		;NO GOOD
	TLNE	N,-1		;ALSO ONLY 6 DIGITS
	JRST	PPERR
	HRLZ	PP,N		;PUT IN AC PP
	PUSHJ	P,.TIAUC##	;LOOK AT NEXT CHAR
	CAIE	C,UNISYM	;WANT UNIQUE PPN?
	JRST	GPRGMN		;NO, COLLECT PROGRAMMER NO
	PUSHJ	P,.TIAUC##	;GET SEPARATOR INTO CH
	MOVEI	N,UNIPRG	;PUT UNIQUE CODE INTO N
	TLOA	F,FL.WLD	;NOTE UNIQUE PROGRAMMER NO
GPRGMN:	PUSHJ	P,.OCTNC##	;COLLECT PROGRAMMER, 1ST CHAR IN CH
	JUMPE	N,PPERR		;THIS SHOULD CATCH FORMAT ERRORS
	TLNE	N,-1		;..
	JRST	PPERR		;NO GOOD.
	HRR	PP,N		;MAKE AN XWD
	JUMPLE	C,NOSWIT	;[442] NO PATH OR SWITCES IF EOL FOUND
;HERE HANDLE PATH DEFINITION AND LOGIN SWITCHES

PTHSWT:	PUSHJ	P,.REEAT##	;[325] BACK UP ONE CHARACTER
	PUSHJ	P,.FILIN##	;[434] GO SCAN OFF THE PATH
	MOVEI	T1,U.PATH	;NOW GO COPY THE SPEC
	MOVEI	T2,.FXLEN	;  INTO LOGIN'S CORE
	PUSHJ	P,.GTSPC##	;  AREA
NOSWIT:	SKIPN	PP		;[447] NON-PATH PPN TYPED?
	  MOVE	PP,U.PATH+.FXDIR;[447] NO - GET PATH PPN
	TLNE	PP,-1		;[447] MAKE SURE BOTH HALVES
	 TRNN	PP,-1		;[447] ARE NON-ZERO
	  JRST	PPERR		;[447] NOPE - COMPLAIN
	MOVEM	PP,PPN		;[447] YES - SALT PPN AWAY FOR LOGIN UUO
	SETSTS	TTY,IO.SUP	;[447] TURN OFF ECHOING
	OUTPUT	TTY,		;[456] MAKE SURE SCNSER KNOWS ABOUT IT

	MOVEI	T1,U.PATH	;[457] GET ADDR OF PATH SPEC TO CHECK
	PUSHJ	P,CHKPTH	;[457] MAKE SURE IT'S A NICE PATH SPEC
	  JRST	PTHERR		;[457] NO - BOMB HIM
	MOVEI	T1,PTHSPC	;[457] GET ADDR OF PATH SWITCH SPEC
	MOVE	T4,PTHSPC+.FXDIR;[474] DON'T WANT CHKPTH TO DEFAULT THIS
	PUSHJ	P,CHKPTH	;[457] MAKE SURE IT'S OK
	  JRST	PTHERR		;[457] BAD BOY
	SKIPN	PTHSPC+.FXDIR+2	;[705] WAS SFD TYPED IN PATH?
	JRST	NOSWT1		;[705] NO, SO LEAVE PTHSPC ALONE
	TLNN	T4,-1		;[705] ELSE: - IS PROJECT ZERO?
	HLL	T4,PP		;[705] YES - DEFAULT TO USER'S
	TRNN	T4,-1		;[705] IS PROG NO. ZERO?
	HRR	T4,PP		;[705] YES - DEFAULT TO USER'S
NOSWT1:	MOVEM	T4,PTHSPC+.FXDIR;[474][705] GET DESIRED PPN BACK
	SKIPN	U.PATH+.FXDIR+2	;[457] WERE SFD'S TYPED WITHOUT /PATH?
	POPJ	P,		;[457] NO - ALL IS OK
	SKIPN	PTHSPC+.FXDIR+2	;[457] YES - WAS AN SFD TYPED IN /PATH?
	POPJ	P,		;[457] NO - STILL OK
	JRST	PTHERR		;[457] YES - THAT IS A CONFLICT - COMPLAIN
	SUBTTL	SESSION command scanning

PARSES:	GETPPN	PP,			;SETUP PPN
	 JFCL
	MOVEM	PP,PPN			;STASH AWAY
	PUSHJ	P,.PSCAN##		;SCAN
	 POPJ	P,			;IF PROMPT NEEDED, RETURN
	PUSHJ	P,.TIAUC##		;PRIME THE PUMP
PARSS1:	CAIN	C," "			;A SPACE?
	 PUSHJ	P,.TIAUC##		;YES--GET A REAL CHAR
	CAIE	C,"/"			;SWITCH COMING?
	 JRST	LGNISF			;NO--ERROR
	PUSHJ	P,.KEYWD##		;YES--GO PROCESS IT
	 JRST	LGNISF			;NO SWITCH--ERROR
	JUMPG	C,PARSS1		;LOOP IF MORE
	POPJ	P,			;ELSE RETURN

	FATAL	ISF,<Illegal SESSION command format>
;[457] ROUTINE TO CHECK LEGALITY OF PATH SPEC (NO WILDCARDS ALLOWED)
;[457] CALL:	MOVE	T1,ADDRESS-OF-PATH-SPEC
;[457]		PUSHJ	P,CHKPTH
;[457]		  BAD PATH
;[457]		OKAY
;[457] THIS ROUTINE ALSO PLUGS IN LOGGED-IN PPN IF NO PPN GIVEN

CHKPTH:	MOVSI	T2,'DSK'	;FORCE DEFAULT OF DSK
	SKIPN	.FXDEV(T1)	;DEFAULT SUPPLIED BY SCAN
	  MOVEM	T2,.FXDEV(T1)	;STORE CORRECTED DEVICE
	MOVE	T3,.FXDEV(T1)	;GET THE DEVICE NAME
	DEVCHR	T3,		;GET ITS DEVICE TYPE
	TXNE	T3,DV.DSK	;MUST BE A DISK
	 SKIPE	.FXNAM(T1)	;NOR FILE NAME
	  JRST	.POPJ		;BOMB HIM ON THAT
	SKIPE	.FXEXT(T1)	;CAN'T EVEN GIVE EXT
	  JRST	.POPJ
	MOVSI	T3,-.FXLND	;ENTRIES IN A FULL PATH SPEC
	ADD	T3,T1		;[457] BASE ADDR OF PATH SPEC
PTHCHK:	SKIPN	.FXDIR(T3)	;WAS A DIRECTORY GIVEN?
	  JRST	.PLUS5		;NO, WE'VE REACHED END OF LIST
	AOSE	.FXDIM(T3)	;YES, WERE WILD CARDS GIVEN?
	  JRST	.POPJ		;YES, MUSTN'T DO THAT
	AOJ	T3,
	AOBJN	T3,PTHCHK	;LOOP TO CHECK ENTIRE PATH
.PLUS5:	HLLZ	T2,.FXDIR(T1);DID HE GIVE A PROJ?
	SKIPN	T2
	  HLLM	PP,.FXDIR(T1);NO--JAM IT IN
	HRRZ	T2,.FXDIR(T1);DID HE GIVE A PROG. NO.
	SKIPN	T2
	  HRRM	PP,.FXDIR(T1);NO--GO DO THE DEFAULT
	JRST	.POPJ1		;[457] GIVE GOOD RETURN
;HERE TO GET NAME

GETNAM:	MOVEI	T1,[ASCIZ /your name/]
	MOVEM	T1,HELP
	MOVE	T1,U.NAME	;GET THE USER NAME
	MOVE	T2,U.NAME+1	;GET THE SECOND HALF
	CAME	T1,[-1]		;NAME GIVEN?
	JRST	GETNM1		;YES--DO NOT NEED TO ASK
	MOVE	T1,ENTRY+NM1WRD	;[462] PICK UP NAME FROM ACCT.SYS
	MOVE	T2,ENTRY+NM2WRD	;[462] ..
	JUMPN	T1,.+3		;[462] IS THERE ONE?
	 TLNE	F,FL.ATT	;[462] NO - ARE WE ATTACHING?
	  JRST	GETNM1		;[462] YES - DON'T ASK, THEN
	SETZ	T1,		;NO SWITCHES ON NAME
	MOVEI	M,[ASCIZ .Name: .]
	PUSHJ	P,MSG		;[443] PROMPT
	SETSTS	TTY,0		;TURN ON ECHO
	OUTPUT	TTY,		;[456] CAUSE SCNSER TO SEE NEW STATUS
	PUSHJ	P,GET2WD	;GET NAME
	SETSTS	TTY,IO.SUP	;NO ECHO NOW
	OUTPUT	TTY,		;[456] HEY, SCNSER...
GETNM1:	MOVEM	T1,NAME
	MOVEM	T2,NAME2
	MOVE	T3,ENTRY+PROWRD	;GET PROFILE WORD
	TRNN	T3,P.NMTS	;IS NAME REQUIRED?
	SKIPE	ENTRY+NM1WRD	;SKIP IF ACCT.SYS = 0
	JRST	GETCOD		;GO COLLECT PASSWORD
	MOVEM	T1,ENTRY+NM1WRD	;NO--FORCE A VALID NAME BY
	MOVEM	T2,ENTRY+NM2WRD	; OVERWRITING NAME IN ACCT.SYS ENTRY
	TRNN	T3,P.PWTS 	;NEED PASSWORD
	JRST	PSWOK		;NO--CHARGE AHEAD
;HERE TO GET PASSWORD

GETCOD:	MOVEI	T1,[ASCIZ /a valid password/]	;HELP
	MOVEM	T1,HELP		; TEXT FOR TIMEOUT
	PUSHJ	P,CODGET
	MOVEM	T1,CODE		;SAVE THE PASSWORD TO INCLUDE IN FACT FILE
	JUMPN	T2,TRYAGN	;CAN'T BE MORE THE 6 LETTERS
	SKIPN	ENTRY+NM1WRD	;[355] ASSUME OK IF NAME IN FILE IS ZERO
	JRST	NAMEOK
	MOVE	T1,ENTRY+PROWRD	;[355] GET PROFILE WORD
	TRNN	T1,P.NMTS	;[355] NAME REQUIRED?
	JRST	NAMEOK		;[355] NO -- PROCEED
	MOVE	T1,ENTRY+NM1WRD	;YES. CHECK THE NAME.
	MOVE	T2,ENTRY+NM2WRD
	CAMN	T1,NAME		;..
	CAME	T2,NAME2	;SECOND HALF
	JRST	BADNAM
NAMEOK:	MOVE	P1,CODE		;[557] GET PASSWORD TYPED
	IFN	NCRYPT,<	;[557] IF ENCRYPTING
	PUSHJ	P,ENCODE##	;[557] THEN ENCRYPT IT
	>			;[557] END IFN NCRYPT
	CAME	P1,ENTRY+CODWRD	;[557] DOES PASSWORD MATCH?
	  JRST	TRYAGN		;NO. HE LOSES.
	IFN	PSWCHG,<	;[557] IF ALLOWING PSWD CHANGES
	SKIPG	U.NPSW		;[557] USER WANT TO CHANGE HER PSWD?
	  JRST	PSWOK		;[557] NO - SKIP THIS STUFF
NOWAY:	MOVEI	T1,[ASCIZ /a new password/]
	MOVEM	T1,HELP		;[557] HELP TEXT FOR TIMEOUT
	MOVEI	M,[ASCIZ /New password: /]
	PUSHJ	P,MSG		;[557] PROMPT
	SETSTS	TTY,0		;[557] TURN ON ECHO
	OUTPUT	TTY,		;[557] TYPE THE PROMPT
	PUSHJ	P,GET2WD	;[557] GET THE ANSWER
	SKIPN	P1,T1		;[557] MAKE SURE NON-NULL
	  JRST	NOWAY		;[557] NULL PSWD IS A NO-NO
	JUMPN	T2,NOWAY	;[557] PASSWORD TOO LONG
	IFN	NCRYPT,<	;[557] ENCRYPTING PSWDS?
	PUSHJ	P,ENCODE##	;[557] YES - MUNGE IT
	>			;[557] END IFN NCRYPT
	MOVEM	P1,ENTRY+CODWRD	;[557] REPLACE OLD PSWD WITH NEW
	PUSHJ	P,WTUFD		;[557] WRITE THE BLOCK TO ACCT.SYS
	>			;[557] END IFN PSWCHG
	JRST	PSWOK		;CHARGE AHEAD
;SUBROUTINE TO SCAN OFF DISK PRIORITY
;
SWDSKP:	PUSHJ	P,.OCTNW##	;READ THE NUMBER
	CAML	N,[-3]		;TOO SMALL
	CAILE	N,3		;TOO BIG
	JRST	SDSKPE		;YES--ERROR
	MOVEM	N,U.DPRI	;STORE THE ANSWER
	PJRST	.SWDON##	;RETURN

SDSKPE:	M.FAIO	<Invalid argument to /DSKPRI:>


;[470] SUBROUTINE TO STORE ARGS TO /ASSIGN:PHYS:LOG
;
ASSIGN:	TRZ	F,R.NXSW!R.EOL	;[627] CLEAR NEXT-SWITCH-SEEN FLAG AND END-OF-LINE FLAG
	AOS	(P)		;[470] SKIP RETURN TO BYPASS .SWDPB
	PUSHJ	P,.+1		;[470] DO THIS TWICE - ONCE FOR PHYS
				;[470] NAME, ONCE FOR LOG NAME
	TRNE	F,R.EOL		;[473] EOL SEEN YET?
	  POPJ	P,		;[473] YES-SCAN BARFS IF WE CALL .SIXSW
	MOVE	T1,DEVPTR	;[470] GET POINTER TO TABLE
	AOBJP	T1,A2MANY	;[470] TOO MANY /ASSIGN SWITCHES
	SETZ	T2,		;[627] ZAP T2 IN CASE NO LOGICAL NAME
	TRNE	F,R.NXSW	;[627] ARE WE ABOUT TO READ THE NEXT SWITCH?
	  JRST	ASIGN1		;[627] YES - DON'T!
	PUSH	P,T1		;[470] SAVE T1 OVER .SIXQW
	PUSHJ	P,.SIXSW##	;[470] GET SIXBIT STRING
	CAIN	C,"/"		;[627] NEXT SWITCH?
	TRO	  F,R.NXSW	;[627] REMEMBER TO STOP NOW
	SKIPG	C		;[473] EOL YET?
	TRO	  F,R.EOL	;[627] EOL - REMEMBER IT
	POP	P,T1		;[470] GET T1 BACK AGAIN
	MOVE	T2,.NMUL##	;[470] PICK UP ARG FROM SCAN
ASIGN1:	MOVEM	T2,(T1)		;[627] STORE AWAY IN TABLE
	MOVEM	T1,DEVPTR	;[470] SAVE POINTER TO TABLE
	POPJ	P,		;[470] RETURN
;SUBROUTINE TO READ /ACCOUNT SWITCH
;CALL:	PUSHJ	P,ACCTSW
;	RETURN HERE
;
ACCTSW:	PUSHJ	P,.SWASQ##	;READ THE QUOTED STRING
	MOVE	T1,[POINT 7,.NMUL##];POINT TO STORAGE
	MOVEI	T3,^D39		;MAXIMUM NUMBER OF CHARACTERS IN ACCOUNT STRING
ACCTS1:	ILDB	T4,T1		;GET A CHAR
	JUMPE	T4,.SWDPB##	;NOTE THAT VALIDATION IS DONE LATER
	CAIGE	T4,176		;NO. CHECK FOR ILLEGAL CHARACTERS
	 CAIGE	T4," "
	  JRST	LGNICA		;BAD CHARACTER. GO REPORT IT
	SOJGE	T3,ACCTS1	;LOOP FOR ALL
	JRST	LGNATL		;ERROR IF TOO LONG

;SUBROUTINE TO READ /REMARK SWITCH
;CALL:	PUSHJ	P,RMRKSW
;	RETURN HERE
;
RMRKSW:	PUSHJ	P,.SWASQ##	;READ THE QUOTED STRING
	MOVE	T1,[POINT 7,.NMUL##];POINT TO IT
	MOVEI	T3,^D39		;SET MAXIMUM LENGTH
RMRKS1:	ILDB	T4,T1		;GET A CHAR
	JUMPE	T4,.SWDPB##	;GO STORE IF THE END
	CAIGE	T4,176		;NO. CHECK FOR ILLEGAL CHARACTERS
	 CAIGE	T4," "
	  MOVEI	T4,"\"		;IF ILLEGAL, SUBSTITUTE A BACKSLASH
	DPB	T4,T1		;STORE THE CHAR
	SOJGE	T3,RMRKS1	;LOOP FOR ALL
	JRST	.SWDPB##	;AND RETURN TO STORE

;SUBROUTINE TO READ /BATNAM:"NAME" SWITCH
BATNAM:	PUSHJ	P,.SIXQW##	;[744] READ QUOTED SIXBIT STRING
	MOVE	N,.NMUL##	;[744] RETURN FIRST WORD
	JRST	.SWDPB##	;[744] AND LET SCAN STORE
	SUBTTL	TERMSW -- Handle /TERMINAL:(args) switch	[744]

;THIS ROUTINE IS SIMILIAR TO .KEYWD IN SCAN, EXCEPT IT DOESNT HANDLE
;ALSO THE CASES THAT SCAN'S DOES. BUT, IT HANDLES THE SIMPLE SN,SP,SL
;SUB-SWITCHES THAT LOGIN USERS FOR /TERMINAL:. MAYBE SOMEDAY IF SCAN
;CHANGES, WE CAN REMOVE THIS CODE


IFN SETTTY,<				;[744]
TERMSW:	PUSHJ	P,.SAVE2##		;SAVE P1 (SWITCH INDEX)
					;  AND P2 (LOCAL/REMOTE INDEX)
	MOVEI	P2,TTYSWT		;GET POINTER TO SWITCH TABLES
	PUSHJ	P,.SIXSW##		;GET NAME
	MOVE	T1,[IOWD TERM.L,TERM.N]	;GO LOOKUP NAME
	PUSHJ	P,.NAME##		;IN TABLE
	  SKIPA				;CAN'T FIND, TRY HARDER
	JRST	[MOVEI	P1,-TERM.N(T1)	;GET SWITCH INDEX
		 JRST	KEYWDG]		;AND PROCESS
	JUMPG	T1,E.UKK##		;AMBIGUOUS IF MORE THAN ONE
	TLC	N,'NO '			;SEE IF /NOXYZ
	TLCE	N,'NO '			;..
	 JRST	E.UKK##			;NO--ISSUE ERROR
	PUSH	P,N			;SAVE WORD
	LSH	N,^D12			;STRIP "NO"
	MOVE	T1,[IOWD TERM.L,TERM.N]	;GO LOOKUP NAME
	PUSHJ	P,.NAME##		;AND TRY AGAIN
	  JRST	[POP   P,N		;ERROR--RESTORE WORD
		 JRST	E.UKK]		;AND ISSUE ERROR
	POP	P,N			;RESTORE NAME
	HRROI	P1,-TERM.N(T1)		;GET INDEX, FLAG /NOXYZ
	MOVX	T1,FS.NOS 		;GET YES/NO BIT
	TDNN	T1,TERM.D(P1)		;SEE IF YES/NO SWITCH
	 JRST	[MOVNI	T1,1		;ELSE PRETEND UNKNOWN
		 JRST	E.UKK##]	;FOR SCAN
KEYWDG:	MOVE	T2,TERM.D(P1)		;GET DEFAULT
	MOVEI	N,(T2)			;COPY INTO N
	MOVE	T1,TERM.M(P1)		;GET PROCESSOR OR TABLE POINTER
	TXNE	T2,FS.NOS		;SEE IF "NO" SWITCH
	JRST	[HLRZ N,P1		;IF SN STYLE, GET NO INDICATOR
		 MOVEI N,1(N)		;SET N=0 IF NO, 1 IF NOT NO
		 JRST KEYWDA]		;GO STUFF RESULT
	CAIN	C,":"			;SEE IF VALUE SPECIFIED
	JRST	KEYWD2			;YES--GO CHECK INTO IT
;HERE WHEN DEFAULT NEEDED
KEYWD1:	TXNE	T2,FS.VRQ		;SEE IF VALUE REQUIRED
	 JRST	E.SVR##			;YES--GIVE ERROR
	TLNN	T1,-1			;SEE IF MAX SET
	JUMPN	T1,KEYWDJ		;NO--DIRECT ACTION
	JRST	KEYWD8			;YES--GO STORE DEFAULT
;HERE WHEN VALUE SPECIFIED BY USER (MAY BE NULL)
KEYWD2:	;JUMPE	T1,E$$NMA		;IF NO VALUE LEGAL, GIVE ERROR
	JUMPG	T1,KEYWDJ		;IF SPECIAL PROCESSOR, GO DO IT

	PUSHJ	P,.SIXSW##		;VALUE IS ANOTHER KEYWORD--GET IT
	MOVE	T1,TERM.M(P1)		;REFETCH SUB-KEY POINTER
	PUSHJ	P,.NAME			;LOOK IT UP
	  JRST	E.UKK##			;ERROR
	SUB	T1,TERM.M(P1)		;DETERMINE INDEX AS VALUE
	MOVEI	N,(T1)			;PLACE IN VALUE (1,2,...)
	JRST	KEYWD8			;AND GO STORE IT AWAY

;HERE IF SN SWITCH TO LOOK FOR VALUES

KEYWDA:	JUMPE	N,KEYWD8		;IF NO, PROCEED (NO VALUES)
	CAIE	C,":"			;SEE IF VALUE COMING
	JRST	KEYWD8			;NO--THAT'S IT
KEYWDB:	PUSHJ	P,.SIXSW##		;GET VALUE AS NAME
	MOVE	T1,[IOWD YNTABL,YNTAB] 	;TRY YES-NO TABLE
	PUSHJ	P,.NAME			;LOOK UP NAME
	 JRST	E.UKK##			;UNKNOWN
	MOVEI	N,(T1)			;GET LOCATION OF MATCH
	SUBI	N,YNTAB			;GET OFFSET IN TABLE
	ANDI	N,1			;GET YES/NO SETTING
	JRST	KEYWD8			;RETURN THAT VALUE

;HERE TO GO TO SWITCH PROCESSOR
KEYWDJ:	PUSHJ	P,(T1)			;GO DO IT
	 JFCL				;GO STORE
;HERE TO STORE SWITCH
KEYWD8:	LDB	T1,TERM.P(P1)		;GET STORED VALUE
	CAME	T1,[-1]			;SEE IF SET
	 JRST	[CAME	T1,N		;SAME AS BEFORE?
		  SKIPE	INISCN		;IN SWITCH.INI?
		   JRST	.SWDON##	;YES--JUST FORGET
		 JRST	E.DSI##]	;NO--ERROR
	DPB	N,TERM.P(P1)		;NO--STORE VALUE
	JRST	.SWDON##		;AND RETURN W/O STORE

;TABLE OF YES/NO VALUES--MUST BE NO/YES PAIRS
YNTAB:	SIXBIT	/0/
	SIXBIT	/1/
	SIXBIT	/NO/
	SIXBIT	/YES/
	SIXBIT	/OFF/
	SIXBIT	/ON/
YNTABL==.-YNTAB
>;END IFN SETTTY			;[744]
;SUBROUTINE TO ASK FOR AND READ PASSWORD
;VALUES	T1=SIXBIT PASSWORD

CODGET:	PJUMPG	C,GET2WD	;[747] IF USER ALREADY TYPED, NO PROMPTS
	SKIPE	FL2741		;[546] IS THIS A 2741?
	  JRST	PW2741		;[546] YES - DO 2741 THINGS
	TLNE	F,FL.FDX	;SKIP IF NOT FDX LINE
	JRST	FDXCOD		;YES.
	MOVEI	T3,3		;THREE OVERLAYS
MASKLP:	PUSHJ	P,PRMASK	;PRINT THE MASK
	MOVX	T1,.CHCRT	;JUST A CR
	PUSHJ	P,.TCHAR##	;TYPE IT
	SOJG	T3,MASKLP	;GO BACK 3 TIMES
	PUSHJ	P,GET2WD	;COLLECT THE PASSWORD
	MOVEI	CH,"*"		;MASK FOR DISPLAY TERMINALS
	MOVEI	N,6		;COUNT
	PUSHJ	P,TYO		;PRINT ENOUGH TO ERASE PASSWORD
	SOJG	N,.-1		;LOOP
	PJRST	.TCRLF##	;[747] EASY

PW2741:	MOVEI	T1,[ASCIZ "Password: #$%&*@"]
	PUSHJ	P,PBACK6	;SEND 6 BACKSPACES
	PUSHJ	P,PRMASK	;PRINT A MASK
	PUSHJ	P,BACK6		;SEND 6 BACKSPACES
	PUSHJ	P,PRMASK	;PRINT A MASK
	PUSHJ	P,BACK6		;BACKSPACE OVER IT
	MOVEI	T1,[ASCIZ "######"] ;MAKE IT BLACK
	PUSHJ	P,PBACK6	; ..
	MOVEI	T1,[ASCIZ "@@@@@@"] ; ..
	PUSHJ	P,PBACK6
	JRST	CODCRL		;[747] READ PASSWORD

PBACK6:	PUSHJ	P,.TSTRG##	;TYPE STRING IN T1
BACK6:	MOVEI	T1,[BYTE (7)10,10,10,10,10,10,0]
	PJRST	.TSTRG##	;TYPE 6 BACKSPACES


;ROUTINE TO PRINT A MASK
PRMASK:	TIMER	T1,		;MUST MAKE MASK
	ADDB	T1,MSKMEM	;PROTECT AGAINST FAST SYSTEM
	TRO	T1,1		;FOR RANDOM NUMBERS
	MOVNI	T2,6		;6 CHARS LONG
MASK1:	IMULI	T1,-3		;RANDOM CHAR
	HRRZ	N,T1
	IDIVI	N,76		;NO SPACE OR QUEST MK
	MOVEI	CH,41(N+1)	;THE CHAR
	PUSHJ	P,TYO		;OUTPUT IT
	AOJL	T2,MASK1	;MAKE A LINE
	POPJ	P,0		;RETURN

FDXCOD:	MOVEI	M,[ASCIZ /Password: /]	;REQUEST CODE
	PUSHJ	P,MSG		;..
CODCRL:	PUSHJ	P,GET2WD	;[747] READ PASSWORD
	PJRST	.TCRLF##	;[747] CRLF AND RETURN
LOGBLK:	IOWD	LOGSWL,LOGSWN
	XWD	LOGSWD,LOGSWM
	XWD	0,LOGSWP
	SIXBIT	/LOGIN/		;[320] TYPE HLP:LOGIN.HLP ON /HELP
LOGBLN==.-LOGBLK

SCIBLK:	IOWD	COMLEN,COMLST
	XWD	SAOFST,'LGI'
	XWD	TTYGET,STYO
	XWD	0,0
	XWD	0,FLUSH	
	EXP	FS.ICL

COMLST:	<SIXBIT	/LOGIN/>
	<SIXBIT	/ATTACH/>
	<SIXBIT	/SESSION/>
COMLEN==.-COMLST

LOKBLK:	XWD	[WILDBK],0
	XWD	JUNK,SECBUF	;[422] THROW AWAY 4-WORD LOOKUP BLK SO
	XWD	.FXLEN,.RBSTS+1	;[422] IT WON'T OVERWRITE AUXACC.SYS DATA
	XWD	0,WLDPNT
LOKBLN==.-LOKBLK


IFN SETTTY,<			;[744]
TTYSWT:	TERM.N(P1)		;[744] SWITCH POINTERS FOR /SETTTY 
	TERM.P(P1)		;[744]
	TERM.M(P1)		;[744]
	TERM.D(P1)		;[744]
>;END IFN SETTTY		;[744]
;TABLES TO DRIVE SCAN

DM	COR,^D0,^D262143,^D262143	;[551]
DM	DPR,3,0,1
DM	FIL,.FXLEN,0,0
DM	LOC,77,0,0
DM	QTA,1,0,0
DM	TIM,0,0,^D60
DM	YN,1,0,1
DM	PRO,777,0,0			;[745]
DM	BUF,777,0,2			;[750]

IFN	SETTTY,<
DM	FLL,3,0,2		;[344] DEFAULTS FOR TTY CHAR. SWITCHES
DM	PSZ,^D63,^D63,^D24
DM	WTH,^D255,^D80,^D132
	>			;[344] END IFN SETTTY

	DEFINE SWTCHS,<
SP	ACCOUNT,<*P,<POINT ^D65-^D8,U.ACTS>>,ACCTSW,,FS.VRQ
SP	ASSIGN,<*F,DEVTAB>,ASSIGN,,FS.VRQ	;[470]
SL	ATTACH,<*F,U.ATT>,ATT,ATTASK
SP	BATNAM,<*F,U.BNAM>,BATNAM,,FS.VRQ	;BATCH ONLY - BATCH JOB NAME
SP	BATSEQ,<*F,U.BSEQ>,.SWDEC##,,FS.VRQ	;BATCH ONLY - BATCH SEQUENCE NUMBER
SP	CORE,<*F,U.CORE>,.SWCOR##,COR,FS.VRQ
SN	DEFER,<*F,U.DFER>,
SP	DEFBUFFER,<*F,U.DFBU>,.SWDEC##,BUF,	;[750]
SP	DEFPROT,<*F,U.DFPR>,.SWOCT##,PRO,FS.VRQ	;[620]
SL	DSKFUL,<*F,U.DFUL>,DSKF,DSKFPA
SP	DSKPRI,<*F,U.DPRI>,SWDSKP,DPR,FS.VRQ
SN	GUIDELINE,<*F,U.GUID>
SP	LIB,<*F,LIBSPC>,.SWFIL##,FIL,FS.VRQ
SN	LIMIT,<*F,U.LIMIT>
SP	LOCATE,<*F,U.STA>,.SWOCT##,LOC,FS.VRQ
SP	NAME,<*P,<POINT ^D65-2,U.NAME>>,.SIXQW##,,FS.VRQ
SN	NEW,<*F,U.NEW>,
SS	NOLIB,<*F,LIBSPC+.FXDIR>,0
SP	NOTE,<*F,NOTSPC>,.SWFIL##,FIL,FS.VRQ
SL	NOTICE,<*F,U.NOTC>,NOTC,0,FS.VRQ	;[450] /NOTICE:
SS	NOWATCH,<*F,U.NWAT>,0
IFN	PSWCHG,<				;[557]
SN	PASSWORD,<*F,U.NPSW>, 			;[557]
	>					;[557] END IFN PSWCHG
SP	PATH,<*F,PTHSPC>,.SWFIL##,FIL,FS.VRQ	;[456] /PATH SWITCH
SP	*PHYSICAL,<*F,U.CPPL>,.SWCOR##,COR,FS.VRQ
SP	QUOTA,<*F,U.QTA>,.SIXSW##,QTA
SP	REMARK,<*P,<POINT ^D65-^D8,U.RMRK>>,RMRKSW,,FS.VRQ
SP	REQID,<*F,U.BREQ>,.SWDEC##,,FS.VRQ		;BATCH ONLY - BATCH REQUEST ID
SN	SCAN,<*F,U.SCAN>, 
SP	SFDPROT,<*F,U.SFDP>,.SWOCT##,,FS.VRQ
SL	SPOOL,<*F,U.SPL>,SPOL,0,FS.OBV
SN	STR,<*F,U.STR>, 
SN	SYS,<*F,U.SYS>, 
SP	TIME,<*F,U.TIME>,.SWDEC##,TIM,FS.VRQ
SP	UFDPROT,<*F,U.UFDP>,.SWOCT##,,FS.VRQ	;[553]
SP	VIRTUAL,<*F,U.CVPL>,.SWCOR##,COR,FS.VRQ
SL	WATCH,<*F,U.WAT>,WTCH,0,FS.OBV


;**NOTE** DO NOT ADD NEW SETTTY SWITCHES HERE. ADD THEM IN THE OTHER
;KEYWORD TABLE ON THE NEXT PAGE. SOMEDAY THE STAND-ALONE SETTTY SWITCHES
;LISTED BELOW MAY BE REMOVED

IFN	SETTTY,<		;[344] TTY CHARACT. SWITCHES
SN	ALTMODE,<*F,U.ALTM>,
SN	BLANK,<*F,U.BLNK>,
SN	CRLF,<*F,U.CRLF>,
SN	DEBREAK,<*F,U.DBRK>,
SN	ECHO,<*F,U.ECHO>,
SP	FILL,<*F,U.FILL>,.SWOCT##,FLL
SN	FORM,<*F,U.FORM>,
SN	GAG,<*F,U.GAG>,
SN	LC,<*F,U.LC>,
SN	PAGE,<*F,U.PAGE>,
SP	PAGESIZE,<*F,U.PGSZ>,.SWDEC##,PSZ,FS.VRQ
SL	RCVSPEED,<*F,U.RSPD>,SPED,0,FS.VRQ
SN	RTCOMP,<*F,U.RTC>,
SL	SPEED,<*F,U.SPED>,SPED,0,FS.VRQ
SN	SETTTY,<*F,U.SETT>,			;[744]
SN	TABS,<*F,U.TABS>,
SN	TAPE,<*F,U.TAPE>,
SP	TERMINAL,,TERMSW,,FS.VRQ		;[744]
SN	TTDEFER,<*F,U.TTDE>,
SP	TYPE,<*F,U.TYPE>,.SWSIX##,,FS.VRQ	;[675]
SP	WIDTH,<*F,U.WDTH>,.SWDEC##,WTH,
SL	XMTSPEED,<*F,U.XSPD>,SPED,0,FS.VRQ
	>			;[344] END IFN SETTTY

>
	DOSCAN(LOGSW)		;EXPAND TABLES

;[744] ADD ALL NEW TERMINAL SWITCHS HERE
IFN SETTTY,<
DEFINE SWTCHS,<
SN	ALTMODE,<*F,U.ALTM>,
SN	BLANK,<*F,U.BLNK>,
SN	CRLF,<*F,U.CRLF>,
SN	DEBREAK,<*F,U.DBRK>,
SN	DEFER,<*F,U.TTDE>,
SN	DISPLAY,<*F,U.DISP>,
SN	ECHO,<*F,U.ECHO>,
SP	FILL,<*F,U.FILL>,.SWOCT##,FLL
SN	FORM,<*F,U.FORM>,
SN	GAG,<*F,U.GAG>,
SN	LC,<*F,U.LC>,
SS	NOFILL,<*F,U.FILL>,0			;[747]
SN	PAGE,<*F,U.PAGE>,
SP	PAGESIZE,<*F,U.PGSZ>,.SWDEC##,PSZ,FS.VRQ
SL	RCVSPEED,<*F,U.RSPD>,SPED,0,FS.VRQ
SN	RTCOMP,<*F,U.RTC>,
SL	SPEED,<*F,U.SPED>,SPED,0,FS.VRQ
SN	TABS,<*F,U.TABS>,
SN	TAPE,<*F,U.TAPE>,
SN	TIDY,<*F,U.TIDY>,			;[747]
SP	TYPE,<*F,U.TYPE>,.SIXSW##,,FS.VRQ	;[675]
SN	UC,<*F,U.UC>,				;[747]
SP	WIDTH,<*F,U.WDTH>,.SWDEC##,WTH,
SL	XMTSPEED,<*F,U.XSPD>,SPED,0,FS.VRQ
>;END DEFINE SWTCHS
	DOSCAN	(TERM.)		;[744] EXPAND THE SUBTABLE POINTERS
>;END IFN SETTTY

KEYS	ATT,<ASK,IGNORE>
KEYS	DSKF,<ERROR,PAUSE>
KEYS	SPOL,<LPT,PLT,PTP,CDP,CDR>
KEYS	WTCH,<FILES,MTA,VERSION,WRITE,READ,WAIT,RUN,DAY>
KEYS	NOTC,<ALWAYS,SOMETIMES,NEVER>

IFN	SETTTY,<
KEYS	SPED,<50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,EXTA,EXTB>
	>			;[344] END IFN SETTTY

	WCHLSH==:^D17-WTCHDA	;AMOUNT TO SHIFT BITS RETURNED BY
				; SCAN FOR SETUUO

;LOWSEG STORAGE FOR LGNSCN
	RELOC
MSKMEM:	BLOCK	1	;MEMORY FOR MASK PRINTER
	RELOC
	PRGEND
	TITLE	LGNACT - Accounting module for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM

	LGNDCL

;ENTER HERE WITH	T3=TTBITS FOR TTY OR CONTROL JOB TTY

TTYGO:	MOVE	T2,STATES	;GET STATES BITS
	TLNE	F,L.OPR!L.SOPR	;OPER OR HIS SUB?
	TLNE	F,FL.BAT	;[700]  AND NON-BATCH JOB?
	SKIPA			;[700]  NO--CONTINUE
	JRST	PPNGO		;[505] YES. OK TO GO
	TXNN	T2,ST%NLG	;NO LOGIN?
	JRST	SYSAVL		;NO--SYSTEM IS AVAIL
	STOP	SNA,<System not available>
SYSAVL:	TXNE	T3,GL.DSL!GL.REM	;NON-LOCAL?
	TXNN	T2,ST%NRL	;AND STATES SAYS LOCAL ONLY?
	JRST	NOTRMT		;NO. OK
	FATAL	NRU,<No remote users. Try again later.>
NOTRMT:	TLNE	F,FL.ATT	;[555] SKIP IF LOGIN, NOT IF ATTACH
	  JRST	PPNGO4		;[654] DON'T NEED TO CHECK LOGMAX FOR ATTACH
	PUSH	P,T2		;SAVE STATES WORD

IFN	BATMAX, <		;[664] CHECK BATMAX??
	TLNE	F,FL.BAT	;[505] BATCH JOB?
	  JRST	BACHEK		;[505] YES - DO BATCH CHECKING
>
	MOVX	T1,%CNLNM	;NUMBER OF JOBS NOW
	GETTAB	T1,		;GET FROM MONITOR
	  JRST	NT2MNY		;IF IT FAILS ASSUME OK
	MOVX	T2,%CNLMX	;GET MAXIMUM
	GETTAB	T2,		; ..
	  JRST	NT2MNY		;ALL IS WELL IF FAILS
	SUB	T2,T1		;GET NUMBER OF FREE JOB SLOTS
	JUMPG	T2,NT2MNY	;[665] JUMP IF BELOW LIMIT
	MOVEI	T1,3		;1=ALWAYS, 2=SOMETIMES, 3=NEVER
	MOVEM	T1,U.NOTC	;Simulate /NOTICE:NEVER
	FATAL	JCE,<Job capacity exceeded>

	IFN	BATMAX,<	;[664] [505] CHECK BATMAX??
BACHEK:	MOVX	T1,%CNBNM	;[505] GET BATNUM
	GETTAB	T1,		;[505] FROM MONITOR
	  JRST	NT2MNY		;[505] ..
	MOVX	T2,%CNBMX	;[505] GET BATMAX
	GETTAB	T2,		;[505] FROM MONITOR
	  JRST	NT2MNY		;[505] ..
	CAMGE	T1,T2		;[505] BATNUM .GT. BATMAX?
	  JRST	NT2MNY		;[505] NO - ALL'S WELL
	MOVEI	T1,3		;1=ALWAYS, 2=SOMETIMES, 3=NEVER
	MOVEM	T1,U.NOTC	;Simulate /NOTICE:NEVER
	REQUE	JCX,<Job capacity exceeded>
	>			;[556] END IFN BATMAX

NT2MNY:	POP	P,T2		;RESTORE STATES
	TLNE	F,FL.BAT	;BATCH JOB?
	JRST	PPNGO1		;YES, CHECKING ALREADY DONE
	TXNN	T2,ST%BON	;NO. BATCH ONLY ONES ALLOWED?
	JRST	PPNGO		;NO
	FATAL	OBU,<Only batch users may LOGIN.>
PPNGO:	MOVX	T1,%CNLNM	;[650] GET LOGNUM
	GETTAB	T1,		;[650]  ..
	  JRST	PPNGO4
	MOVX	T2,%CNLMX	;[650] NOW GET LOGMAX
	GETTAB	T2,
	  JRST	PPNGO4
	SUB	T2,T1		;[650] CALCULATE NO. OF FREE JOB SLOTS
	MOVX	T1,%CNBMN	;[650] GET BATMIN
	GETTAB	T1,
	  JRST	PPNGO4
	MOVX	T4,%CNBNM	;[676] GET BATNUM
	GETTAB	T4,		;[676]
	  JRST	PPNGO4		;[676]
	SUB	T1,T4		;[676] SUBTRACT BATNUM FROM BATMIN
	CAMLE	T2,T1		;[650] FREE SLOTS .LE. BATMIN?
	  JRST	PPNGO4		;[650] NO, ALL OK
	FATAL	TJX,<Timesharing job capacity exceeded>

PPNGO4:	MOVX	T1,%NSKTM	;FIND OUT IF SYSTEM IS DOWN
	GETTAB	T1,
	  SETZ	T1,
	JUMPE	T1,PPNGO1	;OK TO GO
	JUMPG	T1,PPNGO3	;JUMP IF SYSTEM GOING DOWN SOON
	TLNN	F,L.OPR!L.SOPR	;[606] IF OPR OR SUB OF OPR OR 1,2
 	 TXNN	T3,GL.REM!GL.DSL	;[657] OR LOCAL TTY
	  JRST	PPNGO1		;[606] THEN LET HIM IN ANYWAY
	STOP	TIO,<Timesharing is over>
PPNGO3:	CAIL	T1,^D24*^D60	;OVER A DAY TO GO?
	JRST	PPNGO1		;YES--SKIP WARNING
	INFO	TCI,<Timesharing will cease in >
	  JRST	PPNGO1
	IDIVI	T1,^D60
	MOVE	T4,T2		;SAVE REMAINDER (MINUTES)
	JUMPE	T1,PPNGO2	;SEE IF HOURS NONZERO
	PUSHJ	P,.TDECW##	;YES. PRINT HOURS
	MOVEI	M,[ASCIZ . hours .]
	PUSHJ	P,MSG
PPNGO2:	MOVE	T1,T4		;GET MINUTES
	PUSHJ	P,.TDECW##
	MOVEI	M,[ASCIZ \ minutes.]
\]
	PUSHJ	P,MSG
;FALL INTO PPNGO1
;HERE TO BEGIN CHECKING PPN

PPNGO1:	TLNE	F,FL.ATT	;[555] LOGIN OR ATTACH?
	  JRST	ATTCHK		;[555] ATTACH


;HERE TO COMPUTE BIT IN TIMES WORD TO CHECK

	MOVE	T1,STATES	;[354] GET STATES WORD
	TXNN	T1,ST%NOP	;[354] IS THERE AN OPERATOR?
	JRST	LOGIN3		;[354,360] YES -- PROCEED
	INFO	NOC,<No operator coverage.>
	  JFCL			;[432] DO A CRLF

LOGIN3:	MOVE	P,PDPLST	;[565] RE-INIT STACK
	TLZ	F,FL.WKD+FL.RAS	;TRY AGAIN ENTRY
	PUSHJ	P,.GTNOW##	;GO GET TODAYS DATE
	HLRZ	T1,T1		;SAVE THE DAY
	IDIVI	T1,7		;FIGURE OUT THE DAY
	CAIL	T2,3		;[316] SATURDAY??
	CAILE	T2,4		;[316]  OR SUNDAY??
	TLO	F,FL.WKD	;NO--FLAG AS WEEKDAY
	MOVEM	T2,SAVEDA	;SALT AWAY
	MSTIME	T1,
	IDIV	T1,[EXP ^D1000*^D60*^D60]
	MOVSI	T2,400000	;MAKE A BIT FOR THE CURRENT HOUR
	TLNN	F,FL.WKD	;WEEKDAY?
	MOVEI	T2,4000		;NO. USE LOW 12 BITS
	TLNN	F,FL.WKD	;WEEKDAY?
	ASH	T1,-1		;NO. USE TWO-HOUR SHIFTS
	MOVNS	T1
	LSH	T2,0(T1)	;PUT BIT IN TUNE WITH TIME
	MOVEM	T2,NOWBIT	;SAVE.

	PUSHJ	P,PARSE##	;GO PARSE LOGIN LINE
ATTCHK:	TRZ	F,R.FMT		;FROM NOW ON, ERRORS ARE REAL, NOT FORMAT
	MOVX	T1,ST%IMG
	TDNN	T1,STATES	;SKIP IF NEW SCANNER SERVICE
	TLNE	PP,-2		;SKIP IF  PROJ 1
	JRST	CHECKS		;NOT PROJ 1, GO AHEAD
	MOVX	T1,GL.ITY
	TDNE	T1,TTBITS	;DONT ALLOW PROJ 1 ON PTY
	JRST	NOREMT		;IN OLD SCANNER
CHECKS:	CAME	PP,SYSPPN	;SYSPPN CAN ALWAYS LOGIN
	CAME	PP,MFDPPN	;BUT IF MFDPPN IS NOT SYSPPN,
	JRST	STACCT
	JRST	NOMFDP		;DONT ALLOW MFDPPN
	SUBTTL	Search ACCT.SYS

;HERE TO SEARCH ACCT.SYS FOR USER'S ENTRY

STACCT:	PUSHJ	P,CLRRIB	;[540] CLEAR EXTENDED LOOKUP BLOCK
	MOVE	T1,[SIXBIT /ACCT/]	;LOOK FOR THE SYSTEM FILE
	MOVEM	T1,SECBUF+.RBNAM	;[540] PUT INTO LOOKUP BLOCK
	MOVSI	T1,(SIXBIT /SYS/)	;[540] GET EXTENSION
	MOVEM	T1,SECBUF+.RBEXT	;[540] STUFF IT
	MOVE	T1,SYSPPN	;[540] GET SYS: PPN
	MOVEM	T1,SECBUF+.RBPPN;[540] STUFF IT
	MOVEI	T1,.RBTIM	;[540] GET ARGUMENT COUNT
	MOVEM	T1,SECBUF+.RBCNT;[540] ..
	SETZM	ENTRY		;[540] CLEAR ENTRY IN CASE NO ACCT.SYS
	MOVE	T4,[XWD ENTRY,ENTRY+1]
	BLT	T4,ENTRY+MAXENT-1
	LOOKUP	UFD,SECBUF	;[540] TRY TO READ IT
	  JRST	NOSYS		;CANT. GO DIE.
	MOVE	T1,SECBUF+.RBSIZ;[540] GET NO. OF WORDS WRITTEN
	ADDI	T1,^D127	;[540] COUNT 1 FOR LAST PARTIAL BLOCK
	IDIVI	T1,^D128	;[540] CONVERT TO BLOCKS
	MOVEM	T1,ACCTLN	;ALWAYS SAVE BLOCKS
	SETZM	ACCKNT		;CLEAR COUNT OF READS ON ACCT.SYS
	TLO	F,FL.ACC	;SET FLAG TO NOTE READING ACCT.SYS

;HERE TO FIND DIRECTORY OF ACCT.SYS, IF ANY,
;	AND BUILD IT IN THE HI SEGMENT IF NONE.
IFN	FASTLG,<
	MOVE	T2,SECBUF+.RBTIM;[540] GET CREATION DATE-TIME
	CAME	T2,W.ACCT	;[540] COMPARE WITH LAST DATE-TIME
	  JRST	REBILD		;[540] IF CHANGED, REBUILD TABLE
	SKIPE	DACCFL		;IF TABLE NOT BUILT
	CAME	T1,DACCL	;OR LENGTHS DIFFER
	JRST	REBILD		;BUILD TABLE IMMEDIATELY
	PUSHJ	P,SNOOZE	;ELSE SLEEP
	JRST	LUKUPP		;UNTIL TABLE FINISHED
				;OR WE GET IMPATIENT
REBILD:	SETZM	RDHED		;[444] FORCE NEXT READ TO INPUT
	PUSHJ	P,LOK		;[444] LOCK OUT CTRL-C, WRITE-ENABLE HI SEG
	SETOM	SCDBLT		;[463] INVALIDATE SCHED. TABLE
	SETOM	DACCFL		;INDICATE BUILD-IN-PROGRESS
	AOSG	DLOCK		;CHECK LOCK
	JRST	BDACCT		;GO BUILD TABLE
	PUSHJ	P,SNOOZE	;IN-PROGRESS, WAIT AWHILE
	JRST	RSPROT		;GOT BUILT WHILE WE WAITED
				;FALL OUT HERE IF NO ACTION IN 10 SECS
BDACCT:	MOVE	T1,ACCTLN	;LENGTH OF ACCT.SYS
	MOVEM	T1,DACCL	;SAVE IN HI-SEG
	LSH	T1,1		;DOUBLE BECAUSE WE NEED 2 DIRECTORIES
	SKIPN	WD,PDACC	;UNLESS WE'VE DONE THIS BEFORE,
	HLRZ	WD,.JBHRL	;[424]  GET HIGHEST WE GOT
	TRO	WD,400000	;[424]
	MOVEM	WD,PDACC	;SETUP POINTER TO DIRECTORIES
	ADDI	T1,(WD)		;THAT'S HOW MUCH WE NEED NOW
	HRRZ	WD,.JBHRL
	CAIG	T1,(WD)		;DO WE NEED MORE?
	JRST	COREOK		;NO, DON'T BOTHER THE MONITOR
	HRLZS	T1		;SETUP TO GET MORE
	CORE	T1,
	  JRST	NOSYS		;FATAL ERROR-INSUFFICIENT CORE
COREOK:	PUSHJ	P,RDUFD		;GET FORMAT WORD
	  JRST	NOSYS		;WHA???
	HRRZM	WD,ENTSIZ	;SAVE SIZE OF ENTRIES IN ACCT.SYS
	HLRZS	WD		;GET FORMAT IN RIGHT
	CAIL	WD,ACC506	;[356] IS THIS ACCT.SYS A FORMAT
	CAILE	WD,ACC602	;[356] WE KNOW ABOUT?
	JRST	BADFOR		;[356] NO -- CROAK
	CAIL	WD,ACC602	;[356] SETTING 6.02 STUFF?
	SETOM	EQACT		;[356] YES -- SET FLAG TO REMEMBER
	CAIL	WD,ACC601	;IS THIS THE NEW FORMAT
	SETOM	NEWACT		;YES--SET THE FLAG
	MOVEI	T1,200		;BLOCK LENGTH
	IDIV	T1,ENTSIZ	;OVER ENTRY SIZE IS ENTRIES PER BLOCK
				;T2 GETS REMAINDER
	HRRZ	T1,PDACC	;GET ADDR OF TABLE
	MOVEI	T3,1		;FIRST WORD OF BLOCK IS ALREADY USED
NXTABC:	MOVE	PP,UFDBUF(T3)	;GET FIRST PPN OF THIS BLOCK
	MOVEM	PP,0(T1)	;STORE IN TABLE
	SUB	T3,T2		;POINT TO FIRST PPN IN NEXT BLOCK
	JUMPGE	T3,.+2		;DON'T LET IT GO NEGATIVE
	ADD	T3,ENTSIZ	;KEEP RESULT MODULO ENTSIZE
	SETZM	RDHED		;FORCE A READ
	PUSHJ	P,RDUFD
	  JRST	.+2		;ALL DONE-EOF
	AOJA	T1,NXTABC	;LOOK FOR PPN IN THIS BLOCK
	SETZB	T1,DAUXFL	;FORCE REBUILD OF AUX TABLE
	HRLOM	T1,DACCFL	;SET TABLE-FINISHED SW
	SETOM	DLOCK		;UNLOCK THE CODE
	MOVE	T1,SECBUF+.RBTIM;[540] GET CREATION DATE-TIME OF ACCT.SYS
	MOVEM	T1,W.ACCT	;[540] SAVE IN HI-SEG
RSPROT:	PUSHJ	P,UNLOCK	;[444] UNLOCK CTRL-C
;HERE TO FIND USER'S PPN IN TABLE

LUKUPP:	MOVE	PP,PPN		;GET USER'S PPN
	TRNE	PP,1B18		;WILD PPN?
	HRRI	PP,UNIPRG	;YES--LOOK FOR RIGHT GUY
	MOVN	T1,DACCL	;LENGTH OF TABLE
	HRLZ	T1,T1		;[371] FOR AOBJN LOOP
	HRR	T1,PDACC	;GET ADDR OF TABLE
	CAML	PP,0(T1)	;SCAN FOR HIGHER PPN
	AOBJN	T1,.-1		;CONTINUE SEARCH IF NOT
	JUMPL	T1,NLSTPP	;IS THIS THE LAST ENTRY IN THE TABLE?
	SKIPN	-1(T1)		;IF SO, IS PPN REACT'S TRAILING ZERO?
	SOJ	T1,		;YES TO BOTH. MUST BE IN PRECEDING BLOCK
NLSTPP:	HRRZ	T1,T1		;[371] DISCARD COUNTER IN A LEFT
	SUB	T1,PDACC	;GET OFFSET WITHIN TABLE
	SOJL	T1,PPERR1	;BEWARE THE RIDICULOUS
	HRRZM	T1,ACCKNT	;SET POINTER INTO ACCT.SYS
	USETI	UFD,1(T1)	;SETUP FOR DESIRED BLOCK

;	FIND THE ADDRESS OF THE FIRST PPN IN THIS BLOCK

	MOVE	T4,ENTSIZ	;JUST TO HAVE IT THERE
	HRRZ	T2,T1		;COPY BLOCK COUNT
	ASH	T2,7		;TIMES 200 (BLOCK LENGTH)
	IDIV	T2,T4
	MOVN	T2,T3		;NEGATIVE REMAINDER
	AOJGE	T2,.+2		;ALLOW ONE FOR FORMAT WORD
	ADD	T2,T4		;GET POINTER INTO BLOCK
	MOVNI	T3,177(T4)	;-(BLOCK LEN + ENTSIZ - 1)
	IDIV	T3,T4		;T3 GETS -(NO OF ENTRIES/BLOCK)
	SETZM	RDHED		;FORCE A READ
	PUSHJ	P,RDUFD		;GET THE RIGHT BLOCK
	  JRST	PPERR1		;I HOPE IT'S HIS FAULT
	MOVE	WD,UFDBUF(T2)	;GET FIRST PPN OF BLOCK
	ADD	T1,PDACC	;POINT DIRECTLY TO TABLE ENTRY
	CAME	WD,0(T1)	;CHECK TABLE ACCURACY
	JRST	BADTAB		;IT LIED--REBUILD IT
	HRLI	T2,-200(T2)	;REMAINING COUNT IN BLOCK
	HRRI	T2,UFDBUF-1(T2)	;MAKES IOWD FOR FIRST PPN OF BLOCK
	MOVEM	T2,RDHED	;THAT ENABLES USE OF RDUFD, WHICH
				;MASKS BLOCK BOUNDARIES
>;*** END OF CONDITIONAL ON FASTLG
;HERE TO FIND USER'S ENTRY (IF ANY)

RDACCT:	MOVN	T1,ENTSIZ	;GET SIZE AS A COUNT
	HRLZS	T1		;FOR AOBJN
RDACT1:	PUSHJ	P,RDUFD		;GET A WORD
	  JRST	PPERR1		;GOT TO EOF
	MOVEM	WD,ENTRY(T1)	;STORE IN TEMP BLOCK
	IFN	PSWCHG,<	;[610] IF ALLOWING /PASSWORD
	HRRZ	T2,T1		;[624] STRIP OFF COUNT
	CAIE	T2,CODWRD	;[624] DID WE JUST READ THE PSWD?
	  JRST	RDACT2		;[610] NO
	HRRZ	T2,RDHED	;[610] YES: GET PTR TO WORD WITHIN BLOCK
	MOVEM	T2,SAVPOS	;[610] SAVE FOR LATER
	MOVE	T2,ACCKNT	;[610] PICK UP BLOCK THIS IS IN
	MOVEM	T2,SAVBLK	;[610] AND REMEMBER FOR LATER
RDACT2:	>			;END IFN PSWCHG
	AOBJN	T1,RDACT1	;GET REST OF ENTRY
	MOVE	T1,ENTRY+PPWRD	;CHECK FOR THE PPN
	HLRZ	T2,T1		;PROJ. IN FILE
	HLRZ	T4,PPN		;PROJ SUPPLIED
	CAMLE	T2,T4		;PASSED IT YET?
	JRST	PPERR1		;YES. NOT THERE.
	CAMN	T1,PPN		;IS THIS IT?
	JRST	PPNHIT		;YES. LOOK AT ENTRY
	CAME	T2,T4		;SAME PROJECT
	JRST	NXTPP		;NO. DON'T LOOK FOR #
	MOVE	WD,PPN		;PICK UP PPN
	TRNN	WD,1B18		;WILD ENTRY?
	JRST	[HRRZ	T2,T1	;GET PROGRAMMER NUMBER IN FILE
		HRRZ	T4,PPN	;GET PROGRAMMER NUMBER USER TYPED
		CAMLE	T2,T4	;HAVE WE PASSED IT BY YET?
		JRST	PPERR1	;YES. NON-EXISTANT PPN
		JRST	NXTPP]	;NO. READ NEXT ENTRY
	HRRZI	T1,(T1)		;COPY PROG NBR.
	CAIN	T1,UNIPRG	;MATCH WILD NO
	JRST	PPNHIT		;YES. LOOK AT ENTRY
IFE	FASTLG,<
	JRST	RDACCT		;GO FOR NEXT
NXTPP==	RDACCT	>
IFN	FASTLG,<
NXTPP:	AOJL	T3,RDACCT	;MORE IN THIS BLOCK?

;	WE HAVE NOW READ AN ENTIRE BLOCK WITHOUT FINDING THIS PPN
;	EITHER THE TABLE WAS INCORRECT, OR PPN DOESN'T EXIST
;	ACCKNT points to block we are using

	MOVE	T1,ACCKNT	;GET TABLE POINTER
	ADD	T1,PDACC	;ADDRESS THE TABLE
	MOVE	T1,-1(T1)	;[751]GET FIRST PPN THIS BLOCK
	CAMN	T1,ENTRY+PPWRD
	JRST	PPERR1		;IF MATCH, TABLE IS OK, SO PPN IS BAD
	PUSHJ	P,RDUFD		;HOWEVER, OUR ESTIMATE OF ENTRIES/BLOCK
	  JRST	PPERR1		;  MAY BE OFF BY 1, SO CHECK THE NEXT
	MOVE	T1,ACCKNT	;READ MAY HAVE INCREMENTED BLOCK NO
	ADD	T1,PDACC	;POINT INTO TABLE AGAIN
	CAMN	WD,-1(T1)	;[751]IS TABLE CORRECT FOR THIS BLOCK?
	JRST	PPERR1		;PPN IS WRONG
BADTAB:	USETI	UFD,1		;PREPARE TO SCAN ENTIRE FILE
	JRST	REBILD		;AND BUILD A NEW TABLE
>;*** END OF CONDITIONAL ON FASTLG
	SUBTTL	Check ACCT.SYS entry
;HERE TO DECIDE IF USER MAY LOGIN

PPNHIT:	TLZ	F,FL.ACC	;Clear flag to stop counting
	HLRZ	T1,ENTRY+XPDWRD	;GET EXPIRATION DATE OF PPN
	CAML	T1,TDATE	;[477] SKIP IF DATE L TODAY
	JRST	NOTEXP		;PPN IS OK
	FATAL	PHE,<PPN has expired>
NOTEXP:	;Give warning if PPN is about to expire
	SUBI	T1,^D31		;make exp look like 1 mon. earlier
	CAML	T1,TDATE	;skip if we're close
	 JRST	NOTWRN		;OK, no need for warning
	WARN	PWE,<PPN will expire on >
	 CAI			;non-JFCL noop to prevent CR
	HLRZ	T1,ENTRY+XPDWRD	;get expiration date
	PUSHJ	P,DATEPR	;print it
	PUSHJ	P,.TCRLF##	;final CR/LF
NOTWRN:	MOVE	T3,ENTRY+PROWRD
	MOVE	T1,TTBITS
	TXNN	T1,GL.ITY	;SKIP IF PTY
	JRST	ASKLOK		;SEE IF MAY LOGIN AT THIS TERMINAL
	TLNE	F,FL.BSJ	;SKIP IF NOT BATCH JOB SUBJOB
	 TRNE	T3,P.LGBS	;SKIP IF MAY NOT LOGIN AS SUBJOB
	  SKIPA			;[603] OK
	   JRST	NOLGTS
	TLNE	F,FL.BAT	;[603] BATCH JOB?
	 TRNE	T3,P.LGBT	;[603] YES - ALLOWED TO BE ONE?
	  SKIPA			;[603] NOT BATCH OR BATCH & ALLOWED TO BE
	   JRST	NOLGTS		;[603] BATCH & SHOULDN'T BE - COMPLAIN
	TLNE	F,FL.BAT	;[603] BATCH JOB?
	  JRST	CHEKIT		;[603] YES - CHECK TIMES TO LOG IN
	MOVE	T2,CNTLJP	;CONTROL JOB PPN
	CAME	T2,ALPPPN	;OK IF RUN BY JOB WITH ALL PRIVILEGES
	CAMN	T2,PPN		;OK IF RUN BY SAME PPN
	JRST	PSWOK
	MOVE	T1,CNTLJT	;GET LINE BITS FOR CONTROL JOB
ASKLOK:	TLNE	F,L.OPR!L.SOPR	;OK IF OPR OR SUB OF OPR OR 1,2
	JRST	LOGOK
	MOVEI	T2,P.LGLC	;LOCAL BIT
	TXNE	T1,GL.REM	;SKIP IF NOT REMOTE HARDWIRED TTY
	MOVEI	T2,P.LGRM	;REMOTE BIT
	TXNE	T1,GL.DSL	;SKIP IF NOT DATA SET TTY
	MOVEI	T2,P.LGDS
	TDNN	T2,T3		;SKIP IF MAY LOGIN AT THIS TERMINAL
	JRST	NOLGTS
CHEKIT:	MOVE	T2,ENTRY+TIMWRD	;[603] PICK UP TIME TO LOGIN WORD
	TDNE	T2,NOWBIT	;IS HE ALLOWED NOW?
	JRST	LOGOK		;YES
	FATAL	SOT,<PPN not valid for this time of day>

LOGOK:	TRNE	F,R.SESS	;SESSION COMMAND?
	JRST	PSWOK		;YES. SKIP PASSWORD AND NAME PROMPTING
	TLNE	F,FL.BAT	;BATCH JOB?
	JRST	PSWOK		;YES. DON'T PROMPT
	SKIPN	ENTRY+NM1WRD	;DO WE HAVE A DEFAULT NAME IN
				; ACCT.SYS
	JRST	GETNAM		;YES--HAVE HIM TYPE HIS NAME
	TRNN	T3,P.PWTS	;SKIP IF PASSWORD REQUIRED
	JRST	PSWOK		;NO, DONT ASK
	TRNN	T3,P.NMTS	;SKIP IF NAME REQUIRED
	JRST	GETCOD		;NO, GET PASSWORD
	JRST	GETNAM		;[323] YES, GET NAME AND PASSWORD

NOLGTS:	MOVEI	M,NOTSMS
	TLNE	F,FL.ATT	;SKIP IF LOGIN, NOT IF ATTACH
	MOVEI	M,NOTSAT	;MAY NOT ATTACH HERE MESSAGE
	MOVEI	CH,ERR.FT	;[612] FATAL ERROR
	PUSHJ	P,ERRLIN	;TYPE BEGINNING OF LINE
	MOVEI	M,NOTSM1	;LOCAL MESSAGE
	TRNE	T2,P.LGRM	;SKIP IF NOT REMOTE HARDWIRED TTY
	MOVEI	M,NOTSM2	;REMOTE MESSAGE
	TRNE	T2,P.LGDS	;SKIP IF NOT DATA SET TTY
	MOVEI	M,NOTSM3	;DATA SET MESSAGE
	TRNE	T2,P.LGRO	;SKIP IF NOT REMOTE CTY OR OPR
	MOVEI	M,NOTSM4	;REMOTE CTY OR OPR MESSAGE
	TLNE	F,FL.BSJ	;SKIP IF NOT BATCH JOB SUBJOB
	MOVEI	M,NOTSM5	;SUBJOB MESSAGE
	TLNE	F,FL.BAT	;[603] BATCH JOB?
	  MOVEI	M,NOTSM6	;[603] YES - GET RIGHT MESSAGE
	PUSHJ	P,MSG
	JRST	FLUSH
	SUBTTL	Write FACT file entry

ACCT:
	MOVEI	T1,UGLGN$	;TELL THE ACCOUNT DAEMON THIS JOB IS LOGGIN IN
	PUSHJ	P,.USAGE
IFN FACTSW,<
	PUSHJ	P,ACCTA		;PUT IN ACCOUNTING DATA
	MOVE	P2,FCTWD	;GET CONTROL WORD
	TXNN	F,R.SESS	;DON'T MAKE FACT ENTRY IF SESSION
	PUSHJ	P,.FACTR##	;[571] STICK IT INTO FACT.SYS
>;[647] END IFN FACTSW
	RELEAS	UFD,0		;MAKE WAY FOR LATER IO
	JRST	LAST
	SUBTTL	SWITCH.INI handling

;SUBROUTINE TO BE CALLED WHEN READY TO READ SWITCH.INI OF THE USER.  THIS
;	ALSO FILLS IN THE ACCOUNT AND REMARK IF REQUIRED BY THE TWO BITS
;	P.ACCT AND P.RMRK FOUND IN THE USER PROFILE WORD OF ACCT.SYS.  IF
;	AN ACCOUNT IS REQUIRED (OR THE USER TYPED ONE) AND VALIDATION IS SET IN
;	THE SYSTEM STATES WORD, A CALL TO LGNUSG TO VALIDATE THAT ACCOUNT WILL BE DONE.

SW.INI::TLNE	F,FL.ATT	;SKIP IF LOGIN, NOT IF ATTACH
	JRST	[MOVEI	T1,UGATT$	;NEED NO MORE FOR ATTACH
		PJRST	.USAGE]		;BUT FIRST TELL THE ACCOUNT DAEMON
	TXNN	F,R.SESS	;Skip if SESSION, not if LOGIN
	SKIPE	PTHSPC+.FXDIR	;[467] WAS THERE A /PATH SWITCH?
	  JRST	NOZAP		;[467] YES - LEAVE IT ALONE
	SETZM	PTHSPC		;[467] NO - CLEAR OUT /PATH SPEC
	MOVE	T1,[PTHSPC,,PTHSPC+1]	;[467] AREA SO .OSCAN WILL
	BLT	T1,PTHSPC+.FXLEN-1	;[470] FILL IT IN
NOZAP:	MOVE	T1,[XWD LOGBLN,LOGBLK]	;[442] POINTER TO SWITCH TABLE
	SETOM	INISCN		;[744] FLAG IN SWITCH.INI OSCAN
	TLNN	F,FL.WLD	;[442] FUNNY PPN'S GET NO SWITCH.INI
	PUSHJ	P,.OSCAN##	;[442] READ SWITCH.INI
	SETZM	INISCN		;[744] DONE WITH SWITCH.INI
	PUSHJ	P,PROMPT	;PROMPT THE USER FOR MORE STUFF IF NECESSARY
				; (ACCOUNT AND REMARK FOR NOW)
	MOVE	T1,ENTRY+NM1WRD	;[442] GET USER NAME
	MOVE	T2,ENTRY+NM2WRD	;[442] FROM ACCT.SYS
	MOVE	T3,U.NAME	;[442] GET NAME FROM SWITCHES
	AOSN	T3		;[442] NAME GIVEN IN SWITCH?
	  JRST	ACCT3		;[442] NO - USE ACCT.SYS VALUE
	MOVE	T1,U.NAME	;[442] YES - PICK UP NAME
	MOVE	T2,U.NAME+1	;[442] FROM SWITCHES
ACCT3:	MOVEM	T1,NAME		;[442] STORE NAME AWAY
	MOVEM	T2,NAME2	;[442] FOR LOGIN UUO
	SKIPN	U.PATH+.FXDIR+2	;WERE SFD'S TYPED WITHOUT /PATH?
	CAME	PP,U.PATH+.FXDIR ;OR IS PATH PPN .NE. LOGGED-IN PPN?
	  JRST	NOBLT		;[506] YES - USE IT
	MOVE	T1,[PTHSPC,,U.PATH]	;[457] NO - BLT IN THE PATH SPEC
	BLT	T1,U.PATH+.FXLEN-1	;[457] TYPED IN THE /PATH SWITCH
NOBLT:	TLNE	F,FL.ATT	;[710] SKIP IF NOT ATTACH
	POPJ	P,		;[710] DON'T CHECK LOGMAX FOR ATTACH
IFN	BATMAX,	<		;[710] CHECK BATMAX?
	TLNE	F,FL.BAT	;[710] BATCH JOB?
	JRST	BACHK1		;[710] YES - DO BATCH CHECKING
>
	MOVX	T1,%CNLNM	;[710] NUMBER OF JOBS NOW
	GETTAB	T1,		;[710] GET FROM MONITOR
	  POPJ	P,		;[710] ASSUME OK
	MOVX	T2,%CNLMX	;[710] GET MAXIMUM
	GETTAB	T2,		;[710] GET FROM MONITOR
	  POPJ	P,		;[710] ASSUME OK
	SUB	T2,T1		;[710] GET NUMBER OF FREE JOB SLOTS
	JUMPG	T2,.POPJ	;[710] CONTINUE IF BELOW LIMIT
	FATAL	JLE,<Job limit exceeded>
IFN	BATMAX,<		;[710] CHECK BATMAX?
BACHK1:	MOVX	T1,%CNBNM	;[710] GET BATNUM
	GETTAB	T1,		;[710] FROM MONITOR
	  POPJ	P,		;[710] ASSUME OK
	MOVX	T2,%CNBMX	;[710] GET BATMAX
	GETTAB	T2,		;[710] FROM MONITOR
	  POPJ	P,		;[710] ASSUME OK
	CAMGE	T1,T2		;[710] BATNUM .GT. BATMAX
	POPJ	P,		;[710] NO - CONTINUE
	REQUE	JLX,<Job limit exceeded>
>				;[710] END IFN BATMAX
	SUBTTL	PROMPT user for ACCOUNT and REMARK

;PROMPT - ROUTINE TO BE CALLED IN CASE USER HAS TO BE PROMPTED FOR ANYTHING
;	MORE AFTER SYSTEM ACCESS CHECKING AND READING SWITCH.INI.
;	THE USERS'S SEARCH LIST HAS ALREADY BEEN SET UP, BUT NO UFD HANDLING
;	HAS TAKEN PLACE YET.

PROMPT:	PUSHJ	P,GETACT	;PROMPT THE USER FOR ACCOUNT IF REQUIRED.
				;THE ACCOUNT, IF GIVEN, WILL ALSO BE VALIDATED
	PUSHJ	P,GETRMK	;PROMPT FOR THE REMARK IF REQUIRED
	POPJ	P,
	SUBTTL	Get the account string

;GETACT - SUBROUTINE TO BE CALLED TO CHECK IF USER NEEDS TO BE PROMPTED FOR
;	AN ACCOUNT.  IF VALIDATION IS REQUIRED AND AN ACCOUNT IF FURNISHED, THE
;	ACCOUNT DAEMON WILL BE ASKED TO VALIDATE.

GETACT:	TRO	F,R.FMT		;INDICATE THIS IS ONLY FORMAT ERRORS
	MOVE	T1,U.ACTS
	AOJN	T1,GETAC3	;HAS USER TYPED AN ACCOUNT SWITCH OR HAD IT IN SWITCH.INI?
 	SETZM	U.ACTS		;NO. NOW ZERO THE ACCOUNT STRING AREA
	MOVE	T1,[U.ACTS,,U.ACTS+1]
	BLT	T1,U.ACTS+7
	MOVE	T1,ENTRY+PROWRD	;GET PROFILE WORD
	TXNN	T1,P.ACCT	;IS ACCOUNT STRING REQUIRED?
	POPJ	P,		;NO. JUST RETURN
	MOVE	T1,TTBITS	;IF WE ARE A PTY, PROMPTING WILL CAUSE
	TXNE	T1,GL.ITY	; BATCON, OPSER, ETC. TO DO ERROR REPORTING
	JRST	GETAC2		; SO, JUST TRY FOR A CONTROLLING JOB'S ACCOUNT
	MOVEI	M,[ASCIZ /Account: /]	;PROMPT THE USER
	PUSHJ	P,MSG		; ..
	MOVEI	M,[ASCIZ/a valid account string/]
	MOVEM	M,HELP		;HELP TEST
	SETSTS	TTY,0		;TURN ON ECHO
	OUTPUT	TTY,		;FORCE OUTPUT
	PUSHJ	P,.SAVE2##
	MOVE	P1,[POINT 7,U.ACTS]
	MOVEI	P2,^D39		;MAXIMUM LENGTH IS 39 CHARACTERS
GETAC1:	PUSHJ	P,.TICHE##	;GET CHARACTER
	JUMPLE	C,GETAC3	;DONE WITH INPUT?
	CAIGE	C,176		;NO. CHECK FOR ILLEGAL CHARACTERS
	CAIGE	C," "
	JRST	LGNICA		;BAD CHARACTER. GO REPORT IT AND BOMB OUT THE USER
	IDPB	C,P1		;NOW STORE CHARACTER
	SOJGE	P2,GETAC1	;LOOP UNTIL WE HAVE THE WHOLE THING
	JRST	LGNATL		;ACCOUNT IS TOO LONG

;HERE TO VALIDATE THE ACCOUNT IF NECESSARY.  IF AN ACCOUNT WAS REQUIRED BUT
;	HASN'T BEEN ENTERED YET, SEE IF THE JOB HAS A CONTROLLING JOB.  IF THE
;	JOB IS CONTROLLED BY ANOTHER AND BOTH JOBS ARE UNDER THE SAME PPN,
;	USE THE ACCOUNT THE CONTROLLING JOB IS LOGGED IN UNDER.  TO AVOID RACES
;	VALIDATE AGAIN EVEN THOUGH (MOST OF THE TIME) THE CONTROLLING JOB'S
;	ACCOUNT WAS VALIDATED.
GETAC2:	SKIPE	U.ACTS		;IS THERE AN ACCOUNT NOW?
	JRST	GETAC3		;YES. VALIDATE IF NECESSARY
	SETO	T3,		;NO. IS THERE A CONTROLLING JOB?
	CTLJOB	T3,
	  JRST	LGNNAS		;ERROR. REPORT NO ACCOUNT
	JUMPL	T3,LGNNAS	;NO CONTROLLING JOB. REPORT NO ACCOUNT
	HRL	T1,T3		;
	HRRI	T1,.GTPPN	;GET THE CONTROLLING JOB'S PPN
	GETTAB	T1,
	  JRST	LGNNAS		;ERROR. JUST REPORT NO ACCOUNT
	CAME	T1,PPN		;IS IT THE SAME PPN?
	JRST	LGNNAS		;NO. REPORT NO ACCOUNT SPECIFIED
	MOVE	T1,[.ACTRD,,T2]	;YES. USE THE CONTROLLING JOB'S ACCOUNT
	MOVEI	T2,2		;SET UP THE READ ACCOUNT UUO. JOB # IS IN T3
	MOVEI	T4,U.ACTS	;PUT IT THERE
	ACCT.	T1,
	  JRST	LGNNAS		;ERROR. REPORT NO ACCOUNT SPECIFIED
GETAC3:
IFN VALDSW,<
	MOVE	T1,STATS2	;GET THE SECOND STATES WORD
	TXNN	T1,ST%ACV	;IS VALIDATION REQUIRED?
	POPJ	P,		;NO. DON'T VALIDATE
	MOVEI	T1,UGVAL$	;VALIDATION ID
	PUSHJ	P,.USAGE	;GO. VALIDATE. RETURNS IF OK
> ;END IFN VALDSW
	POPJ	P,		;ALL DONE WITH ACCOUNTS
	SUBTTL	Get the REMARK string

;GETRMK - ROUTINE TO PROMPT FOR AN ACCOUNT IF THE USER IS REQUIRED TO
;	PROVIDE ONE.  IF MORE THAN 39 CHARACTERS ARE TYPED, THE REMARK
;	WILL BE TRUNCATED TO 39 CHARACTERS WITH NO WARNING TO THE USER.
;	IF ILLEGAL CHARACTERS ARE TYPED IN, A BACKSLASH WILL BE SUBSTITUTED
;	FOR THE CHARACTER, AGAIN, WITH NO WARNING TO THE USER.

GETRMK:	MOVE	T1,U.RMRK
	AOJN	T1,GETRM3	;HAS A /REMARK: SWITCH BEEN SEEN?
	SETZM	U.RMRK		;NO. ZERO THE REMARK AREA
	MOVE	T1,[U.RMRK,,U.RMRK+1]
	BLT	T1,U.RMRK+7
	MOVE	T1,ENTRY+PROWRD
	TXNN	T1,P.RMRK	;IS A REMARK REQUIRED?
	JRST	GETRM3		;NO. DON'T BOTHER THE USER WITH A PROMPT
	MOVE	T1,TTBITS	;IF WE ARE A PTY, PROMPTING WILL CAUSE
	TXNE	T1,GL.ITY	; BATCON, OPSER, ETC. TO DO ERROR REPORTING
	JRST	GETRM3		; SO, JUST ALLOW FOR A NULL REMARK
	MOVEI	M,[ASCIZ /Remark: /]	;PROMPT THE USER
	PUSHJ 	P,MSG		; ..
	MOVEI	M,[ASCIZ/a remark string/]
	MOVEM	M,HELP
	SETSTS	TTY,0		;MAKE SURE ECHO IS ON
	OUTPUT	TTY,		;FORCE OUTPUT
	MOVE	P1,[POINT 7,U.RMRK]
	MOVEI	P2,^D39		;LIMIT IS 39 CHARACTERS
GETRM2:	PUSHJ	P,.TICHE##	;GET A CHARACTER
	JUMPLE	C,GETRM3
	CAIGE	C,176		;NO. CHECK FOR ILLEGAL CHARACTERS
	CAIGE	C," "
	MOVEI	C,"\"		;IF ILLEGAL, SUBSTITUTE A BACKSLASH
	IDPB	C,P1		;NOW STORE CHARACTER
	SOJGE	P2,GETRM2
	CLRBFI			;TRUNCATE REST OF REMARK IF USER TYPED MORE THAN 39
GETRM3:	TRZ	F,R.FMT		;INDICATE THERE IS NO MORE FORMAT ERROR
	POPJ	P,
	SUBTTL	Fact file header setup
	IFN	FACTSW,<	;[647]
ACCTA:	MOVE	T1,MYTTY	;[351] TTY LINE NAME
	TLNE	T1,-1		;[421] DO WE HAVE A LINE?
	  JRST	ACCTA1		;[421] YES -- NOT DETACHED
	MOVNI	T1,2		;DET BECOMES -2
	JRST	ACCTA4
ACCTA1:	HRLZ	T4,T1		;D=LINE NUMBER
	JUMPE	T4,ACCTA3	;JUMP IF CTY
	MOVE	T3,[POINT 6,T4]
	SETZ	T1,
ACCTA2:	ILDB	T2,T3		;GET NEXT CHAR OF LINE NUMBER
	JUMPE	T2,ACCTA4	;JUMP IF NO MORE CHARS
	IMULI	T1,10		;CONVERT TO BINARY
	ADDI	T1,-20(T2)	;FROM OCTAL SIXBIT
	JRST	ACCTA2
ACCTA3:	SETO	T1,		;CTY BECOMES -1
ACCTA4:	LSH	T1,6		;SHIFT LEFT 6 BITS
	ANDI	T1,777700	;JUST 12 BITS
	TLNN	F,FL.ATT	;SKIP IF ATTACH, NOT IF LOGIN
	JRST	ACCTA5		;LOGIN
	IOR	T1,FCTAHD	;ATTACH HEADER
	MOVE	T2,ATTJOB	;TARGET JOB
	JRST	ACCTA6		;GO STORE THEM
ACCTA5:	IOR	T1,FCTHED	;LOGIN HEADER
	MOVE	T2,THSJOB	;GET JOB NUMBER
ACCTA6:	MOVEM	T1,FCTDAT	;PUT IN ENTRY
	DPB	T2,[POINT 9,FCTDAT,17]
	MOVE	T1,PPN
	MOVEM	T1,FCTDAT+1	;PROJ PROG NO. TO FACT ENTRY
	MOVSI	T1,(1B8)	;TURN ON BIT IN TYPE CODE
	IORM	T1,FCTDAT	; ..
	PUSHJ	P,.GTNOW##	;GET TODAYS DATE
	MOVEM	T1,FCTDAT+2	;STORE IN FACT FILE ENTRY

	POPJ	P,		;RETURN TO WRITE IT

> ;END FACTSW


	SUBTTL	Password encryption routines

	IFN	NCRYPT,<	;[557] IF ENCRYPTING PSWDS

;ROUTINE TO HASH-CODE THE PASSWORD FOR GREATER SECURITY
;HASHING FUNCTION IS NON-INVERTIBLE
;CALL:	MOVE	P1,[PASSWORD]
;	PUSHJ	P,ENCODE##
;	RETURN HERE WITH HASHED PASSWORD IN P1

ENCODE::MOVE	T2,P1		;GET PSWD IN T2
	MOVE	T1,T2		;AND T2
	HRRZ	T4,PPN		;GET PROGRAMMER NUMBER
	IDIVI	T2,(T4)		;DIVIDE INTO PASSWORD
	MOVM	T3,T3		;GET ABS(REMAINDER)
	MOVE	T4,T3		;COPY FOR A LOOP COUNTER
FOO:	MUL	T1,T1		;SQUARE THE PASSWORD
	ROTC	T1,^D18		;GET MIDDLE 36 BITS OF RESULT
	JUMPN	T1,.+2		;MAKE SURE NON-ZERO
	MOVE	T1,T2		;IF ZERO, PICK UP PSWD AGAIN
	SOJG	T4,FOO		;DO THIS A LARGE (RANDOM) NO. OF TIMES
	XOR	T1,P1		;MUNGE IT STILL MORE
	IDIVI	T3,^D35		;DIVIDE LOOP COUNTER
	ROT	T1,1(T4)	;ROTATE T1 BY REMAINDER
	MOVE	P1,T1		;COPY FINAL RESULT BACK TO P1
	POPJ	P,		;ALL DONE!
	>			;[557] END IFN NCRYPT
	PRGEND
	TITLE	LGNUSG - USAGE accounting, IPCF, and validation
	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	LGNDCL

;THIS ROUTINE HANDLES ALL THE IPCF HANDLING NEEDED TO SUPPORT THE
;	USAGE FILE ACCOUNTING.  IT INCLUDES VALIDATION, ATTACH, LOGIN
;	AND SESSION IPCF MESSAGES TO THE ACCOUNTING DAEMON.   ACCOUNT
;	VALIDATION IS ALSO DONE BY THE ACCOUNTING DAEMON VIA IPCF.
;	THE CALL TO THIS MODULE IS:
;	T1/	FUNCTION (SEE ACTSYM.MAC FOR A LIST OF FUNCTIONS)
;	RETURN HERE.  IF THERE IS ANY ERROR (E.G., A VALIDATION ERROR),
;			THEN LOGIN WILL HANDLE ITS OWN ERROR REPORTING IN LGNERR.
;			THIS IS WHY THERE IS NO SKIP RETURN.

.USAGE:
IFE FTUSAG,<
	POPJ	P,		;USAGE FEATURE TEST IS TURNED OFF
> ;END IFE FTUSAG

IFN FTUSAG,<
	MOVEM	T1,ACTMES	;SAVE THE MESSAGE TYPE
	SKIPE	ACTPID		;DOES THE ACCOUNTING DAEMON EXIST?
	JRST	USAGE1		;YES.
	PUSHJ	P,USPIDW	;NO. WAIT UNTIL IT DOES OR 5 SECONDS
	POPJ	P,		;MONITOR IS IN DEBUG MODE AND TTY IS LOCAL --
				; ALWAYS ALLOW LOGIN IF TRUE
USAGE1:	MOVE	T1,ACTMES	;NOW GO DO THE IPCF MESSAGE
	CAIG	T1,UGATT$	;ANYTHING GREATER THAN ATTACH IS ILLEGAL IN LOGIN
	PJRST	@USGDSP(T1)
FATAL	IIM,<Illegal accounting message>

;DISPATCH TABLE FOR IPCF MESSAGES IN LOGIN

USGDSP:	LGNIIM			;ILLEGAL MESSAGE TYPE
	USVALD			;VALIDATION MESSAGE
	USLOGN			;USER IS LOGGING IN MESSAGE
	USSESS			;USER HAS TYPED A SESSION COMMAND MESSAGE
	USATTA			;USER HAS ATTACHED TO HIS JOB
;USVALD - ROUTINE TO SEND AND RECEIVE IPCF MESSAGES WITH THE ACCOUNTING DAEMON
;	TO VALIDATE ACCOUNTS.
USVALD:	PUSHJ	P,GETPAG	;GET A PAGE FOR IPCF SEND, T2 CONTAINS THE ADDRESS
	MOVE	T1,ACTMES	;GET THE MESSAGE TYPE
	MOVEM	T1,UV$TYP(T2)	;PUT THE MESSAGE TYPE IN THE IPCF SEND
	MOVE	T1,PPN		;GET THE PPN TO BE VALIDATED
	MOVEM	T1,UV$PPN(T2)
	HRLI	T1,U.ACTS	;WHERE TO BLT THE ACCOUNT FROM
	HRRI	T1,UV$ACT(T2)	;WHERE TO BLT THE ACCOUNT TO
	BLT	T1,UV$ACE(T2)
	PUSHJ	P,DATTIM	;GET THE DATE/TIME FOR A UNIQUE MESSAGE IDENTIFIER
	MOVEM	T1,UV$ACK(T2)
	PUSHJ	P,USSEND	;SEND THE MESSAGE
	PUSHJ	P,USRECV	;DON'T DO ANYTHING UNTIL MESSAGE HAS BEEN RECEIVED
	PJRST	USGCHK		;CHECK TO SEE IF MESSAGE A-OK



;USLOGN - ROUTINE TO SEND A IPCF MESSAGE TO THE ACCOUNTING DAEMON
;	TO DENOTE THE FACT THAT THIS JOB IS LOGGING IN.
USLOGN:	PUSHJ	P,GETPAG	;GET A PAGE FOR IPCF SEND, T2 CONTAINS ADDRESS OF PAGE
	MOVEI	T1,UGLGN$	;MESSAGE TYPE
	MOVEM	T1,UL$TYP(T2)
	MOVE	T1,[SIXBIT /LOGIN/]
	MOVEM	T1,UL$PRG(T2)	;PROGRAM NAME
	MOVE	T1,.JBVER	;VERSION NUMBER
	MOVEM	T1,UL$VER(T2)
	HRLI	T1,U.ACTS	;ACCOUNT STRING
	HRRI	T1,UL$ACT(T2)
	BLT	T1,UL$ACE(T2)
	PUSHJ	P,DATTIM	;SESSION START DATE/TIME, ALSO UNIQUE MESSAGE IDENTIFIER
	MOVEM	T1,UL$ACK(T2)
	MOVEM	T1,UL$BEG(T2)
	TLNN	F,FL.BAT	;IS THIS A BATCH JOB?
	JRST	[MOVEI	T1,ULJTI$	;NO.
		MOVEM	T1,UL$JTY(T2)	;SKIP GATHERING OF BATCH INFORMATION
		JRST	USLOG1]
	MOVEI	T1,ULJBA$	;YES. INDICATE A BATCH JOB
	MOVEM	T1,UL$JTY(T2)
	MOVE	T1,U.BSEQ	;BATCH SEQUENCE NUMBER
	MOVEM	T1,UL$BSQ(T2)
	MOVE	T1,U.BNAM	;BATCH JOB NAME
	MOVEM	T1,UL$BNM(T2)
	MOVE	T1,U.BREQ	;BATCH REQUEST ID
	MOVEM	T1,UL$BRI(T2)
USLOG1:	HRLI	T1,U.RMRK	;SESSION REMARK
	HRRI	T1,UL$RMK(T2)
	BLT	T1,UL$RME(T2)
	LDB	T1,[POINT 9,ENTRY+XPDWRD,26]
	MOVEM	T1,UL$CLS(T2)	;SCHEDULING CLASS
	MOVE	T1,PPN		;USER'S PPN
	MOVEM	T1,UL$PPN(T2)
	MOVE	T1,ENTRY+NM1WRD	;USER'S NAME IN ACCT.SYS
	MOVEM	T1,UL$NM1(T2)
	MOVE	T1,ENTRY+NM2WRD
	MOVEM	T1,UL$NM2(T2)
	MOVE	T1,THSJOB	;GET THE JOB NUMBER
	PUSHJ	P,SETTNL	;FIND LINE NUMBER, NODE NAME, TERMINAL DESG.
	MOVE	T1,MONLNO	;LINE NUMBER
	MOVEM	T1,UL$LIN(T2)	;STORE THE LINE NUMBER
	MOVE	T1,MONNOD	;NODE NAME
	MOVEM	T1,UL$NOD(T2)
	MOVE	T1,MONTDE	;LINE DESIGNATOR
	MOVEM	T1,UL$TDE(T2)
	PUSHJ	P,USSEND	;SEND THE MESSAGE
	PUSHJ	P,USRECV	;WAIT
	PJRST	USGCHK		;CHECK TO SEE IF MESSAGE A-OK


;USSESS - ROUTINE TO SEND A IPCF MESSAGE TO THE ACCOUNTING DAEMON TO
;	DENOTE THE FACT THAT THIS USER HAS DONE A SESSION COMMAND.

USSESS:	PUSHJ	P,GETPAG	;GET A PAGE FOR IPCF MESSAGE
	MOVEI	T1,UGSES$	; T2 CONTAINS ADDRESS OF PAGE
	MOVEM	T1,US$TYP(T2)	;MESSAGE TYPE
	MOVE	T1,[SIXBIT /LOGIN/]
	MOVEM	T1,US$PRG(T2)	;PROGRAM NAME
	MOVE	T1,.JBVER	;VERSION NUMBER
	MOVEM	T1,US$VER(T2)
	HRLI	T1,U.ACTS	;NEW ACCOUNT STRING
	HRRI	T1,US$ACT(T2)
	BLT	T1,US$ACE(T2)
	PUSHJ	P,DATTIM
	MOVEM	T1,US$ACK(T2)	;UNIQUE MESSAGE IDENTIFIER
	MOVEM	T1,US$BEG(T2)	;SESSION START DATE/TIME
	HRLI	T1,U.RMRK	;NEW SESSION REMARK
	HRRI	T1,US$RMK(T2)
	BLT	T1,US$RME(T2)
	PUSHJ	P,USSEND	;SEND THE MESSAGE
	PUSHJ	P,USRECV	;HAVE TO WAIT BECAUSE THE ACCOUNT DAEMON
				; GETTAB'S DYNAMIC DATA FOR USAGE ENTRY
	PJRST	USGCHK		;CHECK TO SEE IF MESSAGE A-OK


;USATTA - ROUTINE TO SEND AN IPCF MESSAGE TO THE ACCOUNTING DAEMON TO DENOTE
;	THE FACT THAT THE USER HAS TYPED AN ATTACH COMMAND AND MAY HAVE CHANGED
;	NODES AND/OR LINE NUMBERS.

USATTA:	PUSHJ	P,GETPAG	;GET A PAGE FOR IPCF SEND, T2 CONTAINS PAGE ADDRESS
	MOVEI	T1,UGATT$	;ATTACH MESSAGE TYPE
	MOVEM	T1,UA$TYP(T2)
	MOVE	T1,[SIXBIT /LOGIN/]
	MOVEM	T1,UA$PRG(T2)	;PROGRAM NAME
	MOVE	T1,.JBVER	;VERSION NUMBER OF LOGIN
	MOVEM	T1,UA$VER(T2)
	MOVE	T1,THSJOB	;GET THE JOB NUMBER
	PUSHJ	P,SETTNL	;FIND TERMINAL DESIGNATOR, LINE NO., NODE NAME
	MOVE	T1,MONLNO	;LINE NUMBER
	MOVEM	T1,UA$LIN(T2)	;STORE THE LINE NUMBER
	MOVE	T1,MONNOD	;NODE NAME
	MOVEM	T1,UA$NOD(T2)
	MOVE	T1,MONTDE	;TERMINAL DESIGNATOR
	MOVEM	T1,UA$TDE(T2)
	PUSHJ	P,DATTIM
	MOVEM	T1,UA$ACK(T2)	;UNIQUE MESSAGE IDENTIFIER
	PUSHJ	P,USSEND	;SEND THE MESSAGE
	PUSHJ	P,USRECV	;WAIT
	PJRST	USGCHK		;CHECK TO SEE IF MESSAGE A-OK
;GETPAG - ROUTINE TO CREATE A PAGE AND PUT ITS ADDRESS IN THE SEND/RECEIVE
;	ARGUMENT BLOCKS (IPS.BL AND IPR.BL). IT ALSO RETURNS THE PAGE ADDRESS IN T2

GETPAG:	MOVE	T1,.JBREL	;CREATE A PAGE
	ADDI	T1,1
	MOVE	T2,T1		;SAVE THE ADDRESS IN T2
	LSH	T1,-11		;CONVERT TO A PAGE NUMBER
	MOVEM	T1,PAGBLK+1	;STORE IN THE PAGE. ARGUMENT BLOCK
	MOVEM	T1,IPS.BL+.IPCFP ;SEND ARGUMENT BLOCK
	MOVEM	T1,IPR.BL+.IPCFP ;RECEIVE ARGUMENT BLOCK
	MOVEI	T1,1		;LENGTH OF ARGUMENT BLOCK
	MOVEM	T1,PAGBLK
	MOVE	T1,[.PAGCD,,PAGBLK]
	PAGE.	T1,
	  SKIPA
	POPJ	P,		;GOT THE PAGE
	FATAL	PUE,<PAGE. UUO error for USAGE accounting>


;USPIDW - ROUTINE TO SLEEP 5 SECONDS OR UNTIL THE ACCOUNTING DAEMON PID
;	EXISTS
USPIDW:	MOVX	T1,%CNDBG	;GET THE DEBUGGIN STATUS WORD
	GETTAB	T1,
	  MOVEI	T1,0		;ERROR. ASSUME NOT DEBUGGING
	TXNN	T1,ST%DBG	;IS THE MONITOR BEING DEBUGGED?
	JRST	USPID1		;NO. WAIT FOR THE ACCOUNT DAEMON TO WAKEN
	MOVE	T1,TTBITS	;GET THE TERMINAL CHARACTERISTICS
	TXNN	T1,GL.REM!GL.RBS	;IS IT A REMOTE LINE?
	POPJ	P,		;NO. ALLOW USER TO LOGIN EVEN WITH NO ACCOUNTING
USPID1:	MOVEI	T1,-5
USPID2:	MOVE	T2,[%SIACT]	;GET THE ACCOUNTING DAEMON PID
	GETTAB	T2,
	  JRST	LGNANR		;CAN'T HAPPEN
	JUMPN	T2,[MOVEM	T2,ACTPID
		JRST	.POPJ1]
;************************************************************************
;***************************************************************************
	POPJ	P,		;THIS LINE MUST COME OUT WHEN THE ACCOUNT
				;DAEMON CAN COME UP AT SYSTEM STARTUP
;**************************************************************************
;**************************************************************************
	AOJL	T1,USPID2	;HAS IT BEEN 5 SECONDS?
	FATAL	ANR,<Accounting daemon not running>

;SETTNL - SUBROUTINE TO SET UP TERMINAL DESIGNATOR, NODE NAME AND LINE NUMBER
;	FOR THE JOB IN T1.  STORES VALUES IN MONTDE, MONLNO, AND MONNOD WHICH
;	IS WHERE THE ROUTINES USLOGN AND USATTA WOULD LIKE TO FIND THEM.
;USES T1-T4

SETTNL:	PUSHJ	P,.PSH4T##	;SAVE TEMPS
	MOVSI	T4,(ASCIZ/D/)	;ASSUME DETACHED
	TRMNO.	T1,		;GET TERMINAL DESIGNATOR
	  JRST	SETTN1		;DETACHED
	DPB	T1,[POINT 9,MONLNO,35] ;STORE IN CASE NO NETWORKS
	GETLCH	T1		;GET LINE CHARACTERISTICS
	MOVSI	T4,(ASCIZ/T/)	;ASSUME REGULAR TTY
	TXNE	T1,GL.CTY	;THE SYSTEM CTY
	MOVSI	T4,(ASCIZ/C/)	;YES
	TXNE	T1,GL.ITY	;INVISIBLE (PSEUDO) TTY
	MOVSI	T4,(ASCIZ/P/)	;YES
	HRRZS	T1		;GET RID OF GETLCH BITS
	GTNTN.	T1,		;CONVERT TO NODE AND LINE
	  JRST	SETTN1		;NO NETWORKS
	HRRZM	T1,MONLNO	;STORE REAL LINE NUMBER
	HLRZ	T3,T1		;ISOLATE NODE NUMBER
	HRRI	T2,2		;NUMBER OF ARGUMENTS
	MOVE	T1,[.NDRNN,,T2]	;RETURN NODE NAME FOR NUMBER
	NODE.	T1,		;ASK TODD
	  SKIPA			;FAILED?
	MOVEM	T1,MONNOD	;STORE SIXBIT NODE NAME
SETTN1:	MOVEM	T4,MONTDE	;STORE TERMINAL DESIGNATOR
	PUSHJ	P,.POP4T##	;RESTORE TEMPS
	POPJ	P,		;AND RETURN

;DATTIM - ROUTINE TO GETTAB THE INTERNAL DATE AND TIME (%CNDTM) AND STORE IT
;	IN ACTACK SO IPCF MESSAGES AND THEIR RESPONSES CAN BE SYNCRONIZED AND
;	ALSO ENSURE SYSTEM SECURITY AND ACCOUNTING DATA INTEGRITY.
;	RETURNS THE DATE/TIME WORD IN T1

DATTIM:	MOVX	T1,%CNDTM
	GETTAB	T1,
	  MOVEI	T1,0		;CAN'T HAPPEN
	MOVEM	T1,ACTACK	;SAVE IT AS A UNIQUE NUMBER
	POPJ	P,

;ROUTINE TO SEND A PAGE TO THE ACCOUNTING DAEMON.
USSEND:	MOVX	T1,IP.CFV	;SEND A PAGE
	IORM	T1,IPS.BL+.IPCFL
	MOVE	T1,ACTPID
	MOVEM	T1,IPS.BL+.IPCFR
	MOVEI	T1,1000
	HRLM	T1,IPS.BL+.IPCFP
	MOVE	T1,[4,,IPS.BL]
	IPCFS.	T1,
	  CAIA		;ERROR
	POPJ	P,
	FATAL	ISF,<IPCF send failed for USAGE accounting>

;ROUTINE TO RECEIVE A PAGE.

USRECV:	MOVX	T1,IP.CFV	;BLOCKING RECEIVE OF A PAGE
	IORM	T1,IPR.BL+.IPCFL
	MOVEI	T1,1000
	HRLM	T1,IPR.BL+.IPCFP
	MOVE	T1,[6,,IPR.BL]	;IPCF RECEIVE ARGUMENT LIST
	IPCFR.	T1,		;RECEIVE A PACKET
	  CAIA			;ERROR
	JRST	USREC1		;RECEIVE OK
	CAIE	T1,IPCPR%	;IS IT A PAGE?
	JRST	LGNIRF		;NO, WHOOPS
	MOVX	T1,IP.CFT+IP.CFV;TRUNCATE MESSAGE TO ZERO LENGTH
	MOVEM	T1,IPR.BL+.IPCFL;STORE THAT
	IPCFR.	T1,		;PITCH THE PACKET
	  JRST	LGNIRF		;SHOULDN'T HAPPEN
	JRST	USRECV		;RECEIVE ANOTHER PACKET
USREC1:	MOVE	T1,IPR.BL+.IPCFL;FLAGS
	ANDX	T1,IP.CFM	;ISOLATE TURNED AROUND MESSAGE FIELD
	CAIN	T1,.IPCFN	;A TURNED AROUND MESSAGE?
	JRST	LGNIRF		;YES, PITCH IT
	MOVE	T1,IPR.BL+.IPCFL;GET FLAGS AGAIN
	ANDX	T1,IP.CFE	;ISOLATE ERROR FIELD
	SKIPE	T1		;PITCH IT IF NON-ZERO ERROR FIELD
	JRST	LGNIRF
	HRRZ	T1,IPR.BL+.IPCFP
	LSH	T1,11		;GET THE ADDRESS OF THE MESSAGE
	MOVE	T2,UC$ACK(T1)	;GET THE UNIQUE IDENTIFIER
	CAME	T2,ACTACK	;IS THIS THE ANSWER TO THE MESSAGE WE SENT?
	JRST	USRECV		;NO. KEEP RECEIVING UNTIL WE GET AN ANSWER
	POPJ	P,		;YES.


	FATAL	IRF,<IPCF receive failed for USAGE accounting>

;USGCHK - ROUTINE TO CHECK IF RESPONSES TO IPCF SENDS ARE TRUE OR FALSE.

USGCHK:	HRRZ	T1,IPR.BL+.IPCFP ;GET THE PAGE ADDRESS OF THE DATA
	LSH	T1,11		;CONVERT TO AN ADDRESS
	MOVE	T2,UC$RES(T1)	;GET THE RESPONSE TO THE VALIDATION MESSAGE
	CAIN	T2,UGTRU$	;IS IT A VALID ACCOUNT FOR THIS PPN?
	POPJ	P,		;YES. RETURN
	JRST	USGERR



> ;END OF IFN FTUSAG
	PRGEND
	TITLE	LGNDSK - Directory logic for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	LGNDCL


SUBTTL CHKJSP - check If ATTACH Preferred Over LOGIN

;07-Apr-78/RNH
;Subroutine to see if there are any detached jobs around with the
;same PPN as the one to which this job is trying to log in and
;to give the user the opportunity to attach to one if (s)he so
;desires.  Called by:
;
;	PUSHJ	P,CHKJSP	;Check for detached jobs with same PPN
;	always return here, flags may be different if ATTACH preferred
;
;AC's are vulnerable except P1 through P4.
;
;Apologies to CHKWLD routine in LGNDSK, but to fix it up seemed too
;much a kludge.

CHKJSP::TLNN	F,FL.WLD	;User want unique PPN?
	 TDNE	F,[FL.ATT,,R.SESS] ; or already trying to attach or SESSION?
	  POPJ	P,		;Yes, then this code is pointless
	MOVE	T1,U.ATT	;DID USER TYPE /ATTACH?
	CAIN	T1,ATTIGN	;DID THE USER TYPE IGNORE?
	POPJ	P,		;YES. DON'T PROMPT
	MOVE	T2,PPN		;
	MOVE	T1,TTBITS	;If one disallows PTY's
	TXNN	T1,GL.ITY	; then one unkludges CTL and ATO files
	 CAMN	T2,ALPPPN	;Prevent confusion by preventing OPR, too
	  POPJ	P,		;Exclude such situations

	MOVEI	T1,[ASCIZ /LOGIN or ATTACH preference/]  ;
	MOVEM	T1,HELP		;Supply time-out with a message

	SETZM	OJDFLG		;Indicate no jobs found yet
	PUSHJ	P,.SAVE2##	;Using preserved AC's
	MOVX	P1,%NSHJB	;Get highest job number to check
	GETTAB	P1,		;
	 MOVEI	P1,^D70		;Use reasonable default on error
	MOVNS	P1		;Form AOBJN pointer to step through jobs
	HRLZS	P1		;
	HRRI	P1,1		;Skip job 0
;Next page has the main loop for checking jobs and user response.
CJSP1:	HRRI	P2,.GTPPN	;Check a job's PPN
	HRLI	P2,(P1)		;
	GETTAB	P2,		;
	 JRST	CJSP3		;No check if can't get PPN
	CAME	P2,PPN		;PPN matches one for logging in?
	 JRST	CJSP3		;No, on to next job
	HRRZI	P2,(P1)		;Matches, but there are still questions
	CAMN	P2,THSJOB	;Dealing with our own job?
	 JRST	CJSP3		;Yes, skip rest of loop
	TRMNO.	P2,		;Find if detached by getting its TTY
	 CAIE	P2,0		;Zero on error return sez detached
	  JRST	CJSP3		;Non-zero or good return sez not useful
	HRLZI	T1,(P1)		;JOB NUMBER
	HRRI	T1,.GTDFL	;GET DEFAULT
	GETTAB	T1,		;FIND OUT IF USER WANTED TO BE ASKED
	  MOVEI	T1,0		;ALWAYS DEFAULT TO ASK THE USER
	TXNE	T1,JD.DAD	;DOES THIS JOB WANT TO PROMPT?
	JRST	CJSP3		;NO. CONTINUE THE LOOP
	MOVEI	M,[ASCIZ /
Other jobs detached with same PPN: /]	;
	SKIPE	OJDFLG		;Is this the first one found?
	 MOVEI	M,[ASCIZ /, /]	;No, use separator instead
	PUSHJ	P,MSG		;Separate job numbers neatly
	HRRZI	T1,(P1)		;Get the job number
	MOVEM	T1,OJDFLG	;Remember that at least one found
	PUSHJ	P,.TDECW##	; and tell the user what it was
CJSP3:	AOBJN	P1,CJSP1	;Loop through all jobs
	SKIPN	OJDFLG		;Were any jobs found?
	 POPJ	P,		;No, return to user unscathed
CJSP2:	MOVEI	M,[ASCIZ /
Type job number to ATTACH or carriage-return to LOGIN new job: /]	;
	PUSHJ	P,MSG		;See what the user wants to do
	OUTPUT	TTY,		;
	SETZ	T1,		;
	PUSHJ	P,.PSCAN##	;
	PUSHJ	P,.DECNW##	;Read decimal number
	JUMPE	N,.POPJ		;Assume LOGIN if none given
	HRRI	P2,.GTPPN	;Got one, check if legit
	HRLI	P2,(N)		;
	GETTAB	P2,		;
	 JRST	CJSP5		;
	CAME	P2,PPN		;Check again for PPN match
	 JRST	CJSP5		;
	HRRZI	P2,(N)		;
	TRMNO.	P2,		; and DETACHed status
	 JUMPE	P2,CJSP4	;Zero on error sez detached
CJSP5:	MOVEI	M,[ASCIZ /
?Can't ATTACH to that job./]	;
	PUSHJ	P,MSG		;
	JRST	CJSP2		;
CJSP4:	TLO	F,FL.ATT	;From now on, we're attaching to a job
	HRRZM	N,ATTJOB	;Set things up as ATTACH command
	SETOM	NOWBIT		;
	MOVEI	M,[ASCIZ /
.ATTACH /]			;Give a reassuring ATTACH message
	PUSHJ	P,MSG		;
	HRRZI	T1,(N)		;
	PUSHJ	P,.TDECW	;
	MOVE	T1,PPN		;
	PUSHJ	P,.TPPNW##	;
	PJRST	NEWLIN
	SUBTTL	Turn on echo, diddle some bits

;HERE IF ALL TYPEINS NEEDED TO LOGIN ARE VALIDATED

PSWOK:	TLNE	F,FL.FDX	;SKIP IF HALF DUPLEX
	SETSTS	TTY,0
	OUTPUT	TTY,		;CLEMENTS SAYS THIS WILL BRING BACK ECHOING
	PUSHJ	P,CHKJSP	;Check for detached jobs/same PPN and
				;set FL.ATT if user prefers to attach
	TLNE	F,FL.ATT	;ENOUGH IF ATTACH
	JRST	ACCT		;DONT NEED TO SET UP UFD'S, ETC.
	TRNE	F,R.SESS	;IF SESSION COMMAND, NEED TO CHECK FOR
	JRST	[PUSHJ	P,SW.INI	;ACCOUNTS AND REMARKS
		JRST ACCT]
	MOVE	T1,ENTRY+PRVWRD	;AND PRIV WD
	MOVEM	T1,PRIVWD	;STORE PRIV WORD
	MOVE	T1,ENTRY+CRGWRD
	MOVEM	T1,CHGNO	;CHARGE NUMBER
	CLOSE	UFD,0		;NOW CLEAR SOME IO
	SETZB	T3,RDHED	;..
	SUBTTL	Build scheduler table

	MSTIME	T1,
	TRZ	T1,7B20		;CLEAR A DIGIT
	TRO	T1,1B18		;SET FIRST DIGIT TO 4
	TLNE	F,FL.WLD	;WILD CARD?
CHKWLD:	HRRM	T1,PPN		;YES--STORE FUNNY PPN
	MOVE	T1,PPN		;PPN
	MOVEM	T1,.MYPPN##	;TELL SCAN NEW PPN
	CHGPPN	T1,		;CHANGE TO OUR PPN NOW
	  JRST	NOTHER		;NOT IMPLEMENTED
	GETPPN	T1,		;DONT CARE ABOUT OTHER USERS,
	  JRST	NOTHER		;BUT WOULD TELL IF OTHERS SAME PPN
	TLNE	F,FL.WLD	;IS THIS SUPPOSED TO BE UNIQUE?
	AOJA	T1,CHKWLD	;YES, TRY ANOTHER
	INFO	JSP,<Other jobs same PPN>
	  CAI			;[440] NON-JFCL NO-OP
	MOVE	T1,PPN		;[445] GET PPN
	CAMN	T1,ALPPPN	;[445] IS IT [1,2]?
	  JRST	ALLDON		;[445] YES - SKIP THIS STUFF
	MOVEI	M,[ASCIZ /:/]	;[445] PRINT A COLON
	PUSHJ	P,MSG		;[445] ..
	MOVX	T1,%NSHJB	;[501] GET HGHJOB
	GETTAB	T1,		;[440] WITH A GETTAB
	  JRST	ALLDON		;[440] NOT LIKELY, BUT . .
	MOVN	T1,T1		;[440] NEGATE IT
	HRLZ	P2,T1		;[440] MAKE P2 AN AOBJN POINTER
	AOS	P2		;[440] DON'T BOTHER WITH THE NULL JOB
JOBLUP:	HRRI	T1,.GTPPN	;[440] CODE FOR JBTPPN TABLE
	HRL	T1,P2		;[440] GET JOB NUMBER TO TRY
	GETTAB	T1,		;[440] GET HIS PPN
	  SETZ	T1,		;[440] AGAIN NOT LIKELY, BUT
	CAME	T1,PPN		;[440] IS HE UNDER THIS GUY'S PPN?
	  JRST	LUPER		;[440] NO - KEEP LOOKING
	HRRZ	T2,P2		;[440] GET JOB NUMBER
	CAMN	T2,THSJOB	;[440] THIS JOB?
	  JRST	LUPER		;[440] YES - HE KNOWS ABOUT THIS ONE
	TRON	F,R.COMA	;[440] COMMA TYPED YET?
	  JRST	.+3		;[440] NO - DON'T TYPE ONE
	MOVEI	M,[ASCIZ /,/]	;[440] TYPE A COMMA
	PUSHJ	P,MSG		;[440] ..
	HRRZ	T1,P2		;[440] GET JOB NUMBER
	PUSHJ	P,.TDECW##	;[440] LET SCAN DO THE TYPING
LUPER:	AOBJN	P2,JOBLUP	;[440] KEEP CHECKING

ALLDON:	MOVEI	M,[ASCIZ /]/]	;[440] PRINT CLOSING BRACKET
	PUSHJ	P,MSG		;[440] ..
	PUSHJ	P,NEWLIN	;[440] DO CRLF



NOTHER:	SKIPL	EQACT		;[425] 6.02-STYLE ACCT.SYS?
	JRST	CHECK1		;[425] NO
	MOVE	T1,STATS2	;[425] GET 2ND STATES WORD
	TXNN	T1,ST%NCS	;[632] SKIP THIS IF 6.03 SCHEDULER IN WMU MODE
	TXNN	T1,ST%NCS	;[632] SKIP THIS IF 6.03 SCHEDULER IN WMU MODE
	TXNN	T1,ST%SHC	;[425] DOES MONITOR HAVE SCHED. UUO?
	JRST	CHECK1		;[425] NO -- DON'T WASTE TIME HERE
	PUSHJ	P,CLRRIB	;[540] CLEAR LOOKUP BLOCK
	MOVEI	T1,.RBTIM	;[540] GET ARGUMENT COUNT
	MOVEM	T1,SECBUF+.RBCNT;[540] STUFF IT
	MOVE	T1,[SIXBIT .SCDMAP.]
	MOVEM	T1,SECBUF+.RBNAM;[540] STUFF INTO LOOKUP BLOCK
	MOVSI	T1,(SIXBIT .SYS.)
	MOVEM	T1,SECBUF+.RBEXT;[540]
	MOVE	T1,SYSPPN	;[540] GET A GOOD PPN
	MOVEM	T1,SECBUF+.RBPPN;[540] AND USE IT
	SETZM	RDHED		;[425] FORCE FIRST READ TO INPUT
	LOOKUP	UFD,SECBUF	;[425] IS IT THERE?
	  JRST	[WARN CFS,<Can't find SCDMAP.SYS.  Please call the operator.>
		  JFCL
		JRST	NSCHED]	;[425] CAN'T GET AT SCDMAP.SYS
	SKIPE	SCDBLT		;[540] HAS TABLE BEEN BUILT YET?
	  JRST	BILDIT		;[540] NO - BUILD IT
	MOVE	T1,SECBUF+.RBTIM;[540] YES - SEE WHEN SCDMAP WAS CREATED
	CAMN	T1,W.SCED	;[540] SAME ONE?
	  JRST	CHECK1		;[540] YES - USE CURRENT TABLE
BILDIT:	SKIPL	BLDSCD		;[540] IS BUILD IN PROGRESS?
	  JRST	BUILD		;[556] NO - BUILD IT NOW
	PUSHJ	P,ZZZZ		;[540] YES - TAKE A NAP
	  JRST	CHECK1		;[540] TABLE BUILT BY SOMEONE ELSE

;	20-SEP-79/BAH CORE UUO TO EXPAND HIGH SEGMENT CAN FAIL IF 1) SOMEONE
;	IS SAVING LOGIN OR IF 2) IN AN SMP ENVIRONMENT, ANOTHER CPU IS
;	EXECUTING THE SAME CODE WITH THE HIGH SEGMENT WRITE-ENABLED.
;	TO GIVE THE MONITOR TIME TO CATCH UP, SLEEP A SECOND AND TRY AGAIN
;	(3 TIMES) IF THE CORE UUO FAILS.


BUILD:	MOVEI	T3,3		;SET UP A COUNT FOR CORE UUO'S
BUILD1:	MOVE	T2,DACCL	;[556] GET SIZE OF ACCT.SYS
	LSH	T2,1		;[425] DOUBLE IT BECAUSE 2 TABLES
	ADD	T2,PDACC	;[425] ADD BASE ADDRESS OF TABLES
	ADDI	T2,SCDSIZ	;[425] ADD SIZE OF SCHED. TABLE
	HRRZ	T1,.JBHRL	;[425] GET HIGHEST ADR IN HI SEG
	CAMG	T2,T1		;[425] ENOUGH ROOM?
	  JRST	ENUF		;[425] YES -- PLOW ON
	HRLZ	T1,T2		;[425] NO -- SET UP TO EXPAND HI SEG
	CORE	T1,		;[425] GET BIGGER
	  JRST	[SOJLE	T3,LGNCUF	;TRIED 3 TIMES--REPORT CORE UUO FAILED
		MOVEI	T1,1		;SLEEP FOR A SECOND
		SLEEP	T1,
		JRST	BUILD1]		;TRY THE CORE UUO AGAIN
ENUF:	PUSHJ	P,LOK		;[444] WRITE-ENABLE HI SEG, LOCK OUT CTRL-C
	SUBI	T2,SCDSIZ	;[425] MAKE BASE ADDRESS OF TABLE
	MOVEM	T2,SCDTBL	;[425] SAVE ADDR OF SCHED CLASS TABLE
	HRLI	T2,-SCDSIZ	;[425] MAKE AN AOBJN POINTER
	SETOM	BLDSCD		;[425] FLAG BUILD IN PROGRESS

SCDLUP:	PUSHJ	P,RDUFD		;[425] GET A WORD
	  JRST	[WARN PEF,<Premature EOF reading SCDMAP.SYS.  Please call the operator.>
		  JFCL
		JRST	RSCHED]	;[425] 
	MOVEM	WD,(T2)		;[425] STORE WORD IN TABLE
	AOBJN	T2,SCDLUP	;[425] AND GO AGAIN

	SETZM	BLDSCD		;[425] FLAG BUILD NOT IN PROGRESS
	SETZM	SCDBLT		;[425] FLAG TABLE BUILT
	CLOSE	UFD,0		;[425] ALL DONE
	MOVE	T1,SECBUF+.RBTIM;[540] GET CREATION DATE-TIME OF SCDMAP
	MOVEM	T1,W.SCED	;[540] SAVE IN HI-SEG
	PUSHJ	P,UNLOCK	;[444] UNLOCK THIS CODE
	JRST	CHECK1		;[425] GO DO AUXACC.SYS STUFF

RSCHED:	CLOSE	UFD,0
	SETZM	BLDSCD		;[425] FLAG BUILD NOT IN PROGRESS
	SETOM	SCDBLT		;[425] FLAG TABLE NOT BUILT
	PUSHJ	P,UNLOCK	;[444] UNLOCK THIS CODE
NSCHED:	MOVX	T1,ST%SHC	;[516] SOMETHING BROKE SO PRETEND
	ANDCAM	T1,STATS2	;[425] NO SCHED. UUO
	JRST	CHECK1		;[425] MOVE ON

ZZZZ:	MOVEI	T1,^D60		;[425] WAIT ONE MIN. THEN REBUILD
	SKIPL	SCDBLT		;[433] TABLE BUILT YET?
	POPJ	P,		;[425] YES -- NON-SKIP RETURN
	MOVEI	T2,1		;[425] SLEEP ONE SECOND
	SLEEP	T2,
	SOJG	T1,ZZZZ+1	;[425] WAIT ONE MINUTE
	AOS	(P)		;[425] THEN SKIP RETURN TO 
	POPJ	P,		;[425] REBUILD TABLE

	SUBTTL	Search AUXACC.SYS

CHECK1:	PUSHJ	P,CLRRIB	;[540] CLEAR LOOKUP BLOCK
	MOVEI	T1,.RBTIM	;[540] GET ARG COUNT
	MOVEM	T1,SECBUF+.RBCNT;[540] SALT AWAY
	MOVE	T1,[SIXBIT .AUXACC.]
	MOVEM	T1,SECBUF+.RBNAM;[540] SET UP NAME
	MOVSI	T1,(SIXBIT .SYS.)
	MOVEM	T1,SECBUF+.RBEXT;[540] AND EXTENSION
	MOVE	T1,SYSPPN	;[540] GET SYS: PPN
	MOVEM	T1,SECBUF+.RBPPN;[540] ..
	SETZM	RDHED		;[540]
	LOOKUP	UFD,SECBUF	;[540] LOOK FOR AUXACC.SYS
	  JRST	NOAUXA		;NOPE
	TLZ	F,FL.ACC	;NOTE READING AUXACC.SYS NOW
IFN	FASTLG,<
	SKIPN	DAUXFL		;[540] AUX TABLE BUILT YET?
	  JRST	BLDAUX		;[540] NO - BUILD IT NOW
	MOVE	T1,SECBUF+.RBTIM;[540] CREATION DATE-TIME OF AUXACC
	CAMN	T1,W.AUX	;[540] CHANGED SINCE LAST TIME?
	  JRST	LUKAUX		;[540] NO - WE'RE ALL SET
>;END FASTLG COND
BLDAUX:	PUSHJ	P,RDUFD		;[540] READ 1ST WORD, CONTAINS FORMAT VERSION NUMBER
	  JRST	NOAUXA		;NOT THERE?
	HLRZ	WD,WD		;[403] WD=FORMAT VERSION NUMBER
	CAIN	WD,AC1FOR
	  JRST	AXFMOK
	STOP	BFA,<Bad format in AUXACC.SYS.  Please call the operator.>
	  JFCL
AXFMOK:	IFE	FASTLG,<
	HLRE	T1,T4
	JUMPGE	T1,.+2		;IF +, NO OF BLOCKS, ELSE WORDS
	IDIV	T1,[-^D128]	;APPROXIMATION OF POSITION IN FILE BASED
	IMUL	T1,ACCKNT	;ON POSITION OF USER IN ACCT.SYS
	IDIV	T1,ACCTLN	;BLOCKS READ IN ACCT*LENGTH AUXACC/LENGTH ACCT
	SKIPN	T1
	MOVEI	T1,1		;A MUST BE AT LEAST 1
	CAIN	T1,1
	JRST	ACC1A
	SETZM	RDHED		;IF NOT 1ST BLOCK, FORCE NEW INPUT
	>			;[556] END OF IFE FASTLG
	IFN	FASTLG,<
	PUSHJ	P,LOK		;[444] LOCK OUT OTHER MODIFIERS
	MOVE	T1,ACCKNT	;ACCT.SYS POSITIION
	MOVEM	T1,SAVKNT	;PROTECT TEMPORARILY
	SETZM	ACCKNT
	TLO	F,FL.ACC	;LIES: IT ENABLES COUNTING ON AUXACC
	MOVN	T1,DACCL	;LENGTH OF ACCT.SYS
	HRLZ	T1,T1		;[403] FOR AOBJN
	ADD	T1,PDACC	;[403] SETUP POINTER
	MOVE	T2,DACCL	;[403] FOR AUXACC.SYS TABLE
	HRLI	T2,T1		;INDIRECT POINTER TO DACC+DACCL 
				;INDEXED BY A
;STILL IN FASTLG COND
AUXSCN:	PUSHJ	P,RDUFD
	  JRST	AUXEND		;END OF FILE
	AOJN	WD,AUXSCN	;SCAN FOR -1 (BEGIN OF ENTRY FLAG)
	PUSHJ	P,RDUFD		;GET AND IGNORE ENTRY LENGTH
	  JRST	AUXEND
	PUSHJ	P,RDUFD		;GET PPN
	  JRST	AUXEND
AUXSC1:	CAMGE	WD,0(T1)	;[403] IS THIS PPN .GE. THAT IN DACC TABLE?
	JRST	AUXSCN		;NO, GO GET NEXT
	MOVE	T3,ACCKNT	;[403] PICK UP CURRENT BLOCK NO
	MOVEM	T3,@T2		;[403] STORE IN FREE TABLE LOCATION
	AOBJN	T1,AUXSC1	;[403] GO FOR MORE IF ROOM
AUXDUN:	TLZ	F,FL.ACC	;DISABLE BLOCK COUNTING
	MOVE	T1,SAVKNT	;GET POINTER INTO ACCT.SYS
	MOVEM	T1,ACCKNT	;RESTORE COUNTER
	SETOM	DAUXFL		;INDICATE TABLE OK
	MOVE	T1,SECBUF+.RBTIM;[540] GET CREATION DATE-TIME OF AUXACC
	MOVEM	T1,W.AUX	;[540] SAVE IN HI SEG
	PUSHJ	P,UNLOCK	;[444] UNLOCK THE HI SEG
LUKAUX:	MOVE	T1,ACCKNT	;WHERE WERE WE IN ACCT.SYS?
	ADD	T1,DACCL	;CORRECT ADDRESS IN AUX TABLE
	ADD	T1,PDACC	;POINT INTO TABLE
	MOVE	T1,0(T1)	;[731][730] PICK UP AUX BLOCK
	AOJLE	T1,LGNHMU	;[511] SHOULDN'T NEVAH BE NEG
	>			;[556] END IFN FASTLG
;We have now read (if necessary) AUXACC.SYS and have an appropriate pointer
;into the file.  The following code was revised (ed.716) so that the 
;scheme of things is as follows:
;	1)  Find the entry for this user and read it one structure
;	    at a time.
;	2)  During this initial pass, remember the structure name/quotas/etc.
;	    but merely put the structure in the search list.
;	3)  with the search list set up, go read SWITCH.INI and do any
;	    final user interaction (account validation, etc.).
;	4)  If all is well and it's truly OK to LOGIN, loop through
;	    up UFDs and SFDs with the proper quotas and the proper
;	    protections, etc.  Also turn on STRUCTURE-IN-USE bit and
;	    do any needed recomps.

ACC1E:	USETI	UFD,(T1)
	SETZM	RDHED		;FORCE READ OF THAT BLOCK
ACC1A:	PUSHJ	P,RDUFD		;NOW TRY TO FIND START OF ENTRY
	  JRST	BACKUP		;TOO FAR, BACK UP 1
	AOJN	WD,ACC1A	;ALL ONES (-1) STARTS ENTRY
	PUSHJ	P,RDUFD		;READ LENGTH OF ENTRY
	  JRST	BACKUP
	MOVNI	P2,-1(WD)
	PUSHJ	P,RDUFD		;READ PPN
	  JRST	BACKUP
	CAMLE	WD,PPN		;PASSED USER?
	JRST	BACKUP		;YES, BACK UP 1 BLOCK
ACC1F:	CAME	WD,PPN		;THIS USER?
	JRST	SKACC1		;NO, READ FORWARD TO FIND HIM
ACC1G:	JUMPGE	P2,NOSTR	;JUMP IF NO STR'S FOR THIS USER
	MOVEM	P2+1,SAVERG	;SAVE RANDOM REGISTER
	IDIVI	P2,AC1BLK	;DIVIDE BY SIZE OF EACH BLOCK IN ENTRY
	MOVE	P2+1,SAVERG	;RESTORE REG WIPED BY DIVIDE
	TRZ	F,R.ACRE!R.ASTR	;CLEAR ANY CREATE AND ANY STR FLAGS
	SETZ	P1,		;Clear index into stash area
ACC1B:	PUSHJ	P,RDUFD		;READ NEXT FILE STRUCTURE NAME
	  JRST	ACC1J
	MOVE	M,WD		;M=STR NAME FOR UFDSET
	PUSHJ	P,RDUFD		;RESERVED QUOTA
	  JRST	ACC1J
	MOVE	T2,WD		;T2=RESERVED QUOTA FOR UFDSET
	PUSHJ	P,RDUFD		;FIRST COME, FIRST SERVED QUOTA
	  JRST	ACC1J
	MOVE	T3,WD		;T3=FCFS QUOTA FOR UFDSET
	PUSHJ	P,RDUFD		;LOGGED-OUT QUOTA
	  JRST	ACC1J
	MOVE	T4,WD		;D=LOGGED OUT QUOTA FOR UFDSET
	PUSHJ	P,RDUFD		;BITS ABOUT FILE STRUCTURE
	  JRST	ACC1J
	MOVE	T1,[XWD 1,M]
	DSKCHR	T1,		;SEE IF STR IS IN SYSTEM
	  JRST	ACC1H		;NO, DO NOT PUT IN SEARCH LIST
	TXNE	T1,DC.SAF	;SKIP IF NOT SINGLE ACCESS
	JRST	ACC1H		;CANT BE FOR US YET SO DONT INCLUDE THIS STR
	LDB	T1,[POINTR(T1,DC.TYP)] ;[711] GET STR TYPE
	CAIE	T1,.DCTFS	;[711] IS IT FULL FILE STRUCTURE NAME?
	JRST	ACC1H		;[711] NO - IGNORE INVALID NAME
	TLZ	F,L.WRTL+L.NCR	;set up F based on WD bits
	TXNE	WD,DF.SWL
	TLO	F,L.WRTL
	TXNE	WD,DF.SNC
	TLO	F,L.NCR
	MOVEM	M,SAVAUX(P1)	;save info from AUXACC for 2nd pass
	MOVEM	T2,SAVAUX+1(P1)
	MOVEM	T3,SAVAUX+2(P1)
	MOVEM	T4,SAVAUX+3(P1)
	MOVEM	WD,SAVAUX+4(P1)
	MOVEM	M,UFDFSN	;set structure name for S.L. addition
	PUSHJ	P,ADDSTR	;add structure to search list
	ADDI	P1,5		;bump up pointer
ACC1H:	AOJL	P2,ACC1B	;LOOP FOR ALL STRS IN ENTRY
	SETZM	SAVAUX(P1)	;set end marker for 2nd pass
	PUSHJ	P,SW.INI##	;Read SWITCH.INI and validate account
	TDZA	P1,P1		;reset pointer and skip
ACC2A:	 ADDI	P1,5		;when looping, step to next entry
	SKIPN	M,SAVAUX(P1)	;another one in the wings?
	 JRST	ACC2H		;No, all done
	MOVE	T2,SAVAUX+1(P1)	;Yes, recover stashed data
	MOVE	T3,SAVAUX+2(P1)	;	then go process this
	MOVE	T4,SAVAUX+3(P1)	;	as originally coded to
	MOVE	WD,SAVAUX+4(P1)	;	set up UFD's, etc.
	TLZ	F,L.WRTL+L.NCR
	TXNE	WD,DF.SWL	;SKIP IF NOT READ ONLY
	TLO	F,L.WRTL
	TXNE	WD,DF.SNC	;NO SKIP IF NO CREATE
	TLO	F,L.NCR
	TLNN	F,L.WRTL!L.NCR	;CAN WE CREATE ON THIS STR
	TRO	F,R.ACRE	;YES-INDICATE CREATION POSSIBLE
	PUSHJ	P,UFDSET	;SET UP UFD FOR USER ON THIS STR
	  JRST	.+2		;DIDN'T MAKE IT
	TRO	F,R.ASTR	;DID-SET SOME-STR FLAG
	TLZ	F,FL.ATT	;CLEAR ATTACH FLAG
	MOVSI	T1,RP.BDA+RP.BFA+RP.CRH+RP.FRE+RP.FWE+RP.FCE
	TDNN	T1,SRCBUF+.RBSTS	;SKIP IF ERRORS
	JRST	ACC2A		;NONE TODAY THANK YOU
	WARN	FEE,< >
	  JRST	ACC2A
	MOVE	T1,UFDFSN	;FILE STRUCTURE NUMBER
	PUSHJ	P,.TSIXN##	;PRINT IT OUT
	MOVEI	M,[ASCIZ . file errors exist
.]
	PUSHJ	P,MSG
	JRST	ACC2A		;loop til no more strs
ACC2H:	TRO	F,R.RCOM	;FLAG THAT WE HAVE RECOMPUTED
	TRZN	F,R.ASTR	;[613] ARE ANY STR'S DEFINED IN SEARCH LIST?
	JRST	NOSTRX		;NO, WARN SO
	TRNE	F,R.ACRE	;ARE ANY CREATES ALLOWED?
	JRST	ACCT
	WARN	NCR,<Search list does not allow creates>
	  JFCL
	JRST	ACCT
NOSTR:	WARN	SLE,<Search list is empty>
	  JFCL
	JRST	TOACCT		;Final cleanup, then go to ACCT

NOSTRX:	WARN	SLX,<Search list is empty>
	  JFCL
	JRST	ACCT

ACC1J:	STOP	XRE,<Format or read error in AUXACC.SYS.  Please call the operator.>

;[516] WARNING -- THE FOLLOWING TWO ERROR MACROS ARE REFERENCED
;[516] BY THE LABELS GENERATED BY THE ERROR MACROS AND NOT
;[516] BY FLOWING INTO THEM.

	STOP	CUF,<CORE UUO failed.  Please call the operator.>

	STOP	HMU,<High segment messed up.  Please call the operator.>

IFN	FASTLG,<
AUXEND:	MOVE	WD,ACCKNT	;AT END OF FILE, FORCE LAST BLOCK
	MOVEM	WD,@T2
	AOBJN	T1,.-1		;Fill table with "last" value
	JRST	AUXDUN		;AND PROCEED>
BACKUP:	SOJE	T1,SKACC2	;BACK UP BLOCK COUNTER AND STOP READING IF BEGINNING
	JRST	ACC1E		;READ NEXT PREVIOUS BLOCK IN UFD

SKACC1:	PUSHJ	P,RDUFD		;SKIP FORWARD TO USER
	  JRST	NOINAU		;EOF - NOT THERE
	AOJN	WD,SKACC1	;SEARCH FOR -1 FLAG--START OF ENTRY
	PUSHJ	P,RDUFD		;READ NUMBER OF WORDS THAT FOLLOW
	  JRST	NOINAU
	MOVNI	P2,-1(WD)	;-LENGTH - USED AT ACC1G
	PUSHJ	P,RDUFD		;READ PPN
	  JRST	NOINAU
	CAMG	WD,PPN		;PAST USER?
	JRST	ACC1F		;NO - KEEP LOOKING FOR HIM
SKACC2:	HLLO	T3,PPN		;T3=PROJ,-1=DEFAULT
	CAMLE	WD,T3		;PAST DEFAULT?
	JRST	NOINAU		;YES - NOT THERE
	CAMN	WD,T3		;AT DEFAULT?
	JRST	ACC1G		;YES - USE THIS
	HRLZ	T2,PPN		;PROG NO TO T2 LEFT
	JUMPGE	T2,ACC1F	;KEEP LOOKING UNLESS WILD PROG NO
	HRRI	T3,UNIPRG	;COMPARE AGAINST WILD CARD
	CAME	WD,T3		;ONE OF THOSE?
	JRST	ACC1F		;KEEP LOOKING
	JRST	ACC1G		;GOT IT


NOAUXA:	TLNE	F,L.OPR!L.SOPR	;[577] OPR OR SON-OF-OPR?
	  JRST	NOAUX1		;[577] YES - LET HIM IN ANYWAY
	STOP	CRA,<Can not read AUXACC.SYS>
NOAUX1:	WARN	CRX,<Can not read AUXACC.SYS>
	  JFCL
	JRST	NOSTR		;[577] TELL HIM NO S.L.
NOINAU:	WARN	NXE,<No entry in AUXACC.SYS>
	  JFCL
TOACCT:	PUSHJ	P,SW.INI##	;Even people with strange search lists
				;use switches and charge their usage
	JRST	ACCT
	SUBTTL	Subroutine to set up a UFD

;SUBROUTINE TO SET UP A UFD FOR USE  
;ARGS:	T2=RESERVED QUOTA
;	T3=FIRST COME FIRST SERVED QUOTA
;	T4=LOGGED OUT QUOTA
;	M=NAME OF STR
;	IO=ADDRESS OF ROUTINE TO TYPE A CHAR
;	CH=ACCUMULATOR TO CONTAIN CHAR TO BE TYPED
;	F=FLAG REGISTER
;	  L.WRTL=BIT IN LH OF F = 1 IF USER REQUESTS WRITE LOCK
;	  L.NCR=BIT IN LH F = 1 IF USER REQUESTS NO CREATE SET
;	  L.SIN=BIT IN LH F = 1 IF SINGLE ACCESS REQUESTED
;	  L.FRE1=AVAILABLE BIT IN LH OF F
;	  L.FRE2=AVAILABLE BIT IN LH OF F
;	P=PUSH DOWN LIST POINTER
;
;IF T4=-1 ASSUME NO UFD DESIRED - PERFORM OTHER OPERATIONS
;
;	USR=FREE I/O CHANNEL
;	US1=FREE I/O CHANNEL
;
;CALL	PUSHJ	P,UFDSET
;ERROR	DONT PROCEED (MESSAGE TYPED)
;OK	STR IS IN SEARCH LIST (WARNING MAY BE TYPED)
;
;ASSUMES SYMBOLS FOR AC'S ABOVE DEFINED, LOCATIONS .POPJ, .POPJ1 DEFINED
;
;USES U AND UU MACROS TO RESERVE STORAGE FOR EITHER HIGH OR LOW
;SEGMENT OPERATION.
;
;ROUTINES DEFINED HERE:
;
;MSG:	 TYPES STRING OF ASCII CHARS TO FIRST NULL
;SIXMSG:	 TYPES CONTENTS OF M AS SIXBIT CHARS
;CRLF:	 TYPES CARRIAGE RETURN LINE FEED
;OCTPRT: TYPES CONTENTS OF N AS OCTAL NUMBER
;MPOPJ:	 POP P,M FOLLWED BY POPJ P,
;R.USR:	 READS NEXT WORD FROM CHANNEL USR INTO A (BUFFER HEADER RH.USR, BUFFER B.USR)
;ADDSTR: ADD FILE STRUCTURE TO SEARCH LIST
;DISSTR: DELETE FILE STRUCTURE FROM SEARCH LIST

MNTSUB==1		;DECLARE IN CASE DISMOUNT SUBROUTINE ALSO APPEARS
UFDGIL==^D180		;[514] TIMES TO TRY TO GET UFD INTERLOCK
UFDALC==0		;BLOCKS TO ALLOCATE FOR UFDS (0=STANDARD)
RACEY==2		;VALUE OF LEVEL D FIELD IN STATES WORD FOR MONITORS
			;WHICH INCLUDE RACE CONDITION IMPROVEMENTS
RESRVD==0		;NON ZERO WHEN RESERVED QUOTA IMPLEMENTED
	DEFINE	UFDSEM(PREFIX,TEXT),<
	XLIST
LGN'PREFIX:	MOVEI	M,[ASCIZ "LGN'PREFIX TEXT for "]
	PJRST	UFDSMP
	LIST
	SALL
>
	EXTERN	.JBFF

UFDSET:	TXZ	F,R.UIB!R.UIBM	;[514] CLEAR UFD INTERLOCK FLAGS
	JUMPE	M,.POPJ1	;[572] LEAVE IF BLANK STR NAME
	PUSHJ	P,.SAVE2##	;SAVE P1 AND P2
	MOVEM	M,UFDFSN	;SAVE NAME OF STR
	MOVE	N,T2		;N=RESERVED QUOTA
	MOVE	M,T3		;M=FCFS QUOTA
	MOVE	CH,T4		;CH=LOGGED OUT QUOTA
	MOVEI	P2,UFDGIL	;NUMBER OF TIMES TO TRY FOR UFD INTERLOCK
	TLNE	F,FL.BAT	;[575] BATCH JOB?
	  LSH	P2,1		;[575] YES: DOUBLE OUR PATIENCE
UFDSTA:	MOVEI	T2,.FSULK	;USER-MODE UFD INTERLOCK FUNCTION
	PUSHJ	P,STUFC1	;TEST/SET UFD INTERLOCK
	  JRST	STUFBS		;BUSY, SLEEP AND RETRY
	MOVE	T2,UFDFSN
	MOVEI	T1,.IODMP
	MOVEI	T3,0
	OPEN	USR,T1		;INIT THIS FILE STRUCTURE
	  JRST	UFDSE2		;HOW CAN THIS BE?
	AOJE	CH,UFDOK	;JUMP IF NO UFD OPERATIONS DESIRED
	SUBI	CH,1		;NO, RESTORE LOGGED OUT QUOTA
	PUSHJ	P,SETEXL	;SET UP SRCBUF FOR EXTENDED LOOKUP OF UFD
	SETZB	T3,SRCBUF+4	;CLEAR REST OF LOOKUP BLOCK
	MOVE	T1,[XWD SRCBUF+4,SRCBUF+5]
	BLT	T1,SRCBUF+EXLLEN-1
	SETZ	T2,		;CLEAR FLAG FOR FIRST TRY
UFDERT:	LOOKUP	USR,SRCBUF	;LOOKUP UFD
	  SKIPA	T1,SRCBUF+.RBEXT	;GET ERROR CODE IN A
	JRST	UFDEX		;UFD EXISTS, LOOK AT IT
	TRNE	T1,-1		;SKIP IF NO UFD
	JRST	UFDSE3		;THERE'S SOMETHING WRONG WITH THIS UFD
				;FALL THROUGH TO BUILD UFD
;HERE IF MUST CREATE A UFD

	SETOM	CCWAIT		;DO NOT ALLOW CONTROL-C AFTER WE
				; WRITE A UFD. THAT WOULD LEAVE
				; JUNK ON THE DISK
	JUMPN	T2,UFDENT	;JUMP IF NOT FIRST TIME
	MOVEM	N,SRCBUF+.RBQTR	;STORE RESERVED QUOTA
	MOVEM	M,SRCBUF+.RBQTF	;AND FCFS
	MOVEM	CH,SRCBUF+.RBQTO	;AND LOGGED OUT QUOTA
IFN RESRVD,<ADD	M,N	;LOGGED IN QUOTA=FCFS+RESERVED>
	JUMPE	M,UFDOK		;NO UFD IF LOGGED IN QUOTA = 0
UFDENT:	PUSHJ	P,SETEXL	;SET UP FOR EXTENDED ENTER OF UFD
	MOVE	T1,[EXP RP.LOG+RP.DIR]	;SET DIRECTORY BIT AND LOGGED IN BIT
	MOVEM	T1,SRCBUF+.RBSTS
	MOVEI	T1,UFDALC	;BLOCKS TO ALLOCATE FOR UFD
	MOVEM	T1,SRCBUF+.RBALC
	MOVEI	T2,FBMTRY	;TIMES TO RETRY IF BUSY
	ENTER	USR,SRCBUF	;TRY TO CREATE A UFD
	  JRST	UFDSE1		;IDENTIFY ENTER FAILURE
	USETO	USR,2		;WRITES BLOCK 1 WITH ZEROS
	CLOSE	USR,		;AN EMPTY UFD
	SKIPN	UFDDAT		;IF UFD DATE UNSPECIFIED,
	AOS	UFDDAT		;MAKE IT NON-ZERO FOR DAYMES
	JRST	UFDOK		;ALL SET
;HERE IF UFD ALREADY EXISTS

UFDEX:	TLNE	F,FL.WLD
	JRST	RETRYA
	MOVEM	N,SRCBUF+.RBQTR	;STORE RESERVED QUOTA
	MOVEM	M,SRCBUF+.RBQTF	;AND FCFS
	MOVEM	CH,SRCBUF+.RBQTO	;AND LOGGED OUT QUOTA
;***NOTE: THE QUOTAS IN M AND CH ARE USED AT UFDEXB
	MOVE	T1,SRCBUF+.RBSTS	;LOOK AT STATUS
	TRNE	T1,RP.NDL	;IS THIS UN-DELETABLE?
	JRST	[SETOM UFDNDL	;SET FLAG FOR LATER
		 JRST  UFDOK]	;GIVE UP ON RECOMP STUFF
	LDB	T1,[POINTR(SRCBUF+.RBPRV,RB.CRD)] ;DATE
	LDB	T2,[POINTR(SRCBUF+.RBPRV,RB.CRT)] ;AND TIME OF UFD
	LDB	T3,[POINTR(SRCBUF+.RBEXT,RB.CRX)] ;REST OF DATE
	LSH	T3,^D12		;SHIFT IT OVER
	IORI	T1,(T3)		;OR INTO RESULT
	CAMGE	T1,UFDDAT	;OLD?
	JRST	UFDEXA		;YES.
	CAME	T1,UFDDAT	;SAME?
	JRST	UFDEXB		;NO. NEW. UPDATE.
	CAMGE	T2,UFDTIM	;SAME DATE. TIME OLD?
	JRST	UFDEXA		;NO.
UFDEXB:	MOVEM	T1,UFDDAT	;STORE NEWEST TIME
	MOVEM	T2,UFDTIM	;AND DATE
UFDEXA:	CAME	M,CH		;LOGGED-IN = LOGGED-OUT?
	JRST	UFDEXC		;NO--SEE IF WE NEED TO RECOMP
	CAME	M,[377777,,777777] ;BOTH INFINITE
	JRST	UFDEXC		;NO--SEE IF WE NEED TO RECOMP
	SKIPE	T1,U.QTA	;PICK UP QUOTA SWITCH -- SKIP IF ALL
	CAMN	T1,UFDFSN	;SKIP IF NOT THIS STR
	JRST	UFDEXC		;HE SAID /QUOTA:STR FOR THIS STR DO IT
	MOVE	T1,SRCBUF+.RBSTS ;TURN ON LOGGED IN BIT
	TXO	T1,RP.LOG	; FOR THIS STR BUT
	JRST	UFDEX2		; DO NOT RECOMP
UFDEXC:	MOVE	T1,SRCBUF+.RBSTS	;STATUS BITS
	TLZ	F,FL.ERR	;CLEAR ERROR-IN-FILES BIT
	TLNE	T1,RP.ERR	;ANY ERROR BITS SET FOR FILES IN THIS UFD?
	TLO	F,FL.ERR	;YES, SET FLAG AND LOOK FOR THEM
	SKIPE	T2,U.QTA	;PICK UP QUOTA SWITCH (SKIP IF ALL)
	CAMN	T2,UFDFSN	;NOT ALL--DO THIS STR?
	  JRST	UFDEXD		;[653] RECOMPUTE THIS STR IF NO OTHER USERS
	CAML	CH,SRCBUF+.RBUSD	;IF USED IS OVER LOGGED-OUT QUOTA,
	SKIPGE	SRCBUF+.RBUSD	;OR THE USED COUNT .LT. 0,
	TXO	T1,RP.LOG	; SIMULATE CRASH/REENTRY
	TXOE	T1,RP.LOG	;SKIP IF LOGGED IN BIT ALREADY ON
	TXNE	F,R.RCOM	;DON'T RECOMPUTE IF WE ALREADY HAVE
	JRST	UFDEX2		;NO, GO SET IT AND PROCEED
	TRNE	F,R.DBUG	;[626] DEBUGGING?
	  JRST	UFDEX2		;[626] YES - NEVER RECOMPUTE UNLESS ASKED
UFDEXD:	OTHUSR	T2,		;OTHER USERS THIS PPN
	  JRST	[CAMN T2,PPN	;CLAIMED NO SEE IF UUO IN
		 JRST UFDEX6	;UUO EXISTS--NO OTHER USERS
		 JRST .+1]	;DO NOT KNOW
	MOVX	T2,%NSHJB
	GETTAB	T2,
	  MOVEI	T2,100		;ASSUME 64
	MOVNI	T2,(T2)		;[644] NEGATE
	HRLZS	T2		;LH T2=-NUMBER OF REAL JOBS
UFDEX1:	MOVEI	T1,1(T2)	;T1=NEXT JOB NUMBER
	CAMN	T1,THSJOB	;IS IT THIS ONE?
	JRST	UFDEX4		;YES, DONT BOTHER
	MOVEM	T1,CHRBUF+.DFGJN
	MOVE	T1,UFDFSN
	MOVEM	T1,CHRBUF+.DFGNM	;NAME OF STR
	MOVE	T1,PPN
	MOVEM	T1,CHRBUF+.DFGPP
	MOVEI	T1,CHRBUF
	GOBSTR	T1,		;SEE IF STR IS IN THAT JOB'S SEARCH LIST
	  JRST	UFDEX4		;NOT IN THIS JOBS LIST OR NOT OUR PPN
	JRST	UFDEX5		;OK IS IN SOMEBODY ELSES SEARCH LIST SAME PPN
UFDEX4:	AOBJN	T2,UFDEX1	;LOOP FOR ALL JOBS
;HERE TO LOOKUP ALL FILES AND RECOMPUTE .RBUSD
; ALSO LOOK FOR ANY FILES WITH ERRORS, AND PRINT MESSAGE WHEN FOUND

UFDEX6:	SETZM	WILDBK		;CLEAR WILD FILE LOOKUP SPECIFICATION AREA
	MOVE	T1,[XWD WILDBK,WILDBK+1]
	BLT	T1,WILDBK+.FXLEN-1
	MOVSI	T1,(FX.DIR!FX.PHY!FX.NOM!FX.PRT)	;/OKNONE, DIR SPECIFIED
	MOVEM	T1,WILDBK+.FXMOD	;SETUP MOD WORD
	TLO	T1,(FX.STR)	;NOTE STR SW SET OFF
	MOVEM	T1,WILDBK+.FXMOM	;MOD WORD MASK
	MOVE	T1,PPN	;GET USER'S PPN
	MOVEM	T1,WILDBK+.FXDIR	;THAT'S NOT WILD
	SETOM	WILDBK+.FXDIM
	MOVE	T2,UFDFSN	;FILE STRUCTURE NAME
	MOVEM	T2,WILDBK+.FXDEV	;THAT'S FIXED, TOO
	SETZM	WLDPNT		;WILD INITIALIZE FLAG
	MOVSI	T1,'*  '	;SET UP TO STORE STAR IN
	MOVEM	T1,WILDBK+.FXNAM; FILE NAME
	MOVEM	T1,WILDBK+.FXEXT; EXTENSION
	MOVEM	T1,WILDBK+.FXDIR+2 ; AND 5 SFD'S
	MOVEM	T1,WILDBK+.FXDIR+4 ;  ..
	MOVEM	T1,WILDBK+.FXDIR+6 ;  ..
	MOVEM	T1,WILDBK+.FXDIR+10 ; ..
	MOVEM	T1,WILDBK+.FXDIR+12 ; ..
	SETOM	WILDBK+.FXBFR		;NO /BEFORE
	SETOM	WILDBK+.FXSNC		;NO /SINCE
	SETZB	T1,T3
	MOVEM	T2,CHRBUF	;SAVE STR NAME FOR DSKCHR
	OPEN	US1,T1		;OPEN FILE STRUCTURE
	  JRST	UFDSE2
	SETZM	SRCBUF+.RBQTR	;CLEAR NQC COUNTER
	SETZM	SRCBUF+.RBUSD	;CLEAR USED WORD
	SETOM	RPERCT		;INIT ERROR COUNTER
	MOVE	T1,[XWD .DCUFT+1,CHRBUF]
	DSKCHR	T1,		;GET CURRENT UFBTAL
	  JRST	UFDS9A
	AOSE	RECFLG		;FIRST STR TO RECOMP?
	JRST	LOKALL
	INFO	RDU,<Recomputing disk usage>
	  JFCL
	OUTPUT	TTY,		;[461] THIS MAY TAKE A WHILE, SO SAY
				;[461]  SOMETHING TO KEEP HIM PATIENT
;LOOP OVER ALL FILES ON THIS STR UNDER THIS UFD

LOKALL:	MOVE	T1,[XWD LOKBLN,LOKBLK]
	PUSHJ	P,.LKWLD##	;GET NEXT FILE SETUP FOR LOOKUP
	  JRST	UFDSUM		;THAT IS ALL
	LOOKUP	US1,SECBUF	;LOOKUP FILE
	  JRST	[PUSHJ	P,E.DFL##	;REPORT LOOKUP ERROR
		JRST	LOKALL]	;AND PROCEED
	MOVE	T1,SECBUF+.RBALC	;GET BLOCKS ALLOCATED FOR THIS FILE
	ADDM	T1,SRCBUF+.RBUSD	;COUNT FOR ALL FILES
	MOVE	T4,SECBUF+.RBSTS	;PICK UP STATUS INFO
	TXNE	T4,RP.NQC	;NOT QUOTA CHECKED
	ADDM	T1,SRCBUF+.RBQTR	;YES--COUNT UP 
	TRNN	T4,RP.ERR	;ANY ERROR BITS SET?
	JRST	LOKALL		;NO
	AOSE	RPERCT		;IS THIS THE FIRST ONE WITH ERRORS?
	JRST	NFSTER		;NO
LGNFEA:	MOVEI	M,[ASCIZ /%LGNFEA /]
	PUSHJ	P,MSG
	MOVE	T1,UFDFSN	;YES--GET FILE STRUCTURE NAME
	PUSHJ	P,.TSIXN##	;PRINT IT
	MOVEI	M,[ASCIZ / file errors are:
/]
	PUSHJ	P,MSG		;PRINT BASIC WARNING

DEFINE	ERRBIT	(BIT,MSG),<
	MOVEI	T1,[ASCIZ /MSG/]
	XLIST
	TRNE	T4,BIT
	PUSHJ	P,ERRFIL
	LIST
	SALL
>

LGNFED:NFSTER:	ERRBIT	RP.BDA,<%LGNFED damage>
LGNFEC:	ERRBIT	RP.CRH,<%LGNFEC close after crash>
LGNFER:	ERRBIT	RP.BFA,<%LGNFER error restoring>
LGNHRE:	ERRBIT	RP.FRE,<%LGNHRE hard read errror>
LGNHWE:	ERRBIT	RP.FWE,<%LGNHWE hard write error>
LGNSDC:	ERRBIT	RP.FCE,<%LGNSDC software detected checksum error>
	JRST	LOKALL

;SUBROUTINE TO REPORT ERROR IN A FILE.
;ARGS: T1=POINTER TO MESSAGE
;MUST PRESERVE T4
;
ERRFIL:	PUSHJ	P,.TSTRG##	;TYPE MESSAGE
	MOVEI	T1,[ASCIZ / in/];SET UP NOISE WORD
	PUSHJ	P,.TSTRG##	;SEND IT OUT
	PUSH	P,T4		;SAVE T4
	PUSHJ	P,.TFILE##	;TYPE OUT SPEC
	POP	P,T4		;RESTORE T4
	POPJ	P,		;RETURN
;GIVE SUMMARY OF QUOTAS
UFDSUM:	SKIPN	SRCBUF+.RBUSD	;ANY USED?
	JRST	UFDRER		;NO--SKIP MESSAGE
LGNQTA:	MOVEI	T1,[ASCIZ .[LGNQTA .]
	PUSHJ	P,.TSTRG##
	MOVE	T1,UFDFSN
	PUSHJ	P,.TSIXN##
	MOVEI	T1,[ASCIZ . In:.]
	PUSHJ	P,.TSTRG##
	MOVE	T1,SRCBUF+.RBQTF
	PUSHJ	P,.TDECW##
	MOVEI	T1,[ASCIZ . Out:.]
	PUSHJ	P,.TSTRG##
	MOVE	T1,SRCBUF+.RBQTO
	PUSHJ	P,.TDECW##
	MOVEI	T1,[ASCIZ . Used:.]
	PUSHJ	P,.TSTRG##
	MOVE	T1,SRCBUF+.RBUSD ;BLOCKS IN USE
	PUSHJ	P,.TDECW##	;PRINT IN DECIMAL
	MOVEI	T1,[ASCIZ .]
.]
	PUSHJ	P,.TSTRG##
;HERE WHEN LOOKED AT ALL FILES UNDER THIS UFD ON THIS STR

UFDRER:	CLOSE	US1,		;[667] CLOSE THE LAST FILE
	OUTPUT	TTY,		;[460] KEEP YOUR PANTS ON, GUY...
IFN	FTCMPR, <		;[667] IF ZERO COMPRESSION....
	MSTIME	T1,		;[667] GET A VERY RANDOM FILE NAME
	MOVEM	T1,CMPBLK##	;[667] SAVE IT FOR LATER
	MOVSI	T1,'LGN'	;[667] USE EXTENTION OF .LGN
	MOVEM	T1,CMPBLK##+1	;[667] SAVE IT ALSO
	SETZM	CMPBLK##+2	;[667]
	MOVE	T1,PPN		;[667] USE USERS PPN; NOT HIS DEFAULT
	MOVEM	T1,CMPBLK##+3	;[667]
	LOOKUP	US1,CMPBLK##	;[667] DOES FILE EXIST?
	  SKIPA			;[667] NO, VERY GOOD
	JRST	UFDRER		;[667] SUPERSCEDE WONT DO; GET ANOTHER NNME
	HRRZ	T1,CMPBLK##+1	;[667] PICK UP ERROR CODE
	JUMPN	T1,UFDRE2	;[667] IF IT WASNT FILE NOT FOUND
				;[667]   DON'T COMPRESS THE UFD
	ENTER	US1,CMPBLK##	;[667] CREATE THE TEMP FILE
	  JRST	UFDRE2		;[667] CONTINUE IF CAN'T WRITE FILE
	MOVEI	T1,US1		;[667] GET THE CHANNEL NUMBER
	MOVEM	T1,CMPDSK##	;[667] INTO DISK. BLOCK
	MOVE	T1,[7,,CMPDSK##];[667] FUNCTION CODE 7
	DISK.	T1,		;[667] TELL FILSER TO COMPRESS THE UFD
	  JFCL			;[667] COMPRESSION NOT IMPLEMENTED
	CLOSE	US1,		;[667] COMPRESS LIKE MAGIC
	LOOKUP	US1,CMPBLK##	;[667] FIND THE FILE AGAIN
	  JRST	NOCMPR		;[667] VERY VERY STRANGE
	SETZM	CMPBLK##	;[667] SET THE FILE NAME TO ZERO
	RENAME	US1,CMPBLK##	;[667] DELETE THE TEMP FILE
	  JRST	NOCMPR		;[667] INCREDIBLY STRANGE
UFDRE2:	CLOSE	US1,		;[667] FINISH UP
>				;[667] END IFN FTCMPR
	AOSE	RPERCT		;FIND ANY DISK ERRORS?
	JRST	UFDNCE		;ERRS FOUND, DO NOT CLEAR ERROR BITS
	MOVE	T1,[RP.ERR,,RP.ERR]	;BITS TO BE CLEARED
	ANDCAM	T1,SRCBUF+.RBSTS	;ZAP THEM OUT
UFDNCE:	MOVX	T1,RP.LOG		;[515] MAKE SURE RP.LOG GETS SET
	IORM	T1,SRCBUF+.RBSTS	;[515] ..
	SKIPGE	CCTYPED		;[566] CONTROL-C TYPED?
	 ANDCAM	T1,SRCBUF+.RBSTS;[566] YES - CLEAR RP.LOG
	MOVE	T2,CHRBUF+.DCUFT	;PREVIOUS UFBTAL
	CAMN	T2,[XWD 400000,0]	;IF NO PREVIOUS REFERENCES, UFBTAL CHANGED
	JRST	UFDEX3		;SO WE CANT DO ANYTHING ABOUT IT
	MOVE	T1,[XWD .DCUFT+1,CHRBUF]
	DSKCHR	T1,		;GET NEW UFBTAL
	  JRST	UFDS9A
	SUB	T2,CHRBUF+.DCUFT	;OLD-NEW=-DIFFERENCE FREE
	ADDM	T2,SRCBUF+.RBUSD	;=DIFFERENCE ALLOCATED
	JRST	UFDEX3		;ALL SET


UFDEX2:	MOVEM	T1,SRCBUF+.RBSTS	;MAKE SURE LOGGED IN BIT IS ON
UFDEX5:	LDB	T1,[POINTR(STATES,ST%TDS)]	;LEVEL D FIELD IN STATES WORD
	CAIL	T1,RACEY	;IF LESS THAT RACE CONDITION STUFF, DONT
	SETOM	SRCBUF+.RBUSD	;USE MONITOR'S COPY OF UFBTAL TO COMPUTE .RBUSD
UFDEX3:	MOVEI	T2,FBMTRY	;TIMES TO RETRY IF BUSY
	PUSHJ	P,SETEXL	;[613] SET UP SRCBUF FOR EXTENDED RENAME
	MSTIME	T1,
	IDIVI	T1,^D60000	;IN MINUTES
	DATE	T2,
	PUSH	P,T2		;SAVE T2
	DPB	T1,[POINT 11,T2,23]	;PUT IN TIME IN MINUTES
	DPB	T2,[POINT 23,SRCBUF+.RBPRV,35]	;PUT DATE AND TIME IN RIB
	POP	P,T2		;RESTORE DATE
	LSH	T2,-^D12	;SHIFT OFF 12 BITS
	DPB	T2,[POINTR(SRCBUF+.RBEXT,RB.CRX)] ;STORE IN RIB
	SETOM	CCWAIT		;DO NOT ALLOW HIM TO CONTROL-C OUT
				; AFTER WE SET THE LOGGED-IN BIT.
	RENAME	USR,SRCBUF
	  SKIPA	T1,SRCBUF+.RBEXT
	SKIPE	SECBUF		;DID WE RECOMP?
	SETZM	SRCBUF+.RBSTS	;YES--THE WE GAVE ERROR LIST
	JRST	UFDOK
LGNULF:
UFDSE3:	MOVEI	M,[ASCIZ .%LGNULF .]
	PUSHJ	P,MSG
	MOVEI	M,[ASCIZ . UFD LOOKUP failure .]
	PUSHJ	P,UFDSER	;TYPE ERROR LINE
	  JRST	UFDERT		;[476] RETRY LOOKUP
	JRST	UFDOK

LGNUEF:
UFDSE1:	MOVEI	M,[ASCIZ .%LGNUEF .]
	PUSHJ	P,MSG
	MOVEI	M,[ASCIZ . UFD ENTER failure .]
	PUSHJ	P,UFDSER	;TYPE ERROR LINE
	  JRST	UFDERT		;RETRY ENTER
LGNNUC:	MOVEI	M,[ASCIZ .%LGNNUC No UFD created
.]
	PUSHJ	P,MSG		;TELL POOR USER WE CANT MAKE A UFD

IFN	FTCMPR, <		;[667] IF ZERO COMPRESSION....

;[667] HERE ON AN ERROR WHILE TRYING TO ZERO COMPRESS A UFD

NOCMPR:	WARN	CZC,<Cannot zero compress UFD>
	  JFCL
	JRST	UFDRE2		;[667] CONTINUE UFD SET-UP

>				;[667] END IFN FTCMPR
;HERE TO EXIT FROM SUBROUTINE

UFDOK:	PUSHJ	P,ADDSTR	;ADD STR TO JOBS SEARCH LIST

;HERE TO CLEAR UFD INTERLOCK

	PUSHJ	P,STUFCL	;CLEAR UFD INTERLOCK
	JRST	.POPJ1		;ALL DONE

UFDSER:	HRRZS	T1,SRCBUF+.RBEXT	;ERROR CODE
	CAIN	T1,3		;SKIP IF NOT FILE BEING MODIFIED
	SOJG	T2,UFDSR1	;JUMP IF CAN STILL RETRY
	MOVE	T1,UFDFSN	;GET FILE STRUCTURE NAME
	PUSHJ	P,.TSIXN##	;PRINT NAME OF STR
	PUSHJ	P,MSG		;IDENTIFY FAILURE
	HRRZ	T1,SRCBUF+.RBEXT	;ERROR CODE
	PUSHJ	P,.TOCTW##	;PRINT IT IN OCTAL
	PUSHJ	P,.TCRLF##
	JRST	.POPJ1
UFDSR1:	MOVEI	T1,1
	SLEEP	T1,
	POPJ	P,


;[444] ROUTINE TO WRITE-ENABLE HI SEG AND LOCK OUT ANY OTHER JOBS
;[444] WHICH MIGHT TRY TO MODIFY IT.  ALSO LOCKS OUT CONTROL-C
;[444] SO USER CAN'T LEAVE HI SEG IN FUNNY STATE

LOK:	SETOM	CCWAIT		;[444] LOCK OUT CONTROL-C
	SETZ	T1,		;[444] WRITE-ENABLE HI SEG
	SETUWP	T1,		;[444] ..
	  JRST	LGNCUH		;[444] A FATE TOO EVIL TO CONSIDER
	MOVEM	T1,SVPROT	;[444] SAVE OLD HI SEG PROT CODE
	POPJ	P,		;[444] RETURN

;[444] ROUTINE TO UNDO EVERYTHING THE ABOVE ROUTINE DID

UNLOCK:	MOVE	T1,SVPROT	;[444] GET OLD HI SEG PROT CODE
	SETUWP	T1,		;[444] RESTORE IT
	  JRST	LGNCLH		;[444] PRETEND THIS DIDN'T REALLY HAPPEN
	PJRST	CTLCOK##	;[444] GO ENABLE CONTROL-C AGAIN

	STOP	CUH,<Can't unlock high segment.  Please call the operator.>

	STOP	CLH,<Can't lock high segment.  Please call the operator.>
 
;HERE WHEN UFD INTERLOCK IS BUSY - SLEEP AND RETRY

STUFBS:	TLNE	F,FL.WLD
	JRST	RETRYB
	MOVEI	T1,1
	SLEEP	T1,
	CAILE	P2,UFDGIL/3	;[556] WAITING LONG?
	JRST	STUFB1		;NO--JUST SLEEP
	TXOE	F,R.UIBM	;[514] TYPED UIB MESSAGE YET?
	  JRST	STUFB3		;[514] YES - SKIP IT
	PUSH	P,N		;[574] SAVE REGISTERS WIPED
	PUSH	P,M		;[574] BY MESSAGE STUFF
	PUSH	P,CH		;[574] ..
	WARN	UIB,<UFD Interlock busy for >
	  CAI
	MOVE	T1,UFDFSN	;[514] GET F.S. NAME
	PUSHJ	P,.TSIXN##	;[514] TYPE IT
	MOVEI	M,[ASCIZ /.  Wait please . . .
/]
	PUSHJ	P,MSG		;[514] KEEP HIM PATIENT
	OUTPUT	TTY,		;[514] ...
	POP	P,CH		;[574] RESTORE REGISTERS
	POP	P,M		;[574] ..
	POP	P,N

STUFB3:	OTHUSR	T1,		;OTHER USERS SAME PPN
	  PUSHJ	P,STUFCL	;NO. CLEAR INTERLOCK. NOTE: IF
				; OTHUSR IS NOT IMPLEMENTED THEN
				; NEITHER IS THE INTERLOCK.
STUFB1:	SOJG	P2,UFDSTA
	TXOE	F,R.UIB		;[514] IMPATIENT YET?
	  JRST	STUFB2		;[514] YES - GET TOUGH
	MOVEI	P2,UFDGIL	;[514] RESET COUNTDOWN TIMER
	JRST	STUFB1		;[514] IF AT FIRST U DON'T SUCCEED ...

STUFB2:	TLNN	F,FL.BAT	;[575] BATCH JOB?
	  JRST	STUFB4		;[575] NO: ITS OK TO BE TOUGH
	IFN	BATMAX,<	;[575] ONLY BATCON V. 100 AND UP KNOW
				;[575]  ABOUT REQUEUE ERRORS
	REQUE	UBT,<UFD Interlock busy too long.>
	  JFCL
	>			;[575] END IFN BATMAX
	IFE	BATMAX,<	;[575] IF OLD BATCON,
	FATAL	UBT,<UFD Interlock busy too long.>
	  JFCL			;[575] JUST FLUSH THE JOB AWAY
	>			;[575] END IFE BATMAX
STUFB4:
	PUSHJ	P,STUFCL	;[514] THROW THAT CLOWN OFF THE UFD
	JRST	UFDSTA		;[514] PROCEED

UFDSE2:	PUSHJ	P,STUFCL
	UFDSEM	OFF,<OPEN failure>




;SUBROUTINE TO TEST/SET OR CLEAR UFD INTERLOCK
;ENTER AT STUFCL TO CLEAR
;ENTER AT STUFC1 WITH T2=FUNCTION
;RETURN POPJ IF FAILED
;RETURN .POPJ1 IF OK

STUFCL:	PUSHJ	P,STUFC0
	  JFCL
	PJRST	CTLCOK##	;[520] ENABLE CTRL-C
STUFC0:	MOVEI	T2,.FSUCL
STUFC1:	LDB	T1,[POINTR(STATES,ST%TDS)]	;LEVEL D FIELD IN STATES WORD
	CAIGE	T1,RACEY	;SKIP IF INCLUDES RACE CONDITION STUFF
	JRST	.POPJ1		;NO, PRETEND WORKS
	MOVE	T1,[XWD 3,T2]
	MOVE	T3,UFDFSN
	MOVE	T4,PPN
	STRUUO	T1,
	  POPJ	P,
	SETOM	CCWAIT		;[520] LOCK OUT CTRL-C
	PJRST	.POPJ1

;SUBROUTINE TO SET UP HEADER FOR EXTENDED LOOKUP/ENTER/RENAME OF UFD

SETEXL:	MOVEI	T1,EXLLEN-1	;LENGTH OF ARG LIST
	MOVEM	T1,SRCBUF
	MOVE	T1,PPN	;NAME IS USER'S PPN
	MOVEM	T1,SRCBUF+.RBNAM
	MOVSI	T1,(SIXBIT .UFD.)	;EXT IS UFD
	MOVEM	T1,SRCBUF+.RBEXT
	MOVE	T1,MFDPPN	;DIRECTORY IS MFD
	MOVEM	T1,SRCBUF+.RBPPN
	SKIPGE	T1,U.UFDP	;[554] /UFDPROT SPECIFIED?
	  POPJ	P,		;[616] NO - ALL DONE
	ANDI	T1,777		;[554] MASK OUT JUNK
	LSH	T1,^D27		;[554] SLING OVER TO RIGHT PLACE
	MOVEM	T1,SRCBUF+.RBPRV;[554] PUT INTO ENTER BLOCK

	POPJ	P,


;[540] SUBROUTINE TO ZERO EXTENDED LOOKUP BLOCK

CLRRIB:	SETZM	SECBUF		;[540] CLEAR A WORD
	MOVE	T1,[SECBUF,,SECBUF+1]	;[540] 
	BLT	T1,SECBUF+.RBTIM;[540] SPREAD IT AROUND
	POPJ	P,		;[540] ALL DONE!
;THIS ROUTINE ADDS FILE STRUCTURE NAMED IN UFDFSN TO THE
; FILE STRUCTURE SEARCH LIST.

ADDSTR:	PUSHJ	P,.SAVE1##	;SAVE P1
	SETZB	P1,UFDDMF	;SET FLAG TO REMEMBER
	MOVEI	T1,.FSDSL
	MOVEM	T1,UFDMTP	;SET FUNCTION TO DEFINE SEARCH LIST
	SETOB	T2,UFDDMJ	;START JOBSTR WITH -1
	SETOM	UFDDMP		;CLEAR JOB AND PPN SO USES VALUES FOR THIS JOB
	TLZ	F,L.PEND	;BORROW THIS BIT TO MEAN FILE STRUCTURE THERE
MAKSRC:	MOVE	T1,[XWD 3,T2]
	JOBSTR	T1,		;GET USER'S NEXT FILE STRUCTURE
	  JRST	UFDSE8		;SYSTEM PROBLEM
	JUMPE	T2,MAKSR2	;MOUNT STOPS AT FENCE
	AOJE	T2,MAKSR2	;JUMP IF END OF LIST
	SOS	T2
	MOVEM	T2,UFDDMF+1(P1)
	JUMPE	T2,MAKSR1	;DONT DSKCHR THE FENCE
	MOVE	T1,[XWD 1,T2]
	DSKCHR	T1,		;GET CURRENT STATUS OF THIS FILE STRUCTURE
	  JRST	UFDSE9		;CANT FAIL
	MOVE	T2,UFDDMF+1(P1)	;GET BACK FILE STRUCTURE NAME
	CAME	T2,UFDFSN	;AND SEE IF WE ALREADY EXIST
	JRST	MAKSR1		;NO
	TLO	F,L.PEND
	MOVE	T1,T4
	LSH	T1,-4		;ROTATE A TO MATCH UP D.SWL AND L.WRTL
	XOR	T1,F		;COMPARE WRITE LOCK STATES
	TLNN	T1,L.WRTL	;SKIP IF DIFFERENT
	JRST	.POPJ		;NO CHANGE
	TLC	T4,(DF.SWL)
	SETZ	T3,
MAKSR1:	MOVEM	T3,UFDDMF+2(P1)	;SAVE PROJECT,PROGRAMMER NUMBER
	MOVEM	T4,UFDDMF+3(P1)	;SAVE WRITE PROTECT REQUEST
	ADDI	P1,3
	JRST	MAKSRC		;LOOP FOR ALL USER'S FILE STRUCTURES
UFDSE8:	UFDSEM	JUF,<System error - JOBSTR UUO failed>
UFDS9A:	PUSHJ	P,STUFCL
UFDSE9:	UFDSEM	DUF,<System error - DSKCHR UUO failed>

MAKSR2:	TLZE	F,L.PEND
	JRST	MAKSR3		;DONT ADD FILE STRUCTURE 
MAKSRA:	SKIPN	UFDDMF+1(T2)	;T2 STARTS AT 0 FROM ABOVE
	JRST	MAKSRB		;THE FENCE IS A 0
	ADDI	T2,3
	CAIE	T2,(P1)		;IF END, NO FENCE
	JRST	MAKSRA
	JRST	MAKSR4		;OK TO PROCEED
MAKSRB:	MOVE	T3,P1		;IF FENCE, MUST MOVE EVERYTHING DOWN 1 ENTRY
MAKSRL:	CAIG	T2,(T3)		;SKIP IF MORE
	JRST	MAKSR4
	MOVE	T1,UFDDMF(T3)
	MOVEM	T1,UFDDMF+3(T3)
	SOJA	T3,MAKSRL
MAKSR4:	MOVE	T1,UFDFSN
	MOVEM	T1,UFDDMF+1(T2)	;ADD NEW FILE STRUCTURE
	SETZB	T1,UFDDMF+2(T2)
	TLNE	F,L.WRTL
	TXO	T1,DF.SWL	;A SET TO 0 ABOVE
	TLNE	F,L.NCR
	TXO	T1,DF.SNC
	MOVEM	T1,UFDDMF+3(T2)
	ADDI	P1,3
MAKSR3:	MOVEI	T1,UFDMTP
	HRLI	T1,4(P1)	;LENGTH OF ARGUMENT LIST
	STRUUO	T1,
	  JRST	LGNCAS
	POPJ	P,
LGNCAS:	JUMPE	T1,STUFCL	; IF NOT IMPLEMENTED IGNORE ERROR
	PUSH	P,T1		;[466] SAVE ERROR CODE
	MOVEI	M,[ASCIZ "LGNCAS Can not add "]
	PUSHJ	P,UFDSMB
	MOVEI	M,[ASCIZ " to search list -- code="]
	PUSHJ	P,MSG
	PUSHJ	P,STUFCL
	POP	P,T1		;[466] RESTORE ERROR CODE
	PUSHJ	P,.TOCTW##	;PRINT THE ERROR CODE
	PJRST	.TCRLF##		;RETURN

UFDSMB:	PUSH	P,M		;SAVE MESSAGE ADDR
	MOVEI	CH,"?"
	PUSHJ	P,TYO
	TLNN	F,FL.BAT	;IS THIS A BATCH JOB?
	JRST	UFDSMC		;NO
	MOVEI	M,[ASCIZ .(1) .]
	PUSHJ	P,MSG		;PRINT ERROR SEVERITY
UFDSMC:	POP	P,M		;RESTORE TEXT OF MESSAGE
	PUSHJ	P,MSG
	MOVE	T1,UFDFSN	;GET STRUCTURE NAME
	PJRST	.TSIXN##	;PRINT IT


UFDSMP:	PUSHJ	P,UFDSMB
	PJRST	.TCRLF##
RETRYA:	PUSHJ	P,STUFCL
RETRYB:	AOS	PPN
	CLOSE	UFD,
	JRST	CHECK1

;SUBROUTINE TO SLEEP A WHILE OR UNTIL DACCFL IS SET POS

SNOOZE:	MOVE	T2,ACCTLN	; SET SLEEP TIME
	LSH	T2,-3		;   TO FILE LENGTH/8
	CAILE	T2,^D60		;IS SLEEP TIME OVER 60 SECONDS?
	MOVEI	T2,^D60		;YES--CHOP DOWN TO 60
SNOOZ1:	IFN	FASTLG,<
	SKIPLE	DACCFL		;IS DIRECTORY THERE?
	POPJ	P,		;YES, NON-SKIP RETURN
	>			;[556] END IFN FASTLG

	MOVEI	T1,1		;SETUP FOR THE LITTLE SLEEP
	SLEEP	T1,
	SOJG	T2,SNOOZ1	;KEEP YOUR PANTS ON
	AOS	0(P)		;FOR A WHILE, THEN
	POPJ	P,		;RETURN IMPATIENT
MSG:	HRLI	M,(POINT 7,)	;CREATE A BYTE POINTER
MSGL:	ILDB	CH,M		;LOAD UP M
	JUMPE	CH,.POPJ	;RETURN ON NULL
	PUSHJ	P,TYO		;TYPE THE CHAR
	JRST	MSGL
	SUBTTL	Subroutine to create a path

;ARGS:	U.PATH=PATH DESIRED
;	UFDFSN=STR NAME
;CALL WITH:
;	MOVEI	T1,1		;TO CREATE SFDS
;	MOVEI	T1,0		;TO NOT CREATE SFDS
;	PUSHJ	P,ENTPTH
;	RETURN HERE ALWAYS (PTHBUF SET UP FOR PATH. UUO)

ENTPTH:	PUSHJ	P,.SAVE3##	;[746] SAVE P1 AND P2 AND P3
	MOVEI	P3,(T1)		;[746] SAVE FLAG TO CREATE SFDS
	HRRZ	T1,U.PATH+.FXDIR;GET PROG NUMBER
	CAIN	T1,UNIPRG	;IS IT #
	HRRZ	T1,PPN		;YES--CORRECT FOR ACTUAL NO.
	HRRM	T1,U.PATH+.FXDIR;STORE BACK CORRECTED NUMBER
	SETZM	PTHBUF+.PTFCN	;IGNORED ON ENTER
	MOVEI	T1,.PTSCN	;/SCAN:NO
	MOVEM	T1,PTHBUF+.PTSWT;STORE THE SWITCH
	MOVE	T1,U.PATH+.FXDIR;GET PPN
	MOVEM	T1,PTHBUF+.PTPPN;STORE IN PATH
	MOVEI	P1,PTHBUF+.PTPPN+1	;WHERE PATH GOES
	MOVEI	P2,U.PATH+.FXDIR+2	;WHERE PATH COMES FROM
	HRLI	P1,-<.FXLND-1>		;[573] INIT MAX LOOP CNTR
ENTPTL:	SKIPN	(P2)		;ANOTHER SFD GIVEN?
	POPJ	P,		;NO. DONE
	SETZM	(P1)		;[746] MAKE END OF LIST
	MOVE	T1,(P2)		;[746] GET NAME OF SFD
	JUMPE	P3,ENTPT2	;[746] JUMP IF DOESNT WANT SFDS MADE
	MOVEI	T2,17		;[746] MODE
	MOVE	T3,UFDFSN	;[746] STR NAME
	SETZM	T4		;[746] NO BUFFERS
	OPEN	USR,T2		;[746] OPEN STR
	  POPJ	P,		;A FATE TOO EVIL TO CONSIDER
	MOVSI	T2,'SFD'	;EXTENSION IS SFD
	SKIPGE	T3,U.SFDP	;[550] /SFDPROT SPECIFIED?
	  SETZM	T3		;[550] NO - ASSUME STANDARD
	ANDI	T3,777		;[550] MASK OUT JUNK
	LSH	T3,^D27		;[550] SLING OVER TO LEFT HALF
	MOVEI	T4,PTHBUF	;PATH POINTER
	ENTER	USR,T1		;TRY TO ENTER SFD
	  SKIPA			;CAN NOT--SEE WHY
	JRST	ENTPT1		;WE WON.
	HRRZ	T3,T2		;GET ERROR CODE
	CAIE	T3,ERFBM%	;IS FILE BEING MODIFIED?
	CAIN	T3,ERCSD%	;OR DOES IT EXIST YET?
	JRST	ENTPT1		;MODIFIED OR EXITSING -- ALL OK
	PUSH	P,T3		;SAVE T3
	CAIN	T3,ERLVL%	;LEVEL ERROR?
LGNSND:	SKIPA	T1,[[ASCIZ /%LGNSND SFD's nested too deeply(/]]
LGNSEF:	MOVEI	T1,[ASCIZ /%LGNSEF SFD enter failure (/]
	PUSHJ	P,.TSTRG##	;TYPE THE STRING
	POP	P,T1		;RESTORE NUMBER
	PUSHJ	P,.TOCTW##	;TYPE CODE
	MOVEI	T1,[ASCIZ /) /] ;LOAD UP A DELIMITER
	PUSHJ	P,.TSTRG##	;TYPE IT OUT
	MOVE	T1,UFDFSN	;LOAD UP STR NAME
	PUSHJ	P,.TSIXN	;TYPE IT OUT
	MOVEI	T1,":"		;LOAD UP A :
	PUSHJ	P,.TCHAR##	;TYPE IT OUT
	MOVE	T1,(P2)		;GET SFD NAME
	PUSHJ	P,.TSIXN##	;TYPE THAT OUT TOO
	MOVEI	T1,[ASCIZ /.SFD/] ;WE KNOW THE EXTENSION
	PUSHJ	P,.TSTRG##	;SO TELL THE USER
	MOVEI	T1,[PTHBUF]	;[746] POINT TO PATH. BLOCK
	PUSHJ	P,.TDIRB##	;[746] LET SCAN TYPE IT
	PJRST	.TCRLF##	;TYPE A CRLF AND EXIT
ENTPT1:	CLOSE	USR,0		;[454] CLOSE OUT THE SFD
ENTPT2:	MOVEM	T1,(P1)		;[746] STORE T1 (SFD NAME FROM ABOVE)
				; SO SFD'S NEST CORRECTLY.
	ADDI	P2,2		;POINT TO NEXT NAME
	AOBJN	P1,ENTPTL	;[573] LOOP OVER THE PATH
;[614] ENTPT1+4			/LC
	POPJ	P,

	PRGEND
	TITLE	LGNSET - Module to set up user profile for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	LGNDCL

	SUBTTL	Set user profile -- privileged SETUUO's

;ROUTINE TO DO PRIVILEGED SETUUO'S
;ARGS:	U.TIME,U.SPL,U.CORE,U.DFER
;CALL WITH:
;	PUSHJ	P,PRVSET
;	RETURN HERE
;
PRVSET:	TXNE	F,R.SESS	;IF SESSION COMMAND, JUST SET THE ACCOUNT
	JRST	PRSET5
	SKIPGE	T1,U.TIME	;WANT TIME LIMIT SET?
	JRST	PRSET1		;NO--CHECK SPOOL
	HRLI	T1,.STTLM	;YES--SET UP ENTIRE ARGUMENT
	MOVE	T2,['STL',,[ASCIZ .time limit.]]
	PUSHJ	P,SETIT		;DO THE SET UUO
PRSET1:	HRROI	T1,.GTSPL	;[364] GET SPOOL BITS FOR JOB TO SEE
	GETTAB	T1,		;[364] IF SYSTEM HAS SPOOLING. IF NOT,
	  JRST	NSPOOL		;[364] DON'T TRY TO SET SPOOL BITS.
	LDB	T1,SPLBTS	;GET SPOOL BITS FROM ACCT.SYS 
	IOR	T1,U.SPL	;OR IN ONES REQUESTED BY  USER
	HRLI	T1,.STSPL	;COMPLETE ARGUMENT
	MOVE	T2,['SSB',,[ASCIZ .spool bits.]]
	TRZ	T1,-JS.PAL-1	;[365,371] CLEAR BITS WHICH AREN'T DEVICES
	PUSHJ	P,SETIT		;GO SET IT
	MOVE	T1,STATS2	;[374] GET SECOND STATES WORD
	TXNN	T1,ST%GAL	;[374] CAN WE SUPPORT GALAXY-10?
	JRST	NSPOOL		;[374] NO -- DON'T TRY, THEN
	MOVX	T1,%CNVER	;GET THE MONITOR'S VERSION NUMBER
	GETTAB	T1,
	  JRST	PRST1C		;ERROR. SKIP THE SETUUO
	LDB	T2,[POINT 6,T1,23] ;MONITOR VERSION NUMBER
	CAIGE	T2,7		;IS THIS 7.00 OR LATER MONITOR?
	JRST	PRST1C		;NO. SKIP THIS SETUUO
	LDB	T1,[POINT 3,ENTRY+PROWRD,23]	;YES. GET OPERATOR PRIVILEGE CODE
	HRLI	T1,.STOPP
	MOVE	T2,['SOP',,[ASCIZ .operator privileges.]]
	PUSHJ	P,SETIT
PRST1C:	SKIPGE	T1,U.DFER	;[365] WAS THERE A /DEFER SWITCH?
	JRST	NSPOOL		;[365] NO -- SAVE A UUO
	HRLI	T1,.STDFR	;[365] SETUUO CODE FOR DEFERRED SPOOLING
	MOVE	T2,['SDS',,[ASCIZ .deferred spooling bit.]]
	PUSHJ	P,SETIT		;[365] DO THE SETUUO
NSPOOL:	LDB	T2,[POINT 9,ENTRY+VMPWRD,8]	;[521] GET PHYS. LIMIT
	LSH	T2,^D9		;[551] CONVERT TO WORDS
	SKIPG	T1,U.CORE	;[551] GET /CORE ARG IF ONE
	JRST	PRST1B		;[551] NO ARG--USE PHYS. LIMIT
	CAIL	T1,1000		;[551] IS ARG ALREADY IN WORDS ?
	JRST	PRST1A		;[551] YES--SKIP ON
	CAILE	T1,^D256	;[551] IS ARG UNREASONABLE ?
	LSH	T1,^D9		;[551] YES--ASSUME HE MEANT P AND CONVERT
	CAIG	T1,^D256	;[551] IS ARG IN K ?
	LSH	T1,^D10		;[551] YES--CONVERT TO WORDS
PRST1A:	CAML	T1,T2		;[551] IS ARG < OR = PHYS. LIMIT
PRST1B:	MOVE	T1,T2		;[551] NO--USE PHYS. LIMIT FROM ACCT.SYS
	HRLI	T1,.STCLM	;SET UUO CODE FOR CORE
	MOVE	T2,['SCL',,[ASCIZ .core limit.]]
	PUSHJ	P,SETIT		;SET THE CORE LIMIT
	SKIPL	NEWACT		;[613] DO WE HAVE NEW ACCT.SYS?
	POPJ	P,0		;NO--ALL DONE
	MOVE	T1,STATS2	;[374] GET SECOND STATES WORD
	TXNN	T1,ST%VMS	;SKIP IF VM MONITOR
	JRST	PRSET3		;NOT VM DO NOT TRY UUO'S
	MOVE	T1,[.STUVM,,T3]	;LOAD POINTER TO STUFF
	LDB	T3,[POINT 9,ENTRY+VMPWRD,8] ;GET PHYSICAL LIM
	LDB	T4,[POINT 9,ENTRY+VMPWRD,17] ;GET VIRT LIM
	SKIPE	T3		;DO NOT TURN 0 INTO 1
	AOS	T3		;ELSE INCREMENT
	SKIPE	T4
	AOS	T4
	HRL	T3,T4		;MAKE XWD VIRT,,PHYS
	MOVE	T2,['SVM',,[ASCIZ /maximum virtual and physical limits/]]
	PUSHJ	P,SETIT		;GO DO THE SET
PRSET3:	SKIPL	EQACT		;[356] SET 6.02 STUFF?
	JRST	PRSET5		;[431] NO
	LDB	T1,[POINT 9,ENTRY+XPDWRD,35]	;[352] GET QUOTA
	HRLZ	T1,T1		;[426] PUT QUOTA IN LEFT HALF
	TLC	T1,777		;[446] SEE IF QUOTA=-1
	TLCN	T1,777		;[643] ..
	  JRST	PRSET4		;[430] YES -- DON'T DO ENQC.
	HRR	T1,THSJOB	;[426] AND JOB NUMBER IN RIGHT HALF
	MOVE	T2,[XWD 2,T1]	;[352] SET UP POINTER TO ARG
	ENQC.	T2,		;[352] DO IT UP
	 SKIPA			;[507] WOOPS - CHECK IT OUT
	  JRST	PRSET4		;[507] OK - KEEP ON TRUCKIN
	CAMN	T2,[XWD 2,T1]	;[507] AC UNCHANGED (UUO NOT IMPLEMENTED)?
	  JRST	PRSET4		;[507] YES - DON'T BOTHER USER THEN
	WARN	EUF,<ENQC. UUO failed.  Error code = >
	  CAI			;[507] NON-JFCL NO-OP
	MOVE	T1,T2		;[507] PICK UP ERROR CODE
	PUSHJ	P,.TOCTW##	;[507] SPIT IT OUT
	PUSHJ	P,.TCRLF##	;[507] ..
	PUSHJ	P,CALOPR	;[510] TELL USER TO CALL THE OPERATOR

PRSET4:	MOVE	T1,STATS2	;[425] GET 2ND STATES WORD
	TXNN	T1,ST%SHC	;[425] DOES MONITOR HAVE SCHED. UUO?
	  JRST	PRSET5		;[425] NO -- SKIP THIS STUFF
	LDB	T1,[POINT 9,ENTRY+XPDWRD,26]	;[425] GET SCHED TYPE
	IDIVI	T1,4		;[425] GET INDEX INTO TABLE
	ADD	T1,SCDTBL	;[425] ADD TABLE BASE ADDRESS
	TLNE	F,FL.BAT	;[452] BATCH JOB?
	  ADDI	T1,SCDSIZ/2	;[452] YES - INDEX INTO BATCH PART OF TBL
	LDB	T4,BYTTAB(T2)	;[425] INDEX BYTE POINTER BY REMAINDER
				;[622]  TO GET CPU CLASS IN T4
	MOVX	T1,%SSMSI	;[622] NOW GETTAB THE MEDIUM-TERM
	GETTAB	T1,		;[622] SCHEDULING INTERVAL TO SEE
	  JRST	PRSET5		;[622] IF THE CLASS SCHEDULER IS RUNNING
	JUMPE	T1,PRST4B	;[672] [622] IF INTERVAL=0, CLASS SCHEDULER
				;[622]  ISN'T RUNNING SO SKIP CHECKS
	MOVX	T1,%SSSET	;[672] CHECK FLAG FOR CLASS
	GETTAB	T1,		;[672] SCHEDULING
	  SETO	T1,		;[672] NOT WMU CLASS SCHEDULER
	JUMPE	T1,PRST4B	;[672] SKIP CHECKS IF RUNNING ROUND ROBIN
	HRRZI	T1,.GTCQP	;[672] NOW GET CPU QUOTA FOR THIS CLASS
	HRL	T1,T4		;[672] T4 HAS OUR CLASS
	GETTAB	T1,		;[672]
	  JRST	PRSET5		;[672] MONITOR NOT BUILT FOR CLASS SCHEDULAR
	TRNE	T1,-1		;[672] IF PRIMARY % NON-ZERO,
	JRST	PRST4B		;[672]  WERE OK
	MOVE	T2,[%SSBBQ]	;[672] CHECK BACKROUND BATCH
	GETTAB	T2,		;[672] GET BB CLASS
	  SETO	T2,		;[672] NO BB
	CAMN	T2,T4		;[672] IS USER IN BB?
	  JRST	PRST4B		;[672] YES, HE IS OK
	JUMPL	T1,PRST4A	;[672] GIVE ERROR IF FIXED SWAPIN BIT SET
	HRRZI	T1,.GTSQP	;[672] NOW GETTAB SECONDARY ALLOCATION
	HRL	T1,T4		;[672] FOR THIS CLASS
	GETTAB	T1,		;[672]
	  JRST	PRST4B		;[672_] NOT WMU SCHEDULAR
	JUMPN	T1,PRST4B	;[672] OK IF THERE IS A SECONDARY QUOTA
PRST4A:	FATAL	CWR,<CPU class quota is zero: you would never run>
	  JFCL

PRST4B:	HRLI	T4,-1		;[425] -1 MEANS THIS JOB
	MOVE	T1,[1,,T2]	;[425] SET UP POINTER FOR SCHED. UUO
	MOVE	T2,[400005,,T3]	;[425] XWD FUNC, LOC OF ARG LIST
	MOVEI	T3,1		;[425] ONLY ONE ARGUMENT
	SCHED.	T1,		;[425] ZAP!
	  SKIPA			;[425] WOOPS
	JRST	PRSET5		;[425] ALL SET
	CAMN	T1,[1,,T2]	;[425] IF AC UNCHANGED, UUO NOT
	  JRST	PRSET5		;[425] IMPLEMENTED SO FORGET MESSAGE
	WARN	SCF,<SCHED. UUO failed.  Error code = >
	  CAI			;NON-JFCL NO-OP
	PUSHJ	P,.TOCTW##	;[425] TELL HIM ALL ABOUT IT
	PUSHJ	P,.TCRLF##
	PUSHJ	P,CALOPR	;[510] PLEASE CALL OPR
	JRST	PRSET5

BYTTAB:	POINT	9,(T1),8	;[425] BYTE PTR FOR REMAINDER=0
	POINT	9,(T1),17	;[425] REMAINDER=1
	POINT	9,(T1),26	;[425] T1 HAS ADDR OF WORD TO LOOK AT
	POINT	9,(T1),35

PRSET5:	MOVE	T1,[.ACTCH,,T2]
	MOVEI	T2,1		;ONE ARGUMENT
	HRROI	T3,U.ACTS	;SEVEN BIT BYTE POINTER TO ACCOUNT STRING
	ACCT.	T1,		;TELL THE MONITOR THE USER'S ACCOUNT STRING
	  PUSHJ	P,LGNCSA	;ERROR
	TXNE	F,R.SESS	;IF SESSION COMMAND JUST SET THE ACCOUNT
	POPJ	P,
	MOVE	T1,STATS2	;[356,374] GET 2ND STATES WORD
	TXNN	T1,ST%IPC	;DO WE HAVE IPCF?
	POPJ	P,0		;NO--RETURN NOW
	MOVE	T1,[%IPCCP]	;GET THE PID OF [SYSTEM]IPCF
	GETTAB	T1,		; ..
	  POPJ	P,0		;CAN NOT FAIL
	MOVEM	T1,TOPID	;SAVE AS TARGET OF THIS MESSAGE
	MOVX	T1,IP.CFP	;INDICATE THAT I HAVE PRIVS AND
	MOVEM	T1,IPCFLG	; WANT TO USE THEM
	MOVE	T1,[3,,IPCMSG]	;POINTER TO THE MESSAGE
	MOVEM	T1,IPCPTR	; ..
	MOVX	T1,.IPCSQ	;WANT TO SET QUOTA
	MOVEM	T1,IPCMSG	;STORE AS FUNCTION
	HRRZ	T1,ENTRY+VMPWRD	;GET IPCF QUOTAS
	MOVEM	T1,IPCQTA	;STORE IT AWAY
	MOVE	T1,THSJOB	;[351] GET MY JOB NUMBER
	MOVEM	T1,IPCJOB	;STORE THAT AWAY
	MOVEM	T1,FMPID	;ALSO LOAD AS SENDERS PID
	MOVE	T1,[4,,IPCFLG]	;POINTER TO THE MESSAGE
	IPCFS.	T1,		;SEND IT
	  JRST	IPCSER		;SEND ERROR
	MOVX	T1,IP.CFB	;SAY WE DON'T WANT TO BLOCK
	MOVEM	T1,IPCFLG
	MOVE	T1,[4,,IPCFLG]	;SET UP TO GET BACK AN
	IPCFR.	T1,		; ANSWER.
	  JRST	IPCRER		;NO ANSWER
	MOVE	T1,IPCFLG	;GET THE FALGS WORD
	TXNN	T1,IP.CFE	;ANY ERROR CODE?
	POPJ	P,0		;NO--RETURN
	WARN	ESI,<Error from [SYSTEM]IPCF>
	  POPJ	P,0		;ALL DONE
	JRST	IPCQER		;TELL HIM MORE

IPCSER:	WARN	EIS,<Error in send to [SYSTEM]IPCF>
	  POPJ	P,0		;ALL DONE
	JRST	IPCQER		;TELL HIME MORE
IPCRER:	CAIN	T1,IPCNP%	;QUEUE EMPTY?
	POPJ	P,0		;YES--ALL IS WELL
	WARN	EIR,<Error in receive from [SYSTEM]IPCF>
	  POPJ	P,0
IPCQER:	PUSHJ	P,.TCRLF##	;OUTPUT CRLF
	WARN	IQS,<IPCF quotas may not be set correctly>
	  JFCL
	PUSHJ	P,CALOPR	;[510] TELL USER TO CALL OPR
	POPJ	P,0		;RETURN


LGNCSA:
IFE VALDSW,<			;VALIDATION IS NOT REQUIRED SO JUST WARN USER
	WARN	CSA,<Cannot set the account>
	JFCL
	POPJ	P,
> ;END IFE VALDSW

IFN VALDSW,<			;VALIDATION IS REQUIRED, DON'T LET USER LOGIN
	FATAL	CSA,<Cannot set the account>
> ;END IFN VALDSW

;[344] TABLES FOR ROUTINE TO DO TRMOP.S AND SET TERMINAL STUFF

IFN	SETTTY,<

	DEFINE X(TCODE,ARG,FLAGS),<
	XWD	ARG,FLAGS!TCODE+1000 >

;FLAGS
TF.CMP==1B18		;USE COMPLEMENT OF VALUE STORED BY SCAN

TTAB:	X .TOTRM,U.TYPE,0	;[675] DO TYPE SETTING FIRST THEN ALTER
				;[675] THE DEFAULTS.
	X .TOALT,U.ALTM,TF.CMP	;[472] TRMOP.S WHICH ARE DONE BEFORE
	X .TOBLK,U.BLNK,TF.CMP	;[472] PRINTING NOTICE.TXT
	X .TONFC,U.CRLF,TF.CMP
	X .TODBK,U.DBRK,0
	X .TOLCP,U.ECHO,TF.CMP
	X .TOFLC,U.FILL,0
	X .TOFRM,U.FORM,0
	X .TOSND,U.GAG,TF.CMP
	X .TOLCT,U.LC,TF.CMP
	X .TOPAG,U.PAGE,0
	X .TOPSZ,U.PGSZ,0
	X .TORTC,U.RTC,0
	X .TOTAB,U.TABS,0
	X .TOTAP,U.TAPE,0
	X .TOWID,U.WDTH,0
	X .TODEM,U.TTDE,0
	X .TODIS,U.DISP,0	;[743]
	X .TOLCT,U.UC,0		;[747]
	X .TOTDY,U.TIDY,0	;[747]
TTLNTH=.-TTAB

PTAB:	X .TORSP,U.RSPD,0	;[472] TRMOP.S WHICH SHOULD BE DONE
	X .TOTSP,U.XSPD,0	;[472] AFTER PRINTING NOTICE.TXT
PTLNTH=.-PTAB			;[472]

	>		;[344] END IFN SETTTY

	SUBTTL	Set user profile -- non-privileged SETUUOs
 
;HERE AFTER LOGIN UUO IS DONE TO SET OPTIONAL STUFF
USRSET:	HRROI	T1,.GTWCH	;[446] TRY GETTAB TO GET THIS JOB'S
	GETTAB	T1,		;[446] WATCH BITS. IF GETTAB FAILS,
	  JRST	TINY		;[446] THIS MUST BE A 1040 MONITOR
	LDB	T1,WATBTS	;GET WATCH BITS
	LSH	T1,SHFWAT
	HRRZ	T2,U.WAT	;GET WATCH BITS
	LSH	T2,WCHLSH##	;SHIFT TO CORRECT PLACE
	IOR	T1,T2		;OR IN THE USER SETTINGS
	MOVE	T2,ENTRY+PROWRD	;GET THE PROFILE WORD
	TLNE	T2,P.WVER	;WANT TO WATCH VERSIONS?
	TRO	T1,(JW.WVR)	;YES--TURN ON VERSION WATCHING
	SKIPE	NEWACT		;IF OLD ACCT.SYS FORMAT
	TLNE	T2,P.WMTA	; OR USER WANTS MTA WATCHING
	TRO	T1,(JW.WMT)	; TURN ON WATCH MTA
	TLNE	T2,P.WFIL	;USER WANTS FILE WATCHING
	TRO	T1,(JW.WFI)
	MOVE	T2,.FLVRB##	;[455] GET /VERBOSITY FROM SCAN
	LSH	T2,^D6		;[542] SHIFT OVER TO RIGHT PLACE
	ANDI	T2,700		;[542] THROW AWAY GARBAGE BITS
	IOR	T1,T2		;[455] OR INTO WATCH BITS
	HRLI	T1,.STWTC	;SET WATCH FUNCTION
	MOVE	T2,['SWB',,[ASCIZ .watch bits.]]
	SKIPE	U.NWAT		;[336] SKIP THE SETUUO IF /NOWATCH
	PUSHJ	P,SETIT		;DO THE SET UUO
TINY:	SETOM	UFDFSN		;[446] START WITH FIRST STR
USRST1:	MOVE	T2,UFDFSN	;GET STR NAME
	MOVE	T1,[3,,T2]	;[652] POINTER TO ARG BLOCK
	JOBSTR	T1,		;GET NEXT STR
	  JRST	USRST3		;SKIP ALL THE STR STUFF
	JUMPE	T2,USRST2	;JUMP IF WE ARE UP TO FENCE
	AOJE	T2,USRST2	;[427] OR END OF LIST IN ONE-STR SYSTEMS
	SOS	T2		;[427] ACCOUNT FOR AOJE
	MOVEM	T2,UFDFSN	;SAVE STR NAME
	MOVE 	T1,[2,,T2]	;[726] POINTER TO ARG BLOCK
	DSKCHR	T1,		;[726] GET AMOUNT OF LOGGED-IN QUOTA
	 JRST	USRSS1		;[746][726] FAIL-SKIP THIS STR
	TRNN	T3,-1		;[726] ANY BLOCKS LEFT?
	 JRST	USRSS1		;[746][726] NO - SKIP THIS STR
	TXNE	T4,DF.SWL	;[746][652] UNLESS SOFTWARE W/L STR
USRSS1:	 TDZA	T1,T1		;[746] INDICATE DONT CREATE SFDS
	  MOVEI	T1,1		;[746] FLAG TO CREATE SFDS
	PUSHJ	P,ENTPTH	;CREATE SFD'S AS NEEDED
	JRST	USRST1		;LOOP OVER ALL ACTICE STRS
USRST2:	HRREI	T1,.PTFSD	;FUNCTION TO SET DEFAULT PATH
	MOVEM	T1,PTHBUF+.PTFCN ;STORE IN ARGUMENT BLOCK
	SKIPGE	T1,U.SCAN	;SCAN SWITCH GIVEN
	MOVEI	T1,AD.YN	;NO--SETUP DEFAULT
	ADDI	T1,.PTSCN	;ADJUST TO START OF RANGE
	MOVEM	T1,PTHBUF+.PTSWT ;SAVE SWITCH IN ARGUMENT BLOCK
	MOVE	T1,[.PTMAX,,PTHBUF] ;DO THE PATH UUO TO SET
	MOVEI	M,[ASCIZ/%LGNCSP Can not set default path
/]				;[746] WELL, THATS THE WAY OTHERS DO IT
	PATH.	T1,		; DEFAULT PATH
	 PUSHJ	P,MSG		;[746] WARN USER
	SETZM	PTHBUF+.PTSWT	;CLEAR THE SWITCHES
	SKIPN	LIBSPC+.FXDIR	;IF THERE IS NO LIB REQUESTED
	SETZM	PTHBUF+.PTPPN	;CLEAR THE LIB PPN
	HRREI	T1,.PTFSL	;CHANGE FUNCTION TO SET DEFAULT
	MOVEM	T1,PTHBUF+.PTFCN ; LIBRARY
	SKIPGE	T1,U.SYS	;WAS /SYS GIVEN?
	MOVEI	T1,AD.YN	;NO--SET DEFAULT
	JUMPE	T1,USRS2A	;JUMP IF NOSYS
	MOVX	T1,PT.SSY	;ELSE ADD SYS BIT
	IORM	T1,PTHBUF+.PTSWT ; INTO ARGUMENT
USRS2A:	SKIPGE	T1,U.NEW	;WAS /NEW GIVEN
	MOVEI	T1,AD.YN	;NO--SUPPLY ABSENT DEFAULT
	JUMPE	T1,USRS2B	;JUMP IF NONEW
	MOVX	T1,PT.SNW	;SET THE NEW BIT IN
	IORM	T1,PTHBUF+.PTSWT ; PATH. UUO ARGUMENT BLOCK
USRS2B:	SKIPN	T1,LIBSPC+.FXDIR ;GET LIB PPN
	JRST	USRS2C		;JUMP IF NONE
	TLNN	T1,-1		;[567] IS PROJECT # ZERO?
	  HLL	T1,PP		;[567] YES - USE USER'S
	TRNN	T1,-1		;[567] ZERO PROGRAMMER NO.?
	  HRR	T1,PP		;[567] DEFAULT TO USER'S OWN
	MOVEM	T1,PTHBUF+.PTPPN ;STORE PPN
	MOVX	T1,PT.LIB	;SET THE LIB BIT
	IORM	T1,PTHBUF+.PTSWT ;SET /LIB
USRS2C:	MOVE	T1,[.PTMAX,,PTHBUF] ;DO THE PATH UUO
	PATH.	T1,		; ..
	  JFCL			; ..
USRST3:	SKIPGE	T2,U.DFUL	;GET DISK FULL SWITCH
	JRST	USRST4		;JUMP IF NOT GIVEN
	CAIN	T2,DSKFER	;ERROR?
	MOVX	T1,.DFERR	;YES--SET ERROR ARG
	CAIN	T2,DSKFPA	;PAUSE?
	MOVX	T1,.DFPSE	;YES--SET THAT
	HRLI	T1,.STDFL	;SET FUNCTION
	MOVE	T2,['SDF',,[ASCIZ .disk full.]]
	PUSHJ	P,SETIT		;GO SET IT

USRST4:	SKIPN	T1,U.DPRI	;GET DISK PRIORITY
	JRST	USRST5		;NONE SPECIFIED
	LDB	T2,[POINT 2,PRIVWD,2]	;Get value from ACCT.SYS
	JUMPE	T2,USRST5	;None allowed
	CAILE	T1,(T2)		;Is switch value within limits?
	MOVEI	T1,(T2)		;No, use ACCT.SYS value
	HRLI	T1,-2
	MOVE	T2,[.DUPRI,,T1]	;ARG POINTER
LGNSDP:	MOVEI	M,[ASCIZ /%LGNSDP can not set disk priority.
/]
	DISK.	T2,		;DO THE UUO
	  PUSHJ	P,MSG		;GIVE THE WARNING
USRST5:	SKIPL	T1,U.STA	;[633] GET STATION
	  JRST	LGNLUF		;[633] ONE WAS SPECIFIED, USE IT
	MOVEI T1,.GTLOC		;[633] GETTAB FOR NODE # OF CENTRAL SITE
	GETTAB	T1,		;[633] GET CENTRAL SITE NODE NUMBER
	  JRST	USRS5A		;[633] MONITOR MUST NOT SUPPORT NETWORKS
	HRROI	T2,.GTLOC	;[633] THIS JOB'S LOCATION
	GETTAB	T2,		;[633] GET THAT
	  JRST	USRS5A		;[633] NO NETWORK SOFTWARE
	CAMN	T1,T2		;[633] ALREADY LOCATED AT CENTRAL SITE?
	JRST	USRS5A		;[633] YES, NO POTENTIAL PROBLEMS THEN
	MOVEM	T2,NODLOC	;[633] STORE THIS JOB'S LOCATION IN NODE BLOCK
	MOVEI	T2,4		;[633] LENGTH OF THE ARGUMENT BLOCK
	MOVEM	T2,NODLEN	;[633] STORE IN NODE UUO ARGUMENT BLOCK
	MOVEI	T2,.TYLPT	;[633] DEVICE TYPE
	MOVEM	T2,NODDEV	;[633] STORE THAT IN THE ARGUMENT BLOCK
	MOVE	T2,[.NDRCI,,NODBLK] ;[633] NODE UUO ARGUMENT
	NODE.	T2,		;[633] GET NODE CONFIGURATION INFORMATION
	  JRST	USRS5A		;[633] NOT IMPLEMENTED?
	HLRZ	T2,NODDEV	;[633] NUMBER OF LPT'S AT THIS NODE
	JUMPN	T2,USRS5A	;[633] JUMP IF THERE ARE SOME

;[633] IF NO LPT'S AT THIS NODE, LOCATE JOB AT CENTRAL SITE

LGNLUF:	MOVEI	M,[ASCIZ /%LGNLUF LOCATE UUO failed.
/]
	LOCATE	T1,
	  PUSHJ	P,MSG		;GIVE THE MESSAGE

USRS5A:	MOVE	T1,[.STDEF,,T2]	;[620] SETUUO FOR DEFAULTS
	HRRZI	T2,ST.PCD	;[620] FUNCTION CODE FOR FILE PROTECTION
	SKIPGE	T3,U.DFPR	;[745][620] SWITCH SPECIFIED?
	  JRST	USRS5C		;[620] NO - SKIP THE SETUUO
	SETUUO	T1,		;[620] SET IT
	  JFCL			;[620] PROBABLY NOT IMPLEMENTED
;HERE TO SET DEFAULT FOR LOGIN TO ASK FOR ATTACH IF ANY DETACHED JOBS
USRS5C:	MOVE	T1,[.STDEF,,T2]
	MOVSI	T2,1
	HRRI	T2,ST.DAD
	SKIPL	T3,U.ATT	;DID USER TYPE A /ATTACH SWITCH?
	CAIE	T3,ATTIGN	;YES. DID HE SAY TO IGNORE ATTACH PROMPTING?
	TDZA	T3,T3		;NO.  DEFAULT TO ASK
	SETOM	T3		;YES. SET JOB'S DEFAULT TO DON'T ASK
	SETUUO	T1,
	  JFCL			;NOT IMPLEMENTED YET
;HERE TO SET DEFAULT BUFFERS
	MOVE	T1,[.STDEF,,T2]	;[750] SETUP ARGS
	MOVEI	T2,ST.NBD	;[750] SUBFUNCTION DEFAULT BUFFERS
	SKIPL	T3,U.DFBU	;[750] GET USERS SWITCH VALUE
	 SETUUO	T1,		;[750] DO IT IF HE GAVE IT
	  JFCL			;[750] NOT IMPLEMENTED OR NOT GIVEN
;HERE TO SET CURRENT VM LIMITS
USRST6:	MOVE	T1,STATS2	;GET SECOND STATES WORD
	TXNN	T1,ST%VMS	;DO WE HAVE VM?
	JRST	USRST7		;NO--TRY NEXT THING
	MOVEI	T3,0		;PRESET ANSWER TO ZERO
	SKIPGE	T1,U.CVPL	;GET CURRENT VIRT LIMIT
	JRST	USRS6A		;NONE SUPPLIED
	PUSHJ	P,FIXPGS	;CONVERT TO PAGES
	HRL	T3,T1		;USER SUPPLIED ONE -- USE IT
USRS6A:	SKIPGE	T1,U.CPPL	;GET CURRENT PHYS LIMIT
	JRST	USRS6B		;NONE SUPPLIED--LEAVE ZERO
	PUSHJ	P,FIXPGS	;MAKE SURE WE HAVE PAGES
	HRR	T3,T1		;USER SPECIFIED ONE -- USE IT
USRS6B:	JUMPE	T3,USRST7	;JUMP IF NOTHING REQUESTED
	SKIPG	U.LIMIT		;SKIP IF /LIMIT
	SKIPN	U.GUID		;SKIP UNLESS /NOGUIDELINE GIVEN
	TRO	T3,400000	;SET THE BIT
	MOVE	T1,[.STCVM,,T3]	;ARGUMENT TO SET UUO
	MOVE	T2,['SCV',,[ASCIZ /current virtual and physical limits/]]
	PUSHJ	P,SETIT		;DO THE SETUUO

USRST7:	IFN	SETTTY,<	;[344]
	SKIPN	U.SETT		;[344] DID HE SAY /NOSETTY?
	JRST	USRST8		;[344] YES -- SKIP THE WHOLE BIT
	SKIPG	T1,U.SPED	;[344] DID HE SAY /SPEED:N?
	JRST	.+3		;[344] NOPE
	MOVEM	T1,U.RSPD	;[344] YES -- SET BOTH RCV AND XMIT
	MOVEM	T1,U.XSPD	;[344] SPEED TO N
	MOVE	T1,[-TTLNTH,,TTAB] ;[472] TABLE OF PRE-NOTICE TRMOP.S
	PUSHJ	P,DOTRMP	;[472] DO THE TRMOP.S
	>			;[472] END IFN SETTTY


USRST8:	MOVEI	P1,DEVTAB	;[470] MAKE PTR TO LIST
	HLRE	T1,DEVPTR	;[470] GET -NUMBER OF WORD PAIRS LEFT
	ADDI	T1,DVICES*2	;[470] MAKE +NUMBER OF PAIRS USED
	JUMPL	T1,USRS8C	;[470] NO /ASSIGN SWITCH TYPED
	CAILE	T1,DVICES*2	;[470] TOO MANY?
	  MOVEI	T1,DVICES*2	;[631] YES - USE MAX
	LSH	T1,-1		;[470] HALVE BECAUSE WORD PAIRS
	MOVN	P2,T1		;[470] MAKE AOJL COUNTER
USRS8A:	SETZB	T1,T3		;[470] SET UP OPEN BLOCK
	MOVE	T2,(P1)		;[470] GET PHYSICAL NAME
	OPEN	UFD,T1		;[470] OPEN ON SOME RANDOM CHANNEL
	  JRST	NDEV		;[470] LOSE
	AOS	P1		;[470] BUMP POINTER
	MOVEI	T1,UFD		;[470] CHANNEL NUMBER
	SKIPN	T2,(P1)		;[470] PICK UP LOGICAL NAME
	  JRST	.+3		;[470] NONE - KEEP GOING
	DEVLNM	T1,		;[470] ASSIGN LOGICAL NAME
	  JRST	NODEV		;[470] LOST
	MOVE	T1,THSJOB	;[470] SET ASSCON BY REASSI
	MOVEI	T2,UFD		;[470] CHANNEL NUMBER
	REASSI	T1,		;[470] ZAP!
USRS8B:	CLOSE	UFD,		;[470] TIDY UP
	AOS	P1		;[470] BUMP POINTER
	AOJLE	P2,USRS8A	;[502] LOOP THRU DEVICE LIST

USRS8C:	POPJ	P,		;[470] ALL DONE


NODEV:	SOS	P1		;[470] DROP BACK TO POINT AT PHYS NAME
NDEV:	WARN	CAD,<Could not assign device >
	  CAI			;[470]
	MOVE	T1,(P1)		;[470] GET PHYSICAL NAME
	PUSHJ	P,.TSIXN##	;[470] TYPE IT
	AOS	P1		;[472] BUMP POINTER
	SKIPN	(P1)		;[472] LOGICAL NAME SPECIFIED?
	  JRST	USRS8D		;[472] NO - DON'T TALK ABOUT IT
	MOVEI	M,[ASCIZ / logical name /]	;[470]
	PUSHJ	P,MSG		;[470]
	MOVE	T1,(P1)		;[470] GET LOGICAL NAME
	PUSHJ	P,.TSIXN##	;[470] TYPE IT
USRS8D:	PUSHJ	P,NEWLIN	;[470] CRLF
	JRST	USRS8B		;[470] KEEP ON TRUCKIN

;[472] ROUTINE TO DO POST-NOTICE TRMOP.S
POSTMS:	IFN	SETTTY,<	;[472]
	OUTPUT	TTY,		;[475] SPIT OUT SOME BYTES
	SKIPN	U.SETT		;[472] DID HE SAY /NOSETTTY?
	  POPJ	P,		;[556] YES- SKIP IT
	PUSHJ	P,WAITO		;[472] WAIT UNTIL OUTPUT BUFFER EMPTY
	MOVE	T1,[-PTLNTH,,PTAB] ;[472] TABLE OF POST-NOTICE TRMOP.S
	PUSHJ	P,DOTRMP	;[472] DO THEM UP
	>			;[472] END IFN SETTTY
	POPJ	P,		;[472]

	IFN SETTTY,<		;[556]
DOTRMP:	MOVE	P1,[XWD 3,T2]	;[472] SET UP ARG POINTER
TLOOP:	SETZ	P2,		;[344] CLEAR FLAGS
	HLRZ	T4,(T1)		;[344] GET ADDR OF ARG FOR TRMOP.
	MOVE	T4,(T4)		;[344] GET ACTUAL ARGUMENT
	CAMN	T4,[-1]		;[675] IF -1,
	JRST	LEAVE		;[675]  SCAN DIDN'T TOUCH IT
	HRRZ	T2,(T1)		;[344] GET TRMOP. FUNCTION CODE & FLAGS
	TRZE	T2,TF.CMP	;[344] CLEAR FLAGS OUT OF T2 SO IT
	TRO	P2,TF.CMP	;[344] WILL BE A REAL TRMOP. CODE
	MOVE	T3,TTYUDX	;[344] GET TTY UDX
	TRNE	P2,TF.CMP	;[344] COMPLEMENT ARGUMENT?
	TRC	T4,1		;[344] YUP
	TRMOP.	P1,
	  JRST	WHA		;[344] OOPS -- CHECK IT OUT
LEAVE:	AOBJN	T1,TLOOP	;[344] GO ROUND AGAIN
FORGET:	POPJ	P,		;[475] ALL DONE
	>			;[470] END IFN SETTTY

	IFN	SETTTY,<	;[556]
;[344] HERE IF TRMOP. UUO FAILS
WHA:	CAIN	P1,TOPRC%	;[344] NOT PRIVILEGED?
	JRST	IGNORE		;[344] ACT LIKE IT DIDN'T HAPPEN
	JUMPE	P1,IGNORE	;[344] IF FUN. NOT IMPLEMENTED, IGNORE
	CAMN	P1,[XWD 3,T2]	;[344] IF UUO NOT IMPLEMENTED, FORGET
	JRST	FORGET		;[475] THE WHOLE THING
	PUSH	P,T1		;[375] WATCH OUT FOR T1
	HRRZ	T1,(T1)		;[675] PICK UP FUNCTION CODE
	CAIN	T1,.TOTRM+1000	;[675] TRYING TO SET TERMINAL TYPE
	JRST	NOTTYP		;[675] YES, NO SUCH TTY TYPE
	PUSH	P,T1		;[675] PRESERVE T1 FOR LATER USE
	MOVEI	M,[ASCIZ /%LGNTUF TRMOP. UUO failed.  Function code = /]
	PUSHJ	P,MSG		;[375] TELL HIM WHAT HAPPENED
	POP	P,T1		;[675] GET FUNCTION CODE WHICH LOST
	TRZ	T1,TF.CMP	;[472] USER DOESN'T CARE ABOUT FLAG
	PUSHJ	P,.TOCTW##	;[375] PRINT IT
	PUSHJ	P,.TCRLF##	;[375]
	POP	P,T1		;[375] AND GET T1 BACK AGAIN

IGNORE:	MOVE	P1,[XWD 3,T2]	;[344] RESTORE POINTER
	JRST	LEAVE		;[344] AND RETURN

;[675] TERMINAL TYPE INVALID ERROR
NOTTYP:	POP	P,T1		;[677]  GET T1 BACK AGAIN
	WARN	TTI,<Terminal type invalid.  Using defaults>
	  JFCL
	JRST	IGNORE		;[744] AND RETURN

;[367] ROUTINE TO SLEEP UNTIL FINISHED OUTPUTTING ON TTY
WAITO:	MOVEI	P1,^D120	;[475] WAIT FOR TTY OUTPUT FOR 2 MIN.
WAITO1:	MOVE	T1,[XWD 2,T2]	;[553] SET UP POINTER FOR TRMOP.
	MOVEI	T2,.TOSOP	;[367] SKIP IF OUTPUT BUFFER NON-EMPTY
	MOVE	T3,TTYUDX	;[367] OUR UNIVERSAL I/O INDEX
	TRMOP.	T1,		;[367] IF OUTPUT BUFFER EMPTY OR TRMOP.
	  POPJ	P,		;[367] FAILS, ASSUME OK AND RETURN
	MOVEI	T4,1		;[367] SLEEP FOR ONE SECOND
	SLEEP	T4,
	SOJG	P1,WAITO1	;[553] IF STILL PATIENT, KEEP SLEEPING
	POPJ	P,		;[475] WAITED TOO LONG - GIVE UP

	>			;[357] END IFN SETTTY

	SUBTTL	Set user parameters -- subroutines

;SUBROUTINE TO DO A SET UUO
;CALL WITH:
;	T1 = SET UUO ARGUMENT
;	LH(T2) =  3 LETTER CODE IN SIXBIT
;	RH(T2) = ADDRESS OF ASCIZ STRING
;	PUSHJ	P,SETIT
;	RETURN HERE IN ALL CASES
SETIT:	SETUUO	T1,		;SET THE PARAMETER
	  SKIPA			;LOST--PRINT MESSAGE
	POPJ	P,0		;WORKED--RETURN
	PUSH	P,T2		;SAVE T2
	PUSHJ	P,NEWLIN	;START WITH CLEAN LINE
	MOVEI	T1,[ASCIZ .%LGN.] ;PRINT PREFIX
	PUSHJ	P,.TSTRG##	; ..
	HLLZ	T1,(P)		;COPY 3 LETTER CODE
	PUSHJ	P,.TSIXN##	;PRINT THAT OUT
	MOVEI	T1,[ASCIZ . SET UUO failed attempting to set .]
	PUSHJ	P,.TSTRG##	;TYPE THE FIRST STUFF
	HRRZ	T1,(P)		;COPY REST OF STRING
	PUSHJ	P,.TSTRG##	;PRINT IT
	POP	P,T2		;CLEAN UP STACK
	PJRST	.TCRLF##	;ADD A CRLF
;SUBROUTINE TO CONVERT CORE ARGUMENT TO PAGES
;CALL WITH:
;	MOVE	T1,ANSWER-FROM-.SWCOR
;	PUSHJ	P,FIXPGS
;	RETURN HERE # OF PAGES IN T1
;USES NO AC'S
FIXPGS:	CAIG	T1,^D512	;JUST A NUMBER?
	IMULI	T1,^D1024	;YES--CONVERT TO WORDS
	LSH	T1,-9		;CONVERT TO PAGES
	POPJ	P,0		;RETURN


;[510] SUBROUTINE TO TELL USER TO CALL THE OPERATOR IF SOMETHING
;[510] IS TERRIBLY WRONG

CALOPR:	WARN	CTO,<Please call the operator>
	  JFCL
	POPJ	P,
;LOWSEG STUFF FOR LGNSET
	XLIST
	LIT
	LIST

	RELOC
IPCFLG:	BLOCK	1		;IPCF FLAGS
FMPID:	BLOCK	1		;MY PID
TOPID:	BLOCK	1		;SENDER'S PID
IPCPTR:	BLOCK	1		;POINTER TO MESSAGE
IPCMSG:	BLOCK	1		;FUNCTION FOR [SYSTEM]IPCF TO DO
IPCJOB:	BLOCK	1		;JOB TO DO IT TO
IPCQTA:	BLOCK	1		;IPCF QUOTA
NODBLK:
NODLEN:	BLOCK	1		;[633] LENGTH OF NODE UUO ARGUMENT BLOCK
NODLOC:	BLOCK	1		;[633] NODE NUMBER
	BLOCK	1		;[633] RESERVED ARGUMENT
NODDEV:	BLOCK	1		;[633] NUMBER OF DEVICES,,DEVICE TYPE
	PRGEND
	TITLE	LGNIO - Input output module for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	LGNDCL

;SUBROUTINE TO INPUT CHARS TO 1ST NON-SIXBIT CHAR - SAVE 2 WORDS OF CHARS
;VALUES	T1,T2=SIXBIT CHARS
;	CH=TERMINATING CHAR
;	FL.BRK BIT IN LH F=1 IF TERMINATING CHAR IS A BREAK CHAR

GET2WD:	PUSHJ	P,.SAVE1##	;SAVE P1
	SETZB	T1,T2
	CLOSE	TTY,0		;[456] DUMP OUT TTY BUFFER
	MOVE	P1,[POINT 6,T1]
GETNL:	PUSHJ	P,.TICHE##	;GET A CHAR. WITH THE RIGHT
				; AMOUNT OF CONVERSION.
	JUMPLE	C,DONIT		;[456] JUMP IF END OF LINE
	CAIL	C,"A"+40	;CONVER LOWER CASE
	CAILE	C,"Z"+40	; TO UPPER CASE
	SKIPA
	SUBI	C,40	
	MOVEI	CH,-40(C)	;CONVERT TO SIXBIT
	CAME	P1,[600,,T2]	;POINTER EXPIRED
	IDPB	CH,P1		;NO--STASH AWAY
	JRST	GETNL		;GET THE NEXT CHAR

DONIT:	INIT	TTY,IO.SUP	;[456] RE-INIT TTY
	SIXBIT	/TTY/		;[456] ..
	XWD	TOB,TIB		;[456] ..
	  LOGOUT		;[456] THIS IS IMPOSSIBLE
	POPJ	P,		;[456] RETURN
;SUBROUTINE TO DETERMINE IF JOB NUMBER IN T1 IS A BATCH JOB
;ARGS	T1=JOB NUMBER
;RETURN	.POPJ IF JOB IS NOT BATCH
;	.POPJ1 IF JOB IS BATCH

ISBATC:	HRLZ	T4,T1
	HRRI	T4,.GTLIM	;[602] GETTAB INDEX FOR JBTLIM
	GETTAB	T4,		;[602] GET BITS
	  SETZ	T4,
	TXNN	T4,JB.LBT	;[602] BATCH JOB?
	  POPJ	P,		;[602] NO
	JRST	.POPJ1		;[602] YES - SKIP RETURN

;[333] SUBROUTINE TO DETERMINE WHETHER THIS JOB IS A SUBJOB OF OPSER.
;[333] RETURN	POPJ IF NOT
;[333]		POPJ1 IF IT IS

ISOPSR:	SETO	T1,		;[333,340] THIS JOB
	CTLJOB	T1,		;[333] WHO CONTROLS ME?
	  POPJ	P,		;[333] I DUNNO
	MOVE	T2,T1		;[404] REMEMBER CNTRL JOB NO.
	TRMNO.	T1,		;[333] WHERE'S HIS TTY AT?
	  POPJ	P,		;[333,340] DUNNO
	GETLCH	T1		;[333,341] WHAT KIND OF TERMINAL
	TXNE	T1,GL.ITY	;[333] PTY?
	POPJ	P,		;[333,340] YES--PROBABLY BATCON
	HRLZ	T1,T2		;[337,340,404] GET JOB NO.
	HRRI	T1,.GTPRG	;[333] SET UP FOR GETTAB
	GETTAB	T1,		;[333] GET PROGRAM NAME
	  POPJ	P,		;[333] A REAL LOSER
	CAME	T1,[SIXBIT /OPSER/]
	POPJ	P,
	JRST	.POPJ1
GIVNBR:	TLNE	F,FL.BAT	;ARE WE A BATCH JOB?
	JRST	LGNEIB		;YES--NEVER SAY # TO BATCON
	PUSHJ	P,NEWLIN	;GIVE A CRLF
	MOVEI	CH,"#"		;PROMPT CHAR FOR PPN
	PUSHJ	P,ECHOON	;TYPE AND ENABLE ECHO
	MOVEI	CH,[ASCIZ /project-programmer number/]
	MOVEM	CH,HELP		;STORE REASON FOR WAITING
	POPJ	P,		;RETURN
ECHOON:	PUSHJ	P,TYO		;[456] TYPE NUMBER SIGN
	CLOSE	TTY,0		;[456] DUMP TTY BUFFER
	INIT	TTY,0		;[456] RE-INIT WITH ECHO ON
	SIXBIT 	/TTY/		;[456] ..
	XWD	TOB,TIB		;[456] ..
	  LOGOUT		;[456] THIS IS A NO-NO
	POPJ	P,		;[456] RETURN

STYO:	SKIPA	CH,T1		;CHARACTER OUTPUT FOR SCAN & WILD
SPACE:	MOVEI	CH,40
TYO:	PUSHJ	P,TTYOUT	;[456] OUTPUT THE CHAR
	CAIN	CH,.CHCRT	;CARRAGE RETURN?
	SETZM	HPOS		;YES--BACK TO START OF LINE
	CAIL	CH," "		;CONTROL CHARACTER?
	AOS	HPOS		;NO--UPDATE POSITION
	POPJ	P,0		;RETURN

TYI:	PUSHJ	P,.TIAUC##	;GET CHAR BY SCAN'S SUBROUTINE
	MOVE	CH,C		;[331] COPY CHAR
	POPJ	P,

	FATAL	EIB,<Error in BATCON - LOGIN aborted>

TTYOUT:	SOSG	TOB+2		;[456] CHOP BYTE COUNT
	  OUTPUT	TTY,	;[456] NO ROOM - MAKE SOME
	IDPB	CH,TOB+1	;[456] PUT A BYTE IN
	POPJ	P,		;[456] RETURN
;SUBROUTINE TO GET ONE CHAR AND BOMB USER FOR BEING
; SLOW.
;
;CALLED ONLY FROM SCAN -- MAY CHANGE NO AC'S

TTYGET:	PUSHJ	P,.SAVE2##	;SAVE P1 AND P2
	SKIPN	FL2741		;IS THIS A 2741?
	TRNE	F,R.PTYJ	;PTY JOB?
	JRST	TTGET2		;YES -- GO INTO TI WAIT
	MOVEI	P2,TTYSLP	;NUMBER OF MINS. TO SLEEP
TTGET1:	SKPINL			;ANYTHING THERE??
	  SKIPA			;NO--LOOP
	JRST	TTGET2		;YES--GO GET IT
	MOVE	P1,[HB.RTL!HB.RWJ!^D60000]
	HIBER	P1,		;HIBER FOR 1 MIN.
	  JRST	TTGET2		;TINY MONITOR
	SKPINL
	  SKIPA
	JRST	TTGET2
	SOJG	P2,TTGET1	;LOOP FOR A WHILE
	PUSHJ	P,HELPR		;TELL HIM WHY WE LOST
	JRST	FLUSH		;GET RID OF HIM

TTGET2:	INCHWL	C		;GET A CHAR. INTO C
	CAIE	C,.CHCNC	;CONTROL-C?
	CAIN	C,.CHCNZ	;[343] OR CONTROL-Z?
	PJRST	RICC##		;YES--GO EXIT
	CAIN	C,.CHCRT	;IS IT A CARRAGE RETURN?
	SETZM	HPOS		;YES--UPDATE HORIZ. POSITION
	CAIL	C," "		;PRINTING CHARACTER?
	AOS	HPOS		;YES--UPDATE HORIZ POSITION
	POPJ	P,		;RETURN

;HERE IF USER DOES NOT TYPE ANYTHING WITHIN 2 MIN.
LGNWFS:
HELPR:	OUTSTR	[ASCIZ /
?LGNWFS  Waiting for /]
	OUTSTR	@HELP		;EXPLAIN THE LOSSAGE
LGNPSO:	OUTSTR	[ASCIZ /
?LGNPSO  Please start over
/]
	POPJ	P,

;SUBROUTINE TO TYPE A CRLF IF ONE IS NEEDED
NEWLIN:	SKIPN	HPOS		;IS A CRLF NEEDED?
	POPJ	P,0		;NO--JUST RETURN
	PJRST	.TCRLF##	;YES--GO TYPE ONE
	SUBTTL	LOGIN messages

	MSGOK==1		;FLAG TO TYPE MEESSAGE EVEN IF USER
				; HAS SEEN IT.
	FNAME==2		;FLAG TO REQUEST FILE NAME PRINTING
	STONLY==4		;[357] FLAG TO PRINT STR NAME ONLY

;HERE TO PRINT RANDOM FILES USER GETS ON LOGIN

DAYMES:	PUSHJ	P,.SAVE1##	;SAVE P1
	TLNN	F,FL.WLD	;WILD PPN
	JRST	ACCT2		;NO--HE KNOWS WHO HE IS
	INFO	LIA,<You are logged in as >
	 JRST	ACCT2
	HLRZ	N,PPN		;GET PROJECT
	PUSHJ	P,OCTPRT	;PRINT
	MOVEI	CH,","		;PRINT A ,
	PUSHJ	P,TYO		;DONE
	HRRZ	N,PPN		;GET PROGRAMMER
	PUSHJ	P,OCTPRT	;PRINT
	MOVEI	M,[ASCIZ .]
.]				;ADD IN A CLOSE BRACKET
	PUSHJ	P,MSG		;AND A CRLF
ACCT2:	MSTIME	T1,		;GET TIME OF DAY
	IDIVI	T1,^D60000	;TO MINUTES
	IDIVI	T1,^D60		;NOW BREAK IN MINS AND HRS
	PUSH	P,T2		;SAVE MINUTES
	MOVE	N,T1		;HOURS
	PUSHJ	P,DECPR2
	PUSHJ	P,.TCOLN##	;TYPE A COLON
	POP	P,N		;MINUTES
	PUSHJ	P,DECPR2
	MOVEI	CH,11		;TAB
	PUSHJ	P,TYO
	MOVE	T1,TDATE	;[477] 
	PUSHJ	P,DATEPR	;Print the date
	MOVEI	CH,11
	PUSHJ	P,TYO
	MOVE	T1,SAVEDA	;DAY OF WEEK
	MOVEI	M,WEEKDA(T1)
	PUSHJ	P,MSG		;TYPE DAY OF WEEK
	PUSHJ	P,.TCRLF##
	MOVEI	T1,2		;[454] GET DEFAULT FOR /NOTICE
	MOVE	P1,U.NOTC	;[453] GET SWITCH TYPED
	AOSN	P1		;[453] WAS A SWITCH TYPED?
	  MOVEM	T1,U.NOTC	;[453] NO - USE DEFAULT
	MOVEI	T1,NOTSPC	;[362] /NOTE FILESPEC
	MOVEI	P1,FNAME	;[362] PRINT FILE NAME
	PUSHJ	P,TYPE		;[362] TYPE IT
	PUSHJ	P,ISOPSR	;[333] IS THIS AN OPSER SUBJOB?

DIEMSG:	SKIPA	T1,[DAYSPC]	;[333,337] NO--PRINT NOTICE.TXT
	POPJ	P,0		;[662] [333] YES--DON'T PRINT IT
	MOVEI	P1,0		;FLAGS
	PJRST	TYPE		;GO PRINT IT AND RETURN

;[662]	CREATE SEPERATE /STR PRINTER
STRMES::SKIPG	U.STR		;/STR GIVEN
	POPJ	P,0		;NO--RETURN
	MOVEI	T1,STRSPC	;STR.TXT SPEC
	MOVEI	P1,MSGOK!FNAME!STONLY	;[357] OK TO TYPE MESSAGE
	PJRST	TYPE		;PRINT IT

;FILE SPEC FOR SYS:NOTICE.TXT/PHYSICAL/NOSTR
DAYSPC:	SIXBIT	/SYS/
	SIXBIT	/NOTICE/
	EXP	-1
	XWD	'TXT',-1
	EXP	FX.PHY!FX.NOM
	EXP	FX.STR!FX.PHY!FX.NOM
	BLOCK	.FXLEN-<.-DAYSPC>

;FILE SPEC FOR SYS:STR.TXT/PHYSICAL/STRS
STRSPC:	SIXBIT	/ALL/
	SIXBIT	/STR/
	EXP	-1
	XWD	'TXT',-1
	EXP	FX.PHY!FX.STR
	EXP	FX.PHY!FX.STR
	XWD	1,4
	XWD	-1,-1
	BLOCK	.FXLEN-<.-STRSPC>

;Subroutine to print date from T1
DATEPR:	IDIVI	T1,^D31		;THE USUAL DATE PRINTER
	MOVEI	N,1(T2)		;DAY OF MONTH
	PUSHJ	P,DECPR2
	IDIVI	T1,^D12		;MONTH AND YEAR
	MOVE	T2,MONTAB(T2)
	MOVEM	T2,DATEMP
	SETZM	DATEMP+1	;FOR ASCIZ, DDTOUT
	MOVEI	M,DATEMP
	PUSHJ	P,MSG
	MOVEI	N,^D64(T1)	;YEAR
	PJRST	DECPR2		;Print year and return
;SUBROUTINE TO TYPE A FILE
;CALL WITH:
;	MOVEI	T1,ADDRESS-OF-SCAN-STYLE-FILESPEC
;	MOVEI	P1,FLAGS
;	PUSHJ	P,TYPE
;	RETURN HERE
TYPE:	SKIPN	.FXNAM(T1)	;[512] ANY NAME OR MASK SPECIFIED?
	  POPJ	P,		;[512] NO - SKIP IT
	HRLZ	T1,T1		;FLIP AROUND
	HRRI	T1,TYPSPC	;ADDRESS OF OUT SPEC
	BLT	T1,TYPSPC+.FXLEN-1 ;[436] COPY THE FILESPEC
	SETZM	WLDPNT		;CLEAR MEMORY FOR FIRST CALL
	MOVX	T1,FX.NOM!FX.PRT ;/OKNONE AND /OKPROT
	IORM	T1,TYPSPC+.FXMOD;FORCE SWITCH TO BE
	IORM	T1,TYPSPC+.FXMOM; SET ON ALL CALLS TO WILD
TYPE1:	MOVE	T1,[4,,[[TYPSPC],,0
			UFDBUF,,SECBUF
			.FXLEN,,.RBPRV+1
			UFD,,WLDPNT]]
	MOVX	T2,.IOASC	;SET UP ASCII MODE
	MOVEM	T2,UFDBUF	; ..
	PUSHJ	P,.LKWLD##	;LOOK FOR FILE
	  POPJ	P,0		;ALL DONE
	MOVEI	T1,B.DC##	;SET UP ADDRESS OF BUFFER HEADER
	MOVEM	T1,UFDBUF+2	; ..
	OPEN	UFD,UFDBUF	;OPEN THE FILE
	  PJRST	E.DFO##		;CAN'T
	LOOKUP	UFD,SECBUF	;LOOKUP FILE
	JRST	[PUSHJ P,E.DFL## ;REPORT ERROR
		 JRST  TYPE1]	;LOOK FOR NEXT FILE
IFN SUPNOT,<
	TRNE	P1,MSGOK	;WANT MESSAGE ALWAYS?
	JRST	TYPE3		;YES--GO TYPE IT
	SKIPE	UFDNDL		;SKIP IF UFD CAN BE DELETED
	JRST	TYPE2		; SAW THE MESSAGE
	LDB	T1,[POINTR(SECBUF+.RBPRV,RB.CRD)]
	LDB	T2,[POINTR(SECBUF+.RBEXT,RB.CRX)] ;GET TOP 3 BITS OF DATE
	LSH	T2,^D12		;MOVE OVER TO CORRECT PLACE
	IORI	T1,(T2)		;COMBINE
	CAMLE	T1,UFDDAT	;IS FILE NEWER THAN UFD?
	JRST	TYPE3		;YES--PRINT ANYWAY
	CAME	T1,UFDDAT	;SAME DAY?
	JRST	TYPE2		;NO--DISTINCTLY OLDER
	LDB	T2,[POINTR(SECBUF+.RBPRV,RB.CRT)]
	CAML	T2,UFDTIM	;IS MESSAGE NEWER THAN UFD
	JRST	TYPE3		;YES--GO PRINT
TYPE2:	MOVE	T1,U.NOTC	;[450] GET /NOTICE VALUE
	CAIL	T1,2		;[450,453] SOMETIMES OR NEVER?
	JRST	TYPE1		;[453] YES -LOOK FOR NEXT FILE
>
TYPE3:	OUTPUT	TTY,		;[465] KEEP USER PATIENT
	MOVE	T1,U.NOTC	;[450] GET /NOTICE VALUE
	CAIN	T1,3		;[450] NEVER PRINT?
	  JRST	TYPE1		;[450] YES - SKIP IT
	TXNE	P1,FNAME	;WANT TO SEE FILE NAME?
	PUSHJ	P,TYPFIL	;TYPE THE FILE SPEC
TYPE4:	PUSHJ	P,.NXDTW##	;GET A BYTE
	  JRST	TYPE1		;END OF FILE
	PUSHJ	P,.TCHAR##	;TYPE IT
	JRST	TYPE4
;SUBROUTINE TO TYPE A FILESPEC
;CALL WITH:
;	UFDBUF = OPEN BLOCK
;	SECBUF = LOOKUP BLOCK
;	PUSHJ	P,TYPFIL
;	RETURN HERE
TYPFIL:	PUSHJ	P,NEWLIN	;[377] DON'T DOUBLE-SPACE
	MOVE	T1,UFDBUF+1	;GET DEVICE NAME
	PUSHJ	P,.TSIXN##	;TYPE IT
	PUSHJ	P,.TCOLN##	;TYPE IT
	TXNE	P1,STONLY	;[357] ONLY WANT STR NAME?
	PJRST	.TSPAC##	;[357] YES -- FINISH UP
	MOVE	T1,SECBUF+.RBNAM ;GET FILE NAME
	PUSHJ	P,.TSIXN##	;TYPE IT
	MOVEI	T1,"."		;TYPE A DOT
	PUSHJ	P,.TCHAR##	;TYPE THE DOT
	HLLZ	T1,SECBUF+.RBEXT;TYPE THE EXTENSION
	PUSHJ	P,.TSIXN##	;TYPE EXTENSION
	MOVEI	T1,SECBUF+.RBPPN;POINT TO PPN
	PUSHJ	P,.TDIRB##	;PRINT IT
	PJRST	NEWLIN		;START A NEW LINE AND RETURN

	SUBTTL	I/O subroutines

OCTPRT:	PUSH	P,T1
	MOVE	T1,N
	PUSHJ	P,.TOCTW##
	POP	P,T1
	POPJ	P,

DECPR2:	MOVEI	CH,"0"		;IF NEED LEADING DIGIT
	CAIG	N,11
	PUSHJ	P,TYO		;TYPE A ZERO
	PUSH	P,T1
	MOVE	T1,N
	PUSHJ	P,.TDECW##
	POP	P,T1
	POPJ	P,

RDUFD:	SKIPGE	WD,RDHED
	JRST	RDUFD1		;ALREADY READING
	MOVE	WD,[IOWD 200,UFDBUF]
	MOVEM	WD,RDHED
	SETZM	RDHED+1
	TLNE	F,FL.ACC	;SKIP IF READING AUXACC.SYS
	AOS	ACCKNT		;KEEP COUNT OF BLOCKS READ ON ACCT.SYS
	IN	UFD,RDHED
	  JRST	RDUFD1		;[562] ALL SET
	STATO	UFD,IO.EOF	;[562] END OF FILE?
	  JRST	NOSYS		;[562] NO - ANYTHING ELSE IS FATAL
	POPJ	P,0		;YES. NONSKIP RETURN

RDUFD1:	AOBJN	WD,.+1		;NEXT WORD
	MOVEM	WD,RDHED
	MOVE	WD,0(WD)	;GET DATUM

IFE	FASTLG,<
	TLON	F,FL.RAS	;FIRST WORD?
	JRST	RDUFD2		;YES. GO MAKE SPECIAL CHECKS
>
IFN	FASTLG,<
	TLO	F,FL.RAS	;JUST SET IT, NO SKIP
>
	AOS	0(P)		;SKIP RETURN
	POPJ	P,0

	IFN	PSWCHG,<		;[557]

;ROUTINE TO UPDATE ACCT.SYS IN PLACE WITH NEW PASSWORD
;WE SIMPLY ENTER ACCT.SYS IN UPDATE MODE AND REWRITE
;THE RELEVANT BLOCK WITH THE NEW PASSWORD
;CAUTION - WTHED IS USED FOR TWO DIFFERENT THINGS:
;THE I/O CMD LIST FOR WRITING ACCT.SYS IF IT CAN BE ENTERED,
;OR THE NUMBER OF TIMES LEFT TO RETRY IF IT CAN'T

WTUFD:	MOVEI	T1,^D60		;[557] # OF TIMES TO RETRY
	MOVEM	T1,WTHED	;[557] SAVE IT AWAY
	PUSHJ	P,CLRRIB	;[557] CLEAR EXTENDED LOOKUP BLOCK
	MOVE	T1,[SIXBIT /ACCT/]
	MOVEM	T1,SECBUF+.RBNAM
	MOVSI	T1,(SIXBIT /SYS/)
	MOVEM	T1,SECBUF+.RBEXT
	MOVE	T1,SYSPPN
	MOVEM	T1,SECBUF+.RBPPN
	MOVEI	T1,.RBTIM	;[557] GET ARG COUNT
	MOVEM	T1,SECBUF+.RBCNT
	LOOKUP	UFD,SECBUF	;[557] LOOK IT UP
	  JRST	NOSYS		;[557] THIS IS FATAL
	MOVE	T1,W.ACCT	;[557] GET LAST CREATION DATE-TIME
	CAME	T1,SECBUF+.RBTIM;[557] CHANGED?
	   JRST	NOPE		;[557] YES - DON'T TRY ANYTHING THEN
	HLLZ	T1,SECBUF+.RBEXT
	MOVEM	T1,SECBUF+.RBEXT
	MOVSI	T1,777000	;[557] MASK ALL BUT PROTECTION BITS
	ANDM	T1,SECBUF+.RBPRV;[557] ..

AGAIN:	ENTER	UFD,SECBUF	;[557] TRY TO ENTER FOR UPDATE
	  JRST	ANALYZ		;[557] FIGURE OUT WHAT HAPPENED
	MOVE	T1,SAVBLK	;[624] GET DESIRED BLOCK NUMBER
	USETI	UFD,(T1)	;[557] SET UP TO READ IT
	MOVE	T1,[IOWD 200,UFDBUF]
	MOVEM	T1,WTHED	;[557] SET UP I/O CMD LIST
	SETZM	WTHED+1		;[557] ..
	IN	UFD,WTHED	;[557] READ THE BLOCK
	 SKIPA			;[557] OK
	  JRST	NOSYS		;[557] THIS SHOULD NEVER HAPPEN

;****STILL IN IFN PSWCHG

	MOVE	T2,SAVPOS	;[557] GET POINTER TO WORD WITHIN BLOCK
	MOVE	T1,(T2)		;[624] GET PSWD FROM FILE
	MOVE	P1,CODE		;[651] GET PSWD WE LOGGED IN WITH
	IFN	NCRYPT,<	;[651] IF ENCRYPTED PASSWORDS
	PUSHJ	P,ENCODE##	;[651] ENCRYPT IT
	>;[651] END IFN NCRYPT
	CAME	T1,P1		;[557] SAME AS ONE WE LOGGED IN WITH?
	  JRST	NOPE		;[557] NO - DON'T TRY ANYTHING
	MOVE	T1,ENTRY+CODWRD	;[557] GET NEW PSWD
	MOVEM	T1,(T2)		;[624] REPLACE OLD ONE
	MOVE	T1,SAVBLK	;[624] GET BLOCK TO WRITE
	USETO	UFD,(T1)	;[557] SELECT IT
	OUT	UFD,WTHED	;[557] WRITE IT
	  JRST	WTUFD1		;[624] ALL SET
NOPE:	WARN	CCP,<Couldn't change password>
	  JFCL
WTUFD1:	CLOSE	UFD,0		;[624] FINISH UP AND
	POPJ	P,		;[557] RETURN


ANALYZ:	HRRZ	T1,SECBUF+.RBEXT;[557] GET ERROR CODE
	CAIE	T1,ERFBM%	;[557] FILE BEING MODIFIED?
	  JRST	NOPE		;[557] NO - GIVE UP
	SOSGE	WTHED		;[557] COUNT DOWN TIMER
	  JRST	NOPE		;[557] LOST PATIENCE
	MOVEI	T1,1		;[557] SLEEP FOR
	SLEEP	T1,		;[557] ONE SECOND
	JRST	AGAIN		;[557] KEEP GOING
	>			;[557] END IFN PSWCHG

IFE	FASTLG,<
RDUFD2:	HRRZM	WD,ENTSIZ	;SAVE SIZE OF ENTRIES
	HLRZS	WD
	CAIL	WD,ACC506	;[356] 
	CAILE	WD,ACC602	;[356] 
	JRST	BADFOR
	CAIN	WD,ACC601
	SETOM	NEWACT		;FLAG WE HAVE THE NEW FORMAT
	POP	P,0(P)		;REMOVE SUBR ENTRY
	JRST	RDACCT		;AND TRY AGAIN TO READ A BLOCK
>;*** END OF CONDITIONAL ON FASTLG
BADFRA:	MOVEI	CH,ERR.NF	;NON FATAL ERROR
	JRST	BADFR1

BADFOR:	MOVEI	CH,ERR.SS	;STOP SCHEDULING
BADFR1:	MOVEI	M,BDFRMS
	JRST	NOSYS1

MONTAB:	ASCII	/-Jan-/
	ASCII	/-Feb-/
	ASCII	/-Mar-/
	ASCII	/-Apr-/
	ASCII	/-May-/
	ASCII	/-Jun-/
	ASCII	/-Jul-/
	ASCII	/-Aug-/
	ASCII	/-Sep-/
	ASCII	/-Oct-/
	ASCII	/-Nov-/
	ASCII	/-Dec-/

WEEKDA:	ASCIZ	.Wed.
	ASCIZ	.Thur.
	ASCIZ	.Fri.
	ASCIZ	.Sat.
	ASCIZ	.Sun.
	ASCIZ	.Mon.
	ASCIZ	.Tue.

	PRGEND
	TITLE	LGNERR - Error messages and typeout for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM

	LGNDCL

	SUBTTL	Error conditions

LGNMLB:
NOMFDP:	MOVEI	M,[ASCIZ /LGNMLB May not login as MFD PPN
/]
	JRST	ERR1

LGNP1P:
NOREMT:	MOVEI	M,[ASCIZ /LGNP1P Project 1 may not be PTY
/]
	JRST	ERR1

LGNIPS:
PTHERR:	MOVEI	M,[ASCIZ /LGNIPS Invalid path specification
/]
	JRST	ERR1

LGNBPN:
PPERR:	MOVEI	M,[ASCIZ /LGNBPN Invalid format for project-programmer number
/]
	TRO	F,R.FMT
	JRST	ERR1

PPERR1:	PUSHJ	P,CODGET	;GET PSW TO MAKE IT LOOK GOOD
	MOVEM	T1,CODE		;SAVE THE PASSWORD HE TRIED
BADNAM:			;ALL SAME ERROR, SO DONT HELP HACKERS
LGNIET:
TRYAGN:	MOVEI	M,[ASCIZ /LGNIET INVALID ENTRY - Try again
/]
	MOVE	T1,TTBITS	;[625] GET BITS FOR CNTRLNG TTY
	TXNN	T1,GL.DSL!GL.ITY;[625] DATASET OR PTY?
	  JRST	ERR1		;[625] NO - DON'T SLEEP, THEN
	MOVEI	T1,3		;[625] YES - SLEEP TO MAKE IT HARD
	SLEEP	T1,		;[625] TO BREAK SECURITY
	JRST	ERR1		;[470]

A2MANY:	TROE	F,R.2MNY	;[470] TYPED MESSAGE ALREADY?
	  POPJ	P,		;[470] YES - DON'T BE A BLABBERMOUTH
	WARN	A2M,<Attempt to assign too many devices with /ASSIGN>
	  JFCL			;[470] 
	POPJ	P,		;[470] RETURN


LGNATL:	PUSHJ	P,.CLRBF##	;CLEAR TYPE AHEAD
	SETZM	TIB+2		;AND REST OF THIS BUFFER
	SOSG	LOGTRY
	JRST	FLUSH
	MOVEI	M,[ASCIZ /LGNATL Account /]
	MOVEI	CH,ERR.FT	;FATAL ERROR
	PUSHJ	P,ERRLIN	;TYPE THE FIRST PART
	MOVEI	M,U.ACTS	;GET ADDRESS OF ACCOUNT
	PUSHJ	P,MSG		; AND PRINT IT OUT
	MOVEI	M,[ASCIZ / too long
/]
	PUSHJ	P,MSG
	MOVE	T1,[U.ACTS,,U.ACTS+1] ;ZERO OUT THE ACCOUNT
	SETZM	U.ACTS
	BLT	T1,U.ACTS+7
	JRST	LOGIN3		;GO RETRY WITHOUT SLEEP IN THIS CASE


LGNICA:	MOVEI	M,[ASCIZ /LGNICA Illegal character in account
/]
	MOVE	T1,[U.ACTS,,U.ACTS+1] ;ZERO OUT THE ACCOUNT
	SETZM	U.ACTS
	BLT	T1,U.ACTS+7
	JRST	ERR1

LGNNAS:	MOVEI	M,[ASCIZ /LGNNAS No account specified
/]
	JRST	ERR1


;HERE IF THERE IS AN ERROR WHERE THE ERROR MESSAGE HAS ALREADY BEEN TYPED,
;SO JUST CLEAN UP.

LGNVAL:	PUSHJ	P,.CLRBF##	;CLEAR TYPE AHEAD
	SETZM	TIB+2		; AND REST OF THIS BUFFER
	SOSG	LOGTRY		;DO WE TRY AGAIN?
	JRST	FLUSH		;NO.
	MOVE	T1,[U.ACTS,,U.ACTS+1]	;ZERO THE ACCOUNT
	SETZM	U.ACTS
	BLT	T1,U.ACTS+7
	JRST	LOGIN3		;GO RETRY WITHOUT SLEEPING
;USGERR - ROUTINE TO REPORT ERRORS RECEIVED FROM THE ACCOUNT DAEMON 
USGERR:	HRRZ	T1,IPR.BL+.IPCFP	;GET THE ADDRESS OF THE PAGE OF DATA
	LSH	T1,11		;CONVERT TO AN ADDRESS
	MOVEI	M,UC$ERR(T1)	;GET THE ASCIZ ERROR MESSAGE
	JRST	ERR1






ERR1:	PUSHJ	P,.CLRBF##	;CLEAR TYPE-AHEAD
	SETZM	TIB+2		;AND REST OF THIS BUFFER
	TLNE	F,FL.ATT	;NO SKIP IF ATTACH
IFE FAILOG,<JRST NOATT		;NO RETRIES FOR ATTACH>
IFN FAILOG,<JRST ERR2		;GO LOG THE FAILURE>
	MOVEI	CH,ERR.FT	;FATAL ERROR
	PUSHJ	P,ERRLIN
	TRZE	F,R.FMT		;NO SLEEP OR ERROR LOG IF SYNTAX ERROR
	JRST	ERR3		;Go test LOGTRY
IFN	FAILOG,<
ERR2:	PUSHJ	P,ACCTA		;SETUP FACT FILE ENTRY FOR FAILURE
	MOVE	T1,FCTFMD	;MODIFY HEADER FOR FAILURE TYPE AND EXTENDED LEN
	ADDM	T1,FCTDAT
	MOVE	T1,CODE		;THIS IS THE PASSWORD HE TRIED
	MOVEM	T1,FCTDAT+3	;HANG ONTO IT
	MOVE	T1,CNTLJP	;THIS IS THE PPN OF THE CONTROL JOB
	MOVEM	T1,FCTDAT+4
	MOVE	P2,FCTFWD	;GET FAILURE HEADER WORD
	PUSHJ	P,.FACTR##	;[623] STICK THE WHOLE THING INTO FACT.SYS
	TLNE	F,FL.ATT	;ATTACH?
	JRST	NOATT		;YES, NO RETRIES
>;END OF CONDITIONAL ON FAILOG
ERR3:	SOSG	LOGTRY		;Another chance??
	JRST	FLUSH		;No, bye-bye
	JRST	LOGIN3		;[517]

NOATT:	MOVEI	M,NOATMS	;CANT ATTACH MESSAGE
	PUSHJ	P,MSG		;COMPLAIN ABOUT ATTACH FAILING
	JRST	FLUSH		;AND GIVE UP
NOSYS:	TLNE	F,L.OPR!L.SOPR	;SKIP IF NOT OPR OR SON OF OPR
	JRST	PSWOK		;CTY OR OPR CAN LOGIN EVEN IF NO ACCT.SYS
	STOP	CAF,<Can't access system files.  Please call the operator.>
NOSYS1:	PUSHJ	P,ERRLIN

FLUSH:	CLRBFI			;CLEAR ANY TYPE-AHEAD
	MOVEI	M,KLGMSG	;TYPE KJOB TO INDICATE FLUSHED
	MOVN	T1,THSJOB	;[510] GET NEGATIVE JOB NUMBER
	JOBSTS	T1,		;[510] GET MY STATUS
	  SKIPA			;[510] EH?
	TXNN	T1,JB.ULI	;[510] LOGGED IN?
	PUSHJ	P,MSG		;[510] NO - TELL HIM WE LOGGED OUT
	MOVEI	CH,4		;TURN OFF TERMINALS THAT KNOW HOW
	PUSHJ	P,TYO
	JRST	FLUSHX		;GO CLEAR CORE AND KJOB
	SUBTTL	Error message printer

;CALLED ONLY BY MACROS
ERRMSG:	PUSHJ	P,.PSH4T##	;SAVE T1 THRU T4
	PUSHJ	P,NEWLIN	;GET START OF A NEW LINE
	TXNE	EF,EF.REQ	;[477] REQUE BATCH JOB?
	MOVE	T1,["?",,[ASCIZ .?(5).]]  ;[477] YES
	TXNE	EF,EF.SYS	;SYSTEM FAILURE
	MOVE	T1,["?",,[ASCIZ .?(4).]] ;YES--DATA FOR THAT
	TXNE	EF,EF.ERR	;FATAL ERROR
	MOVE	T1,["?",,[ASCIZ .?(3).]]
	TXNE	EF,EF.WRN	;WARNING?
	MOVE	T1,["%",,[ASCIZ .%(1).]]
	TXNE	EF,EF.INF	;INFORMATIONAL
	MOVE	T1,["[",,[ASCIZ .[.]]
	TLNN	F,FL.BAT	;[600] BATCH JOB?
	  JRST	[HLRZ  T1,T1	;NO--PUT CHAR IN RH
		 PUSHJ P,.TCHAR## ;TYPE IT
		 JRST  ERMSG1]	;CONTINUE
	HRRZ	T1,T1		;CLEAR LH
	PUSHJ	P,.TSTRG##	;TYPE THE MESSAGE
ERMSG1:	TLO	E1,'LGN'	;SET UP PREFIX
;***TEST FOR /VERB:PREFIX HERE
	MOVE	T1,E1		;COPY PREFIX
	PUSHJ	P,.TSIXN##	;TYPE IN SIXBIT
	PUSHJ	P,.TSPAC##	;PRINT A SPACE
;HERE TO PRINT ERROR LINE
ERMSG2:	;***TEST FOR /VERB:FIRST
	MOVEI	T1,(EF)		;COPY STRING POINTER
	PUSHJ	P,.TSTRG##	;PRINT THE STRING
	TXNE	EF,EF.ERR!EF.SYS!EF.REQ ;[503] IS THIS A FATAL ERROR?
	JRST	TNOTE		;[347] YES--GO FLUSH USER
	HLRZ	T1,@-4(P)	;GET RETURN INSTRUCTION
	CAIN	T1,(JFCL)	;IS IT A JFCL?
	PUSHJ	P,[TXNE  EF,EF.INF	;NEED A CLOSE BRACKET
		   PUSHJ P,.TRBRK## ;YES--PUT IT ON
		   PJRST .TCRLF##];ADD A CRLF
	PUSHJ	P,.POP4T##	;RESTORE TEMPS
	PJRST	.POPJ1	;SKIP RETURN (INDICATING PRINT REST)

TNOTE:	PUSHJ	P,.TCRLF##	;[347] DO A CRLF
	PUSHJ	P,.TCRLF##	;[347] AND ANOTHER
	MOVE	T1,[SIXBIT /LOGIN/]	;[615]
	SETNAM	T1,		;[357] CLEAR JACCT
	PUSHJ	P,DIEMSG	;[621] TYPE MESSAGES OF THE DAY
	PUSHJ	P,STRMES##	;[662] AND DO /STR IF DESIRED
	PJRST	FLUSH		;[347] AND DIE

;SUBROUTINE TO START AN ERROR LINE WITH ?(#) (# IF PTY)
;ARGS	M=ADDR OF ASCII TEXT
;	CH=ERROR CODE IF BATCH

ERRLIN:	HRLM	CH,(P)		;REMEMBER ERROR CODE
	MOVEI	CH,"?"		;START WITH QUESTION MARK
	PUSHJ	P,TYO		;TYPE IT
	MOVE	CH,TTBITS	;GET TTY CHARACTERISTICS
	TXNN	CH,GL.ITY	;SKIP IF PTY JOB
	PJRST	MSG		;NO, TYPE TEXT AND RETURN
	MOVEI	CH,"("		;PAREN FOR CONSISTENCY CHECKING
	PUSHJ	P,TYO		;TYPE IT
	HLRZ	CH,(P)		;RESTORE ERROR CODE.
	MOVEI	CH,"0"(CH)	;CONVERT TO ASCII
	PUSHJ	P,TYO
	MOVEI	CH,")"		;FINISH UP
	PUSHJ	P,TYO		;TYPE IT
	PJRST	MSG		;TYPE TEXT AND RETURN
	SUBTTL	Random messages

KLGMSG:	ASCIZ	/
.KJOB
./
CRLFPD:	ASCIZ	/
./
LGNCAJ:
NOATMS:	ASCIZ	/
?LGNCAJ  Can't ATTACH to job/
LGNMNL:
NOTSMS:	ASCIZ	/LGNMNL May not LOGIN /
LGNMNA:
NOTSAT:	ASCIZ	/LGNMNA May not ATTACH /
NOTSM1:	ASCIZ	/local
/
NOTSM2:	ASCIZ	/remote
/
NOTSM3:	ASCIZ	/data set
/
NOTSM4:	ASCIZ	/remote CTY or OPR
/
NOTSM5:	ASCIZ	/as a BATCH job subjob
/
NOTSM6:	ASCIZ	/as a BATCH job
/
LGNWFV:
BDFRMS:	ASCIZ	/LGNWFV Wrong Format Version Number in system files
?LGNCTO Please call the operator.
/
	SUBTTL	Data and storage

;STORAGE

WATBTS:	POINT	5,ENTRY+PROWRD,4
SPLBTS:	POINT	5,ENTRY+PROWRD,9
IFN	FASTLG,<
ENTSIZ:	16			;SIZE OF ACCT.SYS ENTRIES
DACCFL:	0			;DIRECTORY IS NOT BUILT
DLOCK:	-1			;AND NO-ONE IS BUILDING IT
DAUXFL:	0			;AUX TABLE MUST ALSO BE BUILT
DACCL:	0			;EXPECTED LENGTH OF ACCT.SYS = LENGTH OF TABLE
PDACC:	0			;ADDR OF DIRECTORY OF ACCT.SYS
NEWACT:	0			;-1 IF NEW ACCT.SYS 0 IF V2
EQACT:	0			;[504] -1 IF SETTING 6.02 STUFF

;THE FOLLOWING WORDS CONTAIN THE CREATION DATE-TIME OF
;THE ACCOUNTING FILES THE LAST TIME THEY WERE READ SO WE CAN
;TELL IF THEY HAVE CHANGED.
W.ACCT:	0			;[540] ACCT.SYS
W.AUX:	0			;[540] AUXACC.SYS
W.SCED:	0			;[540] SCDMAP.SYS
>;*** END OF CONDITIONAL ON FASTLG
SCDTBL::0			;[425] ADDR OF SCHED TABLE
BLDSCD::0			;[425] -1 MEANS SCHED TABLE BEING BUILT
SCDBLT::-1			;[425] -1 MEANS TABLE NOT YET BUILT
	PRGEND
	TITLE	LGNEND - Exit sequence for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	LGNDCL



;SUBROUTINE TO ALLOW CONTROL-C'S TO WORK AGAIN
;CALL WITH:
;	PUSHJ	P,CTLCOK
;	RETURN HERE IF NO CONTROL-C TYPED
;
CTLCOK::SETZM	CCWAIT		;CLEAR THE CONTROL-C DELAY FLAG
	AOSE	CCTYPED		;WAS A CONTROL-C TYPED?
	POPJ	P,0		;NO--RETURN TO CALLER
				;YES--FALL INTO RICC
;HERE WHEN A CONTROL-C TYPED
RICC::	PUSH	P,INTBLK+2	;SAVE OLD PC
	SKIPL	CCWAIT		;DO WE WANT CONTROL-C HELD UP?
	JRST	CCEXIT		;NO--CHARGE AHEAD
	INFO	WFC,<Please wait for Control-C>
	  JFCL
	OUTPUT	TTY,		;SPIT IT OUT
	SETOM	CCTYPED		;SET THE FLAG
	POPJ	P,0		;RETURN

CCEXIT:	PUSHJ	P,.ISLGI##	;ARE WE LOGGED IN?
	AOJE	T1,CCXIT1	;[645] IF NOT, DELETE SEARCH LIST AND QUIT
	WARN	LAC,<LOGIN aborted by Control-C - job is LOGGED-IN>
	  JFCL
	JRST	CCLAST		;EXIT QUICKLY

;[645] HERE IF ^C TYPED AND NOT LOGGED IN.  DELETE SEARCH LIST SO MOUNT
;[645]  COUNTS STAY CORRECT AND LET SCAN SAY "DOT KJOB DOT"

CCXIT1:	PUSHJ	P,ZEROSL	;Zero the search list
	JRST	.MNRET##	;Let SCAN do the talking

ZEROSL:	MOVEI	T1,.FSDSL	;[645] FUNCTION TO DEFINE SEARCH LIST
	SETOB	T2,T3		;[645] OUR JOB, OUR PPN
	MOVEI	T4,DF.SRM	;[645] DELETE UNNAMED STRUCTURES
	MOVE	N,[4,,T1]	;[645] ARG PTR
	STRUUO	N,		;[645] ZAP THE S.L.
	  JFCL			;[645] SIGH...
	POPJ	P,
LAST:	TLNE	F,FL.ATT	;SKIP IF LOGIN, NOT IF ATTACH
	JRST	ALAST		;FINISH UP ATTACH
	PUSHJ	P,PRVSET	;DO PRIV. SET UUOS
	TXNE	F,R.SESS	;IF SESSION JUST EXIT
	JRST	NORUN
REPEAT 0,<			;[543] CALL EXTERNAL MODULE TO SEE IF
	PUSHJ	P,RNMAIL##	;[543] USER HAS ANY MAIL
>;[543] END REPEAT 0

	PUSHJ	P,STRMES##	;[662] DO /STR IF DESIRED
	SETOM	CCWAIT		;[641] DISABLE CONTROL-C
	MOVE	T1,LGIARG	;NOW LOG THE GUY IN
	LOGIN	T1,
	  JFCL
	SKIPN	ENTRY+RCNWRD	;[563] UNLESS WE'RE GOING TO RUN A CUSP,
	  PUSHJ	P,CTLCOK	;[563] ALLOW CONTROL-C TO WORK AGAIN
	PUSHJ	P,USRSET	;[363] DO ORDINARY SETUUO'S (AND TRMOP.S)
	PUSHJ	P,DAYMES	;[472] PRINT OUT DAILY MESSAGES
	PUSHJ	P,POSTMS	;[472] DO POST-MESSAGE TRMOP.S (SPEED)
	OUTPUT	TTY,		;[510] DUMP TTY BUFFERS
	SKIPN	ENTRY+RCNWRD	;SKIP IF USER IS LOCKED INTO A PROGRAM
	PUSHJ	P,.RUNCM##	;PROCESS /RUN IF ANY
CCLAST:	SKIPN	T4,ENTRY+RCNWRD	;SKIP IF RUN UUO TO BE EXECUTED
	JRST	NORUN		;NO, DONT SET IT UP
	SKIPN	T3,ENTRY+RCDWRD	;YES, SKIP IF DEVICE SPECIFIED
	MOVSI	T3,(SIXBIT .SYS.)	;NO, ASSUME SYS
	SETZB	P1,P2
	MOVE	N,ENTRY+RCPWRD	;PPN
NORUN:	CLOSE	TTY,0		;CLOSE OUT THE TTY
	SETZB	M,LASTX		;CLEAR CORE
	MOVE	WD,TOLO1
NORUN1:	MOVE	T1,[XWD LASTX,LASTX+1]
	SKIPN	.JBDDT##	;SKIP THIS IF DDT IS LOADED
	BLT	T1,@.JBREL
	SETZM	.JBSA		;CLEAR START ADDRESS SINCE PROG NO LONGER THERE
	MOVE	T1,[XWD TOLO,LASTX]
	BLT	T1,LASTX+ETOLO-TOLO	;TRANSFER TO LOW SEG
	MOVEM	WD,LASTX+TOLO1-TOLO
	JUMPE	T4,LASTX+FRUN-TOLO	;JUMP IF NO RUN UUO
	SETZB	T3+3,T3+5	;CLEAR UNUSED ARGS
	JRST	LASTX		;DO RUN UUO
;THE CODE ON THIS PAGE IS COPIED TO THE LOWSEG AND EXECUTED
; FROM THERE. THIS IS DONE WITHOUT BENIFIT OF RELOCATION
; SO BE CAREFUL

TOLO:	MOVEI	WD,T3
	RUN	WD,UU.PHY	;[640] RUN CUSP, PHYSICAL-ONLY
FRUN:	SETZ	T1,		;NO RUN UUO OR RUN UUO FAILED
	SETNAM	T1,		;CLEAR NAME
	HRLI	T1,1		;[576] GET RID OF HI SEG
	HRRI	T1,1		;[576] AND SHRINK LOW SEG TO 1K
	SKIPN	.JBDDT##
	CORE	T1,
	  JFCL
TOLO1:	MONRT.
ETOLO:	EXIT			;AND EXIT IN CASE OF CONTINUE
ALAST:	MOVEI	T1,.GTPPN	;GET PPN OF JOB THAT I AM ABOUT
	HRL	T1,ATTJOB	;  TO ATTACH TO
	GETTAB	T1,		;[157]
	  JRST	NOATT		;     CAN'T GET PPN, CAN'T ATTACH
	CAME	T1,PPN		;PPN'S DIFFER?
	  JRST	NOATT		;  YES, CAN'T ATTACH
	HRRZ	T1,ATTJOB	;[611] JOB NO. TO ATTACH TO
	TRMNO.	T1,		;[611] SEE OF SOMEONE ALREADY THERE
	  JRST	ALAST1		;[611] LOOKS OK SO FAR
	JRST	NOATT		;[611] DON'T DETACH - SQUATTER'S RIGHTS
ALAST1:	MOVN	T1,ATTJOB	;[611] DO MORE CHECKING ON JOB
	JOBSTS	T1,		;[611] ..
	  JRST	NOATT		;[611] FUNNY JOB NUMBER?
	JUMPGE	T1,NOATT	;[611] IF JNA NOT SET, DIE
ALAST2:	MOVEI	M,CRLFPD
	PUSHJ	P,MSG		;MAKE IT LOOK GOOD
	RELEASE	TTY,		;[461] CLOSE OUT TTY
	SETO	T1,		;[420] MAKE T1=-1
	GETLCH	T1		;[420] GET LINE NUMBER AND BITS
	CAME	T1,[-1]		;[420] IF GETLCH A NO-OP OR
	TRNN	T1,-1		;[420] LINE IS DETACHED, THEN
	  JRST	NOATT		;[420] ATTACH HAD BETTER LOSE
	TRZ	T1,600000	;[420] CLEAR UDX BITS
	MOVSI	T1,400000(T1)	;[420] SET UP LINE NO., MONITOR MODE
	HRR	T1,ATTJOB	;[420] GET JOB NUMBER
	ATTACH	T1,		;ATTACH JOB TO TTY
	  JRST	NOATT		;WOOPS, COULDNT!

FLUSHX:	PUSHJ	P,ZEROSL	;Zero the search list
	CLOSE	TTY,0		;[456] FLUSH TTY BUFFER
	RESET			;TURN ON ECHOING
	SKIPE	T1,.JBDDT##	;SKIP IF NO DDT
	 JRST	(T1)		;GO TO DDT
	SETZB	T4,LASTX	;CLEAR CORE IF UNSUCCESSFUL LOGIN
	MOVE	WD,[LOGOUT]	;KILL KJOB
	JRST	NORUN1

	PRGEND
	TITLE	LGNLOW - Low segment for LOGIN

	SEARCH	UUOSYM,MACTEN,SCNMAC,LGNUNV,ACTSYM
	GLOBS		;DECLARE GLOBALS

DEFINE	LWORD(A),<
A::	BLOCK	1
>

DEFINE	LBLOCK(A,B),<
A::	BLOCK	B
>

	TWOSEG
	RELOC	400000
IFN FACTSW,<
FCTAHD:	XWD	240000,3
FCTHED:	XWD	100000,3
FCTFMD:	XWD	20000,2		;MODIFIER FOR FAILURE-TYPE ENTRIES
;** DO NOT SEPARATE THESE TWO LINES **

FCTWD:	XWD	-3,FCTDAT
FCTFWD:	XWD	-5,FCTDAT	;APPEND CONTROL WORD FOR FAILURES
>

LGIARG:	XWD	PPN-CHGNO-1,PPN	;ARGUMENT TO LOGIN UUO
PDPLST:	IOWD	PDLSIZ,PDL

	RELOC
	LOWVAR
	END