Google
 

Trailing-Edge - PDP-10 Archives - BB-J713A-BM - language-sources/batcon.mac
There are 39 other files named batcon.mac in the archive. Click here to see a list.
TITLE	BATCON  --  GALAXY Batch Job Controller
SUBTTL	C.D.O'Toole/M.L. BERKOWITZ	10-Dec-79


;
;
;                COPYRIGHT (c) 1975,1976,1977,1978,1979
;                    DIGITAL EQUIPMENT CORPORATION
;
;     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.

	LSTING==0		;NORMAL MODE IS LISTING ON

	BTNVER==104		;MAJOR VERSION NUMBER
	BTNMIN==0		;MINOR VERSION NUMBER
	BTNEDT==4133		;EDIT NUMBER
	BTNWHO==0		;WHO LAST PATCHED

	SEARCH	GLXMAC		;SEARCH FOR GALAXY PARAMETERS
	PROLOG(BATCON)		;SET UP BATCON WITH GLXLIB
	SEARCH	QSRMAC		;QUASAR DATA BASE SYMBOLS
	SEARCH	BATMAC		;BATCONS PARAMETER FILE
	SEARCH	ORNMAC		;GET ORIONS SYMBOLS



	;THE FOLLOWING ARE DEFINED EXTERNAL

	EXTERNAL L$OUT1		;LOG OUTPUT ROUTINE
	EXTERNAL LOGERR		;LOG FILE ERROR MESSAGE
	SUBTTL	TABLE OF CONTENTS FOR BATCON
;               TABLE OF CONTENTS FOR BATCON
;
;
;                        SECTION                                   PAGE
;    1. TABLE OF CONTENTS FOR BATCON..............................   2
;    2. Assembly Parameters.......................................   3
;    3. Revision History..........................................   4
;    4. SETUP UUO HANDLER AND VERSION INFO........................  10
;    5. BATCON Data Base..........................................  11
;    6. PREDEFINED STORAGE BLOCKS FOR BATCON......................  12
;    7. BATCON Entry Section......................................  13
;    8. Dispatch and Time slice Routines..........................  14
;    9. PROIPC--PROCESS IPCF MESSAGES.............................  15
;   10. WTOMSG  --      SEND A WTO MESSAGE FROM MAIN LEVEL........  16
;   11. TEXTMS--TEXT MESSAGE FROM QUASAR OR ORION.................  16
;   12. CHECKPOINT MESSAGE FROM QUASAR............................  17
;   13. MSGQSR  --      SETUP MESSAGE TO QUASAR...................  18
;   14. SNDQSR--SEND MESSAGE TO QUASAR............................  18
;   15. SNDCHK--SETUP AND SEND STATUS MESSAGE TO QUASAR...........  19
;   16. OPERATOR ACTION MESSAGE FROM QUASAR.......................  20
;   17. SETUPJ--ROUTINE TO PROCESS SETUP MESSAGE..................  21
;   18. ABORTJ--ABORT JOB BY USER REQUEST.........................  22
;   19. WTORMS--RESPONSE TO WTOR MESSAGE..........................  23
;   20. FNDITN  --      FIND STREAM BY ITN........................  23
;   21. PROMES--PROCESS ACTION MESSAGE FROM USER OR OPERATOR......  24
;   22. SENDJB  --      SEND TEXT TO JOB..........................  25
;   23. EXAMIN  --      SHOW CONTROL FILE TO OPERATOR.............  26
;   24. CLRSTR  --      CLEAN UP STREAM WHEN INACTIVE.............  27
;   25. FHIACT  --      FIND NEW HIACTV STREAM..INACTIVE WAS OLD HIACTV  27
;   26. NEXTJB--PROCESS NEXTJOB MESSAGE...........................  28
;   27. FIREUP--FIREUP A JOB FOR PROCESSING.......................  28
;   28. TOPS10 PTY STARTUP CODE...................................  30
;   29. TOPS20 PTY SETUP CODE.....................................  31
;   30. SET HALF DUPLEX FOR PTY...................................  32
;   31. Job Processor - Start the Stream..........................  33
;   32. LOGINJ  --      LOGIN A JOB ON PTY........................  34
;   33. LOGSET  --      SETUP JOB AFTER LOGIN.....................  35
;   34. JOBSTA  --      JOB STARTUP AFTER LOGIN COMPLETED.........  36
;   35. Job Processor - Honor Job's Input Request.................  37
;   36. Job Processor - Execute Batch Commands....................  43
;   37. Job Processor - Perform Auto KJOB and Dismiss the Job.....  51
;   38. QSRUPD  --      UPDATE DEVICE STATUS TO QUASAR............  52
;   39. IDNOPR  --      IDENTIFY LINE TO OPERATOR.................  53
;   40. CANCJB--CANCEL A JOB ROUTINE..............................  54
;   41. STOPJB AND CONTJB ROUTINES................................  55
;   42. CONTJB--CONTINUE JOB BY OPERATOR..........................  56
;   43. CANUSR--CANCEL FROMA USER REQUEST.........................  57
;   44. ATOKJB  --      LOGOUT FOR THE -10........................  58
;   45. ATOKJB  --      LOGOUT FOR THE -20........................  59
;   46. IOWAIT  --      Routine for Output/Input Waiting..........  60
;   47. WAITOU  --      WAIT FOR OUTPUT BEFORE PROCEEDING.........  61
;   48. Job Processor - Error Analysis, Processing, and Reporting.  64
;   49. Job Processor - Random Little Routines....................  65
;   50. CHANNEL RELEASE ROUTINES FOR PTYS.........................  68
;   51. CONTROL FILE MANIPULATION ROUTINES........................  70
;   52. TOPS-20 POSITIONING ROUTINES..............................  71
;   53. FNDCTL--OPEN CONTROL FILE ROUTINE.........................  72
;   54. INPPTY--PTY INPUT ROUTINES................................  73
;   55. SEND PTY OUTPUT TO JOB....................................  74
;   56. GETPTY--GET A CHARACTER FROM PTY INPUT BUFFER.............  75
;   57. PUTPTY--PUT CHARACTERS INTO PTY OUTPUT BUFFER.............  76
;   58. UUOCON--BATCON LUUO HANDLER...............................  78
;   59. TABSRC  --      TABLE LOOKUP ROUTINE......................  81
;   60. System Dependent Subroutines..............................  82
;   61. TOPS10 Subroutines........................................  83
;   62. TOPS20 Subroutines........................................  85
;   63. JOBSTS--JOB STATUS ON STREAM..............................  87
;   64. TSLEEP--SLEEP ROUTINE FOR DISPATCH LOOP...................  88
;   65. BATPSI--BATCON PSI ENABLE CODE............................  89
;   66. BATIPC--BATCON IPCF INTERRUPT HANDLER.....................  90
;   67. ERROR PRINT ROUTINE.......................................  90
;   68. INTERRUPT PROCESSING ROUTINES.............................  91
;   69. PTY AND LOG OUTPUT ROUTINES...............................  92
;   70. STAWTO  --      START WTO/WTOR MESSAGE....................  92
;   71. OUTEXT--ROUTINE TO FINISH MESSAGE AND EXIT................  92
;   72. SNWTOR  --      SEND WTOR ROUTINE.........................  92
;   73. ERRTAB--EXPAND ERROR TABLE VALUES.........................  93
SUBTTL	Assembly Parameters
IFN FTUUOS,<		;DEFINITIONS FOR TOPS10

	IF1,<PRINTX ASSEMBLING GALAXY-10 BATCON>

DEFINE KJSTR,<[ASCIZ\KJOB/BATCH\]>
DEFINE TIMSTR,<[ASCIZ/SET TIME /]>

>  ;END OF IFN FTUUOS



IFN FTJSYS,<		;DEFINITIONS FOR TOPS20

	IF1,<PRINTX ASSEMBLING GALAXY-20 BATCON>

DEFINE KJSTR,<[ASCIZ\LOGOUT\]>
DEFINE TIMSTR,<[ASCIZ/SET TIME-LIMIT /]>

>  ;END OF IFN FTJSYS
	SUBTTL	Revision History

	COMMENT	\

EDIT 1000  This was the version sent to In-House Q/A April 1974

EDIT 1001  Correct mixup in the channel allocator if the CTL file is not
		artifically preserved and DISPOSE:PRESERVE is set

EDIT 1002  Have BACKTO give the correct error if the label was not
		found BEFORE the initiating BACKTO command

EDIT 1003  Allow BACKTO and restart labels to skip over %FIN::

EDIT 1004  Allow NEXT command to select a job after the
		KSYS timer has expired

EDIT 1005  Fix interaction of SILENCE & REVIVE commands with
		DIALOGUE mode & QUOTES (")

EDIT 1006  Correct random little annoyances discovered by Q/A

EDIT 1007  On a line with only the label (e.g. FOO::<CR/LF>),
		the <CR/LF> is NOT to be sent to the subjob.  However,
		FOO::*<CR/LF> gives a blank line to the subjob.
		Same for IF (cond)<CR/LF>

EDIT 1010  Reformat WHAT line for the operators

EDIT 1011  Accept TELL, KILL, REQUEUE, etc...  when a job is STOPped

EDIT 1012  More of EDIT 1005, still a problem with SILENCE & REVIVE

EDIT 1013  Reformat DIALOGUE mode output for the operator

EDIT 1014  Include .MESSAGE for the Mini-Batch Standard
		It is the same as PLEASE <message><altmode><CR/LF>

EDIT 1015  Give more information when the user can't use the specified LOG file

EDIT 1016  General cleanup of code and elimination of
		subroutines no longer needed

EDIT 1017  Make more efficient use of old PTY channels.
		Big help when MJOB .GT. 5

EDIT 1020  Correct problem with REQUEUE labels

EDIT 1021  This was the version sent to Field Test June 1974
EDIT 1022  A leading tab was changed into a blank, shouldn't do that

EDIT 1023  Include /NAME:"<name>" on the LOGIN line

EDIT 1024  LOGIN error code 1 is the same as a warning message.
		Treat it as such.

EDIT 1025  Plug a hole in the SFD code

EDIT 1026  Can only force /RESTART:YES on Checkpoint

EDIT 1027  Post-job disposal of the CTL file wasn't done if the job
		was cancelled because of LOGIN

EDIT 1030  Provide some additional information in the CURRENT command output

EDIT 1031  Some more general cleanup

EDIT 1032  Routines that save and restore the CTL file position were being
		thrown off by "^" in strange places

EDIT 1033  Include BTNxxx for all error messages the user receives

EDIT 1034  Using "1H+" for Fortran overprinting would start at the time
		stamp, not at column 17

EDIT 1035  Implement several suggestions

EDIT 1036  QTS was called from one place, remove lots of code and
		change all references to QTS0 to QTS

EDIT 1037  A timing problem was introduced by EDIT 1024, correct it.

EDIT 1040  Implement more suggestions

EDIT 1041  This was the version released to the Field November 1974
Edits made to version 12 by Software Support that are also in version 100

EDIT 1051  GETSTS returns the status in the right half, Teach this to GETCTL. (SPR 15846)

EDIT 1054  Suppress trailing blanks on lines destined for the monitor command decoder.
		This should avoid any problems associated with card input.

EDIT 1055  With edit 477 of LOGIN, LOGMAX is now enforced. Invent error code
		5 to mean requeue this job, shutdown Batch for NJNINT minutes.
		(SPR 16184)




Edits made during the development of version 13 that are also in version 100


EDIT 1060  Separate old and new LOG files with a Form-Feed.
		Do this to more easily recognize when a LOG file is used more than once
		(SPR  several suggestions)

EDIT 1061  Invent a new reserved label %TERR::.  Control is passed to this label
		if TIME LIMIT EXCEEDED is detected.  It follows the same rules of
		precedence as %ERR:: with respect to %FIN::.  The %EXTRA time
		is given but the CLOSE/DUMP is not sent, allowing REENTER to be used for
		program cleanup for intelligent jobs.

EDIT 1063  De-implement the following:
	    (maintained for 1 versions worth of compatability)
		The FORCE Command (use NEXT)
		The old style $ processing for CDRSTK (who?)

EDIT 1064  The correct path wouldn't be sent to LOGIN if there were no
		SFD levels.  Send it if the P,Pn's are different.

EDIT 1070  Plug a security hole.
EDIT 2000  Begin conversion of MPB BATCON (v12) to the GALAXY-10 system

	     Major changes (aside from queueing protocol) include:

		Remove FTOPR options for a separate BATOPR
		Remove all code for LOGSWS conditionals, LOGIN v.57 is required
		De-implement edit 1017
		Redefine AC usage to conform with QUASAR's
		Change ATOKJB to talk to LOGOUT v.100
		CORE/MCORE parameters are P internally but K for the operators.
		Remove WHKSYS conditionals, Work is done by QUASAR
		At the request of our operators, the default value of PROMPT is 5 min.
		Remove all the BATCON assembly parameters that are now
		   defined in the GALGEN dialogue.

	     This was the version sent with GALAXY-10 Field Test,  June 1975

EDIT 2001  Report the P,Pn of the user requesting the cancellation of a job (ABO.DI)

EDIT 2002  Can get a job from QUASAR with EQ.RDE set, turn them around.

EDIT 2003  Quotes (") output from LOGOUT should be typed to the operator.

EDIT 2004  Fix all the code dealing with core limit enforcment.
		INPCOR, the default value of /CORE, is used to conditionally
		assemble the enforcement code.  If defined = 0, code is not assembled
		since NO was answered to the GALGEN question concerning core enforcment.

EDIT 2005  Take advantage of the new routine in CSPQSR.  Call CSPPSI to enable
		terminal input interrupts, avoid lots of SKPINL's.
	   General code cleanup.

EDIT 2006  Become version 101

EDIT 2007  .EQPAT is optional, Check for it.

EDIT 2010  Convert to TOPS20 style LOGIN, File handling, etc...

EDIT 2011  Fix all the bugs caused by edit 2010

EDIT 2012  The TOPS10 code got broken by edits 2010 & 2011, fix that.

EDIT 2013  Implement the new values for /OUTPUT, they are:
		/OUTPUT:NOLOG	Don't print the LOG
		/OUTPUT:LOG	Print it (default)
		/OUTPUT:ERROR	Print it if an unhandled error occurred
EDIT 2014  Some Code Cleanup and Bug Fixes, Specifically:
		Use the PROLOGUE macro to get SBSMAC Symbols.
		Calling sequence to CSPINI has changed.
		6.03 Monitor uses 1B2 of the OPEN of a PTY to indicate
			that jobs on that PTY are Batch.
		A bug in the TOPS20 code that PMAP'ed away my addressing space
			is corrected (a real cute one).
		Another TOPS20 bug that left the Log file JFN hanging around.
		The CHECKPOINT/REQUEUE messages have changed.
		Remove the old MPB restriction of 5 character labels
			for CHKPNT and /TAG.

EDIT 2015  On the -20, before logging a job out delete any spooled
		input files created by SPRINT for it.

EDIT 2050  Become version 102.
	   Begin to eliminate TOPS10 UUOs on TOPS20.

EDIT 2051  More of Edit 2050.

EDIT 2052  Add ROUTE operator command, tell QUASAR of operators request.

EDIT 2053  Removed

EDIT 2054  Start converting to the version 2 database format.

EDIT 2055  Convert to TOPS20 release 2 JSYSes.

EDIT 2056  Do some cleanup work on operator output.

EDIT 2057  Rework LOG file logic to do "in-his-behalf" FILOP on the -10.

EDIT 2060  Include jobname, user id, and sequence number on
	   all messages to the operator.  Fix a problem on the -20
	   where the LOGIN command was not always sent correctly.

EDIT 2061  Remove angle brackets around user name on "cancelled" message
	    on the -20.  Fix some minor problems.

EDIT 2062  Spooled card-reader files were not getting deleted on 20 due
		to a recently introduced bug in DELSPL.

EDIT 2063  Fix a timing problem on -20 which caused BATCON
		to not realize a job had really logged out.

;;First field-test release of GALAXY release 2, Jan, 1977

EDIT 2064  Fix a bad symbol reference in -10 version when core
		enforcement is turned on (%NSMXM). QAR #3.

EDIT 2065  Make log files work on device NUL on the -20.
		Don't CHKAC them and don't send to LPTSPL.
EDIT 2066  Fix a bug caused by edit 2052 which let BATCON start
		processing jobs before a START command was typed.
		(qar #9).

EDIT 2067  Edit 2066 caused some additional problems.  Try again.

EDIT 2070	FIX KJOB TIMEOUT FOR -20 RELEASE 3


EDIT 4000  Make this version 104, April 1977.
		Insert changes for new FP/FD.

EDIT 4001  Fix some problems in edit 4000.

EDIT 4002	CONVERT CSPMEM AND CSPQSR TO GLXLIB ROUTINES

EDIT 4003	USE GLXFIL FOR THE CONTROL FILE
		AND REPLACE RUNTIM UUO WITH GETJI JSYS

EDIT 4004	MAKE ONE SEGMENT AND REMOVE (S) FROM SABBLK(ERROR)
		FIX REPOSI AND EXAMINE CODE
EDIT 4005	ADD SOME PTY CODE FOR TOPS-20 AND CHANGE AC NAMES
		COMPLETE PTY CONVERSION OFF COMPATIBILITY PACKAGE
EDIT 4006	MAKE SURE CODE FOR -20 STILL WORKS ON THE -10

EDIT 4007	CORRECT LONG LINES AND LOG FILE ERROR RECOVERY(RLJFN)

EDIT 4010	CORRECT -20 PLACING JOB IN MONITOR MODE

EDIT 4011	CONVERT DATA BASE TO .JQ??? FROM Q.???

EDIT 4012	CREATE BATMAC AS BATCONS UNIVERSAL FILE

EDIT 4013	ADD NEW QUASAR MESSAGES FOR -10
EDIT 4014	ADD LOG FILE ERROR RECOVERY CODE TO QUEUE UP LOG FILE
		FOR USER FROM TEMP FILE CREATED BY BATCON
EDIT 4015	ADD NEW CHECKPOINT REQUEUE DEFINITIONS

EDIT 4016	PUT IN WTO ROUTINE TO ORION
EDIT 4017	ADD NEW ACTION PROCESSING BY LINKED LIST
EDIT 4020	ADD WTOR SUPPORT TO BATCON

EDIT 4021	REMOVE OPERATOR INTERFACE
EDIT 4022	ADD NEW CANCJB CODE AND OPTIONS

EDIT 4023	SET UP WTO FOR EACH STREAM AND MAIN PROCESS

EDIT 4024	ADD JOBMSG CODE INLINE NOT CONDITIONAL ASSEMBLY
		AND CONVERT A,B,C,D TO T1-T4

EDIT 4025	ELIMINATE JOBMSG WORD...ORION AND OPR WILL DECIDE

EDIT 4026	SET SPOOL BITS IN RELEASE FOR CREATED LOG FILES.
		(ERROR LOGS OR QUASAR CREATED)
EDIT 4027	CONVERT TO NEW WTO MESSAGE USING WTO.TY

EDIT 4030	ADD NEW ITEXT ERRTAB PROCESSING

EDIT 4031	ADD JOB NUMBER TO WTO MESSAGES

EDIT 4032	FIX FD LENGTH FOR THE CREATED LOG FILE ON OPEN ERROR AND
		NOTIFY OPERATOR ON FAILURE THAT JOB WILL BE CANCELED.
EDIT 4033	CORRECT LABEL INFO IN STATUS MESSAGE
EDIT 4034	CORRECT GETJI INFO ON THE -20
EDIT 4035	Fix Formating at CLOS.5 as well as L$CRL2 for 2 L$CRLF
EDIT 4036	INSTALL EDIT  3002 AS WELL AS -20
		UPDATE FOR NEW LOGIN LINES AND SUPPORT FOR MORE JOBS ON THE
		-20
EDIT 4037	ADD $WTO MESSAGES FOR SETUP MESSAGE
EDIT 4040	FIX CHECKPOINT STATUS MESSAGES FOR LOGGING IN JOBS 
		AS WELL AS CANCELED AND REQUEUED JOBS
EDIT 4041	FIX ?FULL FOR -20 AND SPEED UP PROCESSING OF OPR/USER REQUESTS
EDIT 4042	FIX OPERATOR MESSAGES
EDIT 4043	FIX -20 INTERRUPTS BY CHANGING INTERRUPT LEVELS
EDIT 4044	FIX INMONM ERROR WHEN -20 EXEC SUBCOMMANDS FAIL ALSO
 		FIX SOME SHOW-CONTROL-FILE MESSAGES
EDIT 4045	FIX -20 IOWAIT CODE
EDIT 4046	ADD CODE FOR ^R DISPLAYING OF JOB MESSAGE DATA
EDIT 4047	FIX MONITOR LEVEL PROBLEM ON -20
EDIT 4050	FIX STOP LOGIC
EDIT 4051	FIX SECURITY BUG FOUND BY LNEFF 2077
EDIT 4052	ADD SUPPORT FOR /BATLOG AND /OPRINT SWITCHES AND
		SET THE APPROPRIATE VALUES ON THE -20 FOR STREAM INFO IN
		THE MONITOR
EDIT 4053	ADD SUPPORT FOR .QOSTU STATUS UPDATE MESSAGE AND THE RESPONSE
		TO SETUP CODES FOR NO PTYS AND SYSTEM FULL
EDIT 4054	ADD NEW HEADER LINES TO LOG FILE FOR BATLOG(WRITE-LOG) AND
		OPERATOR-INTERVENTION (ASSISTANCE)
EDIT 4055	FIX ABORTJ BUG AND CLEANUP ATOKJB
EDIT 4056	ADD JOB NUMBER TO STATUS MESSAGE
EDIT 4057	MODIFY IOWAIT ON -20 TO GET STATUS EACH TIME 
EDIT 4060	MODIFY HONORJ TO ONLY GET STATUS IF ENTER THROUGH HONO.0
EDIT 4061	Add SPR 20-10487 for timing problem originally edit 2070
EDIT 4062	Save all Labels identified with BLABL in .JLABL for use in
		Status
EDIT 4063	Fix extra CRLF on BEGIN message also check EQ.PRV in File
		Open Routines to allow standard open not in behalf.
EDIT 4064	Convert to new GLXLIB and New I%JINF Routines for runtime and
		Program Name. Also use $STOP with ITEXT
EDIT 4065	CHECK LOGIN ERROR FOR INVALID ACCOUNT ON -20 OTHERWISE
		ASSUME NO JOBS SLOTS AND REQUEUE
EDIT 4066	ADD DELETE SPOOL FILES IN .EQSIS FOR THE -20
EDIT 4067	READ INPUT FROM PTY BEFORE ATOKJB
EDIT 4070	SET ACCOUNT OF USER ON LOG FILE FOR -20 
		HAVE JOBSTS VERIFY IF PTY HUNGRY THAT CHARACTERS HAVE BEEN READ
		USE EQ.IAS TO VERIFY ACCOUNT IN LOGIN FAILURES
EDIT 4071	OUTPUT PLEASE RESPONSE TEXT AND CLEAN UP IF JOB KILLED
EDIT 4072	FIX DELSPL ON -20 TO DELETE ALL FILES SPR 20-11329 EDIT 3001
EDIT 4073	ALLOW RESTART FOR JOB THAT USER MODIFIED AFTER SYSTEM CRASH TO
		BE RESTARTABLE.
		REMOVE EDIT 4061 SINCE 4070 BETTER SOLUTION
EDIT 4074	USE MINIMUM SIZE FOR MEMORY ALLOCATION.
		CONSOLIDATE MESSAGE TO QUASAR ROUTINES
EDIT 4075	CHECK FOR ERROR AFTER SETTING TIMER ON -20 LOGIN. REQUEUE
		THE JOB
EDIT 4076	Release Message Page (C%REL) for Operator Messages
EDIT 4077	ADD -20 STRUCTURE ACCOUNTING
EDIT 4100	CHANGE CASING ON BTN MESSAGES
EDIT 4101	FIX STATUS FOR JOB BEING SETUP
EDIT 4102	Convert Types and Messages to Upper and Lower Case and Add 
		Copyright Statement. Also Change Use of ENDERR to END.
EDIT 4103	Send Status Update on Restarted Jobs after they start. This will
		Give Quasar the Job number
EDIT 4104	Remove MONLVL and use INMO.1 TO MAKE -10
		WORK RIGHT
EDIT 4105	Always set Delete bit for Spool log Files. 
EDIT 4106	Change JOBSTS for the -20 to do 1 GETJI
EDIT 4107	Setup Jobs Location on the -20
EDIT 4110	Add New LOGIN Switches on the -10
EDIT 4111	FIX OUTPUT:NOLOG PROBLEM IN LOG FILE AND SEND MESSAGES TO 
		LOCATION OF THE JOB
EDIT 4112	CORRECT DELSPL PROBLEM AND USE ONLY THE RIGHT HALF OF THE USER
		NUMBER
EDIT 4113	Change -10 DUMP to DCORE
EDIT 4114	Correct JOBSTS problem on -20 again. This time the monitor
		has the fix.
EDIT 4115	Turn on Stream Number set for the -20 when setting the Batch
		Stream Number
EDIT 4116	CHANGE JOBS.3 SO WE CAN COUNT THE HUNGRY ERROR STATES
EDIT 4117	Change CANCEL to ABORT
EDIT 4120	Remove F%FCHN and use relative Stream number for the channel
EDIT 4121	Add code back at JOBS.3 to clear hungry in certain cases
		Add ERJMP after a SETJB
EDIT 4122	Change the L$OUTP and L$CHKP to return back instead of 
		just aborting.
		This prevents the SNDCHK code from having the main stack
		as streams stack. This can cause too many text levels.
		Fix QAR when -20 logout happens quickly and there is no 
		more output to wait for.
EDIT 4123	Have -10 DCORE add extension .DMP to avoid deletion.
EDIT 4124	Use -1 as ack code for CANUSR so that ORION will log and not
		generate an error
EDIT 4125	Fix a bug in NEWJOB so that the AC's checking the /UNIQUE
		switch value dont self destruct.
EDIT 4126	Send a ^C on the -10 on user login failure to clean up Job
		slot
EDIT 4127	Correct Batch Bug in LOGIN when log file Opened during
		LOGIN

EDIT 4130	TOPS-20 only. The SOUT JSYS now has an error return to
		indicate a  PTY's buffer is full. Teach BATCON. Routines
		affected: PTYSND (BATCON).

EDIT 4131	TOPS-20 ONLY. Can't trust the status returned by interrupts
		regarding PTY hungry. JSYSs don't lie. Use them instead.
		Routines affected: JOBSTS (BATCON).

EDIT 4132	TOPS-20 only. Forgot to do a GETER JSYS before checking error
		code. Routines affected: PTYSND (BATCON).

EDIT 4133	TOPS-20 only. More of 4132. Routines affected: PTYSND (BATCON).
\
	SUBTTL	SETUP UUO HANDLER AND VERSION INFO
;SET UP FOR BALANCE OF ASSEMBLY


	LOC	41
	PUSHJ	P,UUOCON	;UUO INTERRUPT

	%%.BAT==<VRSN.(BTN)>		;SET UP VERSION INFO
	LOC	137
	EXP	%%.BAT			;BATCON VERSION INFO

	RELOC	0
	SUBTTL	BATCON Data Base

	SYSPRM	IODISP,IOWAIT,IOW.02	;DISPATCH ENTRY FOR -10 AND -20
LOWDAT:
BASTBL:: BLOCK	DEFMJB	;STREAM DATA BASE POINTERS (ALSO STREAM AC R)
STREAM:: BLOCK	DEFMJB	;STREAM INDEX BLOCK FOR BATCH STREAMS
TOPPDL:	BLOCK	TPSIZE	;TOP LEVEL PUSH DOWN LIST
HIACTV:	BLOCK	1	;HIGHEST STREAM NUMBER ACTIVE
STACTV:	BLOCK	1	;NUMBER OF ACTIVE STREAMS
CURTIM:: BLOCK	2	;UNIVERSAL DATE TIME FOR $TEXT OUTPUT
MINMAX:	BLOCK	1	;CORE VALUE FOR MIN AND MAX
TEMP2:	BLOCK	1	;TEMP CELL USED DURING '.ERROR' AND '.OPERATOR'
WTOCNT:	BLOCK	1		;COUNT UNUSED IN WTO MESSAGE PAGE
				;POINTER MUST FOLLOW ***
WTOPTR:	BLOCK	1		;BYTE POINTER WITHIN WTO MESSAGE
JOBTOT:: BLOCK	1		;NUMBER OF JOBS PROCESSED
JOBSCT:	BLOCK	1		;TOTAL NUMBER OF JOBSTS DONE
JOBWCT: BLOCK	1		;COUNT OF WAITS DURING LOGIN AND LOGOUT
STIME:	BLOCK	1		;START UNIV. DATE AND TIME
FLAGS:	BLOCK	1		;GLOBAL FLAGS FOR BATCON
	B.REMT==1B0		;REMOTE PROCESSING IS AVAILABLE
IFN FTJSYS,<
DEVNAM:	BLOCK	2		;DEVICE NAME
FIRPTY:	BLOCK	1		;PTY OFFSET FOR PTY NUMBER
NUMPTY:	BLOCK 	1		;NUMBER OF PTYS IN THE SYSTEM
INTRP1:	BLOCK	1		;INTERRUPT LEVEL PC
INTRP2:	BLOCK	1		;INTERRUPT PC LEVEL 2
INTRP3:	BLOCK	1		;INTERRUPT PC LEVEL 3
EE:	BLOCK	1		;TEMPORARY STORAGE FOR INPPTY

SPLNUM:	BLOCK	1		;DIRECTORY NUMBER OF <SPOOL>
INTERR:	BLOCK	1		;PTY ERRORS ENCOUNTERED
UDIERR:	BLOCK	1		;USER INPUT ERRORS
MYNODE:	BLOCK	1		;SAVE MY NODE VALUE

>  ;END OF IFN FTJSYS
	MAX <RSU.SZ!REL.BL!STU.SZ!REQ.SZ!CHE.SZ>
MSGADR:	BLOCK	MAXSIZ			;MESSAGE DATA AREA
IFN FTUUOS,<
SFDPAT:	BLOCK	11	;SFD BLOCK - WORDS 0,1, AND 10 ARE ALWAYS ZERO
>  ;END OF IFN FTUUOS

INMONE:	BLOCK	1			;IN MONITOR MODE ERROR COUNT
LASLOW:
CORCHK:	EXP	INPCOR		;FLAG WORD FOR CORE CHECKING
IFN	FTJSYS,<
STRCHN:	
	ZZ==0
	REPEAT 3,<EXP	ZZ
	ZZ=ZZ+2>
	ZZ=^D23
	REPEAT PTYNCH,<EXP	ZZ
	ZZ=ZZ+2>
LEVTAB:	EXP	INTRP1			;INTERRUPT LEVEL PC
	EXP	INTRP2		;LEVEL 2 INTERRUPTS
	EXP	INTRP3		;LEVEL 3 INTERRUPTS
	DEFINE	CHNBLD(XX,YY),<
	XWD	INT.IN,PTYC'XX	;PTY  HAS OUTPUT
	XWD	INT.OU,PTYC'YY	;PTY WANTS INPUT (HUNGRY)
	>
CHNTAB:	ZZ==0
	ZZ1==1
	REPEAT	3,<CHNBLD(\ZZ,\ZZ1)
	ZZ==ZZ+2
	ZZ1=ZZ+1>
	BLOCK	^D17		;INTERRUPT SYSTEM CHANNEL TABLE
	REPEAT	PTYNCH,<CHNBLD(\ZZ,\ZZ1)
	ZZ==ZZ+2
	ZZ1=ZZ+1>
	XWD	INT.AL,BATIPC	;BATCON IPCF INTERRUPT CHANNEL 35
>  ;END OF IFN FTJSYS
IFN FTUUOS,<

VECTOR:	BLOCK	0			;BEGINNING OF INTERRUPT VECTOR
VECIPC:	BLOCK	4			;IPCF INTERRUPT BLOCK
	ENDVEC==.-1			;END OF INTERRUPT VECTOR

>  ;END IFN FTUUOS
	SUBTTL	PREDEFINED STORAGE BLOCKS FOR BATCON

	;HELLO MESSAGE TO QUASAR BLOCK

HELLOM:	$BUILD	HEL.SZ	;HELLO MESSAGE TO QUASAR
	$SET(.MSTYP,MS.TYP,.QOHEL)	;HELLO MESSAGE
	$SET(.MSTYP,MS.CNT,HEL.SZ)	;MESSAGE SIZE
	$SET(HEL.NM,,<'BATCON'>)	;PROGRAM NAME
	$SET(HEL.FL,HEFVER,%%.QSR)	;QUASAR VERSION NUMBER
	$SET(HEL.NO,HENNOT,1)		;NUMBER OF OBJECTS
	$SET(HEL.NO,HENMAX,DEFMJB)	;MAXIMUM NUMBER OF STREAMS
	$SET(HEL.OB,,.OTBAT)		;OBJECT TYPE BATCH
	$EOB

	;ORION IPCF SEND BLOCK

	;QUASAR IPCF SEND BLOCK

SABBLK:	$BUILD	SAB.SZ			;BUILD SEND ARGUMENT BLOCK
	$SET(SAB.PD,,<0>)		;PID TO SEND TO ...0
	$SET(SAB.LN,,<PAGSIZ>)		;SIZE OF MESSAGE PAGE=1000
	$SET(SAB.SI,SI.FLG,<1>)		;SYSTEM PID FLAG
	$SET(SAB.SI,SI.IDX,<SP.QSR>)	;SPECIAL PID INDEX
	$EOB

	;GLXLIB INITIALIZATION BLOCK

IPBBLK:	$BUILD	IB.SZ			;BUILD IB BLOCK FOR INIT
	$SET(IB.PRG,,%%.MOD)		;PROGRAM NAME
	$SET(IB.OUT,,OUTDAT)		;DEFAULT OUTPUT ROUTINE
	$SET(IB.FLG,IP.STP,1)		;STOPCODES TO ORIONS
IFN	FTJSYS,<
	$SET(IB.INT,,<LEVTAB,,CHNTAB>)	;SIR OF INTERRUPT SYSTEM
>;END FTJSYS
IFN	FTUUOS,<
	$SET(IB.INT,,VECTOR)		;TOPS-10 INTERRUPT VECTOR
>;END FTUUOS
	$SET(IB.PIB,,PIBBLK)		;ADDRESS OF PID BLOCK
	$EOB

PIBBLK:	$BUILD PB.MNS
	$SET(PB.HDR,PB.LEN,PB.MNS)	;MINIMUM SIZE PID BLOCK
	$SET(PB.FLG,IP.PSI,1)		;ATTACH TO PSI
IFN	FTJSYS,<
	$SET(PB.INT,IP.CHN,^D35)	;CHANNEL TO ATTACH TO
>;END FTJSYS
IFN	FTUUOS,<
	$SET(PB.INT,IP.CHN,<VECIPC-VECTOR>)	;OFFSET FOR IPCF
>;END FTUUOS
	$SET(PB.SYS,IP.BQT,-1)			;SET MAX QUOTAS
	$EOB

ITIME:	ITEXT	(<^D/T1/:^D2R0/T2/:^D2R0/T3/>)
JIBTXT:: ITEXT	(<^R/.JQJBB(R)/
>)					;JOB INFO BLOCK EXPANSION
	SUBTTL	BATCON Entry Section

BATCON:	JFCL			;NO CCL ENTRY POINT
	RESET
	MOVE	P,[IOWD TPSIZE,TOPPDL]
	SETZM	LOWDAT		;PREPARE TO CLEAR THE LOW SEG
	MOVE	T1,[LOWDAT,,LOWDAT+1]
	BLT	T1,LASLOW-1	;CLEAR ALL THE LOW SEGMENT
	MOVEI	S2,IPBBLK	;IPB BLOCK FOR I%INIT
	MOVEI	S1,IB.SZ	;SIZE OF THE BLOCK
	PUSHJ	P,I%INIT##	;INITIALIZE GLXLIB SYSTEM
	$CALL	I%NOW		;GET CURRENT TIME
	MOVEM	S1,STIME	;SAVE TIME FOR  START
	PUSHJ	P,ONCECN	;SET UP ONCE ONLY CONSTANTS
	MOVSI	S1,-DEFMJB	;NUMBER OF JOBS
BATC.1:	SETOM	STREAM(S1)	;INIT TO -1
	AOBJN	S1,BATC.1	;GET THEM ALL
	PUSHJ	P,BATPSI	;SET UP INTERRUPT SYSTEM
	MOVEI	S1,HELLOM	;MESSAGE ADDRESS IN S
	MOVEM	S1,SABBLK+SAB.MS ;SAVE MESSAGE ADDRESS
	PUSHJ	P,SNDQSR	;SEND TO QUASAR
	PUSHJ	P,WAKEME	;SET WAKE CONDITIONS FOR FIRST TIME
	SUBTTL	Dispatch and Time slice Routines

TOPLVL:	$CALL	C%RECV		;ATTEMPT TO RECEIVE A MESSAGE
	JUMPF	TOPL.0		;NO,,CONTINUE ON
	PUSHJ	P,PROIPC	;PROCESS IPCF MESSAGES
	JRST	TOPLVL		;FINISH OFF ALL MESSAGES
TOPL.0:	SKIPN	STACTV		;ANY STREAMS ACTIVE
	  JRST	DISP.3		;NO, SEE IF SCHEDULING HAS HAPPENED
TOPDIS:	SETZM	CURTIM+1		;CLEAR SECOND WORD
	$TEXT	(<-1,,CURTIM>,<^C/[-1]/^A>)
	MOVEI	S,0		;START AT THE BEGINNING
DISP.1:	SKIPL	R,BASTBL(S)	;GET DATA BASE WORD
	JRST	DISP.2		;CANNOT PROCESS THIS STREAM
	TLNE	R,RL.MES!RL.CKP	;ANY MESSAGE LIST SET UP OR CHECKPOINT NEEDED
	PUSHJ	P,CHKMES	;YES,,CHECK FOR MESSAGES
	TLZE	R,RL.MSP	;MESSAGE TO PROCESS???
	JRST	DISP.C		;YES .. PROCESS
	TLNE	R,RL.STP!RL.OPR	;IS IT STOPPED OR OPR WAIT
	  JRST	DISP.2		;CANNOT PROCESS THIS STREAM
DISP.C:	MOVSI	17,.JREGS(R)	;SET TO RESTORE PROCESSOR REGS
	BLT	17,13		;RESTORE 0-13
	MOVE	17,.JREGS+14(R)	;AND RESTORE P
	POPJ	P,		;RETURN TO INTERUPTED PROCESS

;RETURN FROM PROCESS IS BY PUSHJ P,QTS.  WHICH SAVES THE REGS AND
;PROCEEDS TO NEXT PROCESS.

QTS:	MOVEM	R,BASTBL(S)	;SAVE R FLAGS
	MOVEM	17,.JREGS+14(R)	;SAVE P
	MOVEI	17,.JREGS(R)	;SET TO SAVE THE PROCESSOR REGS
	BLT	17,.JREGS+13(R)	;SAVE THEM ALL
	MOVE	P,[IOWD TPSIZE,TOPPDL] ;RESTORE TOP LEVEL PDL
STEXIT:				;EXIT FROM STREAM
DISP.2:	CAMGE	S,HIACTV	;PASSED ALL ACTIVE JOBS
	  AOJA	S,DISP.1	;NO, SKIP TO NEXT
DISP.3:	PUSHJ	P,TSLEEP	;JOB SLEEP,HIBER ROUTINE
	JRST	TOPLVL		;REENTER TOP LEVEL LOOP


CHKMES:	TLZE	R,RL.CKP	;CHECKPOINT NEEDED
	JRST	CHKM.1		;DO THE CHECKPOINT
CHKM.0:	SKIPG	.JMESC(R)	;ANY MESSAGES LEFT
	POPJ	P,		;NO..RETURN
	PUSHJ	P,PROMES	;PROCESS MESSAGES
	JUMPF	.POPJ		;MESSAGE IN PROGRESS,,,RETURN
	JRST	CHKMES		;SEE IF ANY MORE
CHKM.1:	MOVE	F,.JREGS+F(R)		;RESTORE THE F VALUES
	PUSHJ	P,SNDCHK	;SEND THE STATUS AND CHECKPOINT LOG FILE
	TLNN	R,RL.KJB	;IS JOB LOGGING OUT IGNORE CLOSJB
	JUMPF	CHKM.3		;ERROR..SETUP TO ABORT JOB
CHKM.2:	MOVEM	F,.JREGS+F(R)	;SAVE F AGAIN
	MOVEM	R,BASTBL(S)	;UPDATE R IN BASTBL
	JRST	CHKM.0		;CHECK FOR MESSAGES NOW
CHKM.3:	MOVE	S1,.JREGS+14(R)	;GET STREAMS STACK
	PUSH	S1,[CLOSJB]	;PUT CLOSE ON STACK
	MOVEM	S1,.JREGS+14(R)	;RESTORE THE STACK
	TLZ	R,RL.OPR!RL.STP!RL.JIE!RL.DIA ;CLEAR R FLAGS
	TLZ	F,FL.NER!FL.PLS	;CLEAR F FLAGS
	TLO	R,RL.MSP	;SET MESSAGE TO PROCESS
	JRST	CHKM.2		;SETUP TO RETURN
	SUBTTL	PROIPC--PROCESS IPCF MESSAGES

PROIPC:	LOAD	S2,MDB.SI(S1)		;GET SYSTEM PID INFO
	TXZN	S2,<SI.FLG>		;FROM SYSTEM PID
	POPJ	P,			;NOT FROM SYSTEM PID...IGNORE
	LOAD	T1,S2,SI.IDX		;GET SYSTEM PID INDEX
	CAIE	T1,SP.QSR		;IS IT FROM QUASAR
	CAIN	T1,SP.OPR		;IS IT FROM ORION
	SKIPA				;YES..
	POPJ	P,			;NOT FROM QUASAR OR ORION..IGNORE
	LOAD	G,MDB.MS(S1),MD.ADR	;GET MESSAGE ADDRESS
	LOAD	T2,.MSTYP(G),MS.TYP	;GET MESSAGE TYPE
	MOVSI	S1,-NUMMSG		;NUMBER OF MESSAGES
PROP.1:	HRRZ	T1,MSGTAB(S1)		;GET TABLE ENTRY
	CAMN	T2,T1			;CHECK IFMATCH
	JRST	PROP.2			;YES...GO PROCESS
	AOBJN	S1,PROP.1		;NO....TRY NEXT ENTRY
	CAIL	T1,.OMOFF		;FIRST ORION MESSAGE
	PJRST	PROP.3			;CHECK OPERATOR ACTION MESSAGE
	MOVEI	S2,[ITEXT (<Invalid Message Type ^O/T2/ From QUASAR or ORION>)]
	PUSHJ	P,WTOMSG		;SEND WTO WITH ERROR
	PJRST	C%REL			;RELEASE THE MESSAGE
PROP.2:	HLRZ	T1,MSGTAB(S1)		;GET ROUTINE ADDRESS
	PUSHJ	P,0(T1)			;PROCESS MESSAGE
	PJRST	C%REL			;RELEASE MESSAGE AND RETURN
PROP.3:	PUSHJ	P,OPRACT		;PROCESS THE MESSAGE
	PJRST	C%REL			;RELEASE MESSAGE AND RETURN

	;MESSAGE TABLE FOR DISPATCHING IPCF'S

MSGTAB:	XWD	NEXTJB,.QONEX		;NEXTJOB MESSAGE
	XWD	CHKPNT,.QORCK		;CHECKPOINT MESSAGE
	XWD	WTORMS,.OMRSP		;RESPONSE TO WTOR
	XWD	ABORTJ,.QOABO		;ABORT MESSAGE
	XWD	SETUPJ,.QOSUP		;SETUP JOB MESSAGE
	XWD	TEXTMS,MT.TXT		;TEXT MESSAGE FROM QUASAR OR ORION
		NUMMSG==.-MSGTAB	;NUMBER OF ENTRIES IN TABLE
	SUBTTL	WTOMSG	--	SEND A WTO MESSAGE FROM MAIN LEVEL

	;THIS ROUTINE IS CALLED WITH S2 ADDRESS OF ITEXT

WTOMSG:	$WTO	(<BATCON Error>,<^I/(S2)/>)
	POPJ	P,			;RETURN

	SUBTTL	TEXTMS--TEXT MESSAGE FROM QUASAR OR ORION

TEXTMS:	MOVEI	S2,[ITEXT (<BATCON IPCF Message Error
^T/.OHDRS+ARG.DA(G)/>)]
	;*** TEXT MESSAGE HAS ARGUMENT BLOCK WITH TEXT
	PJRST	WTOMSG			;SEND THE WTO MESSAGE
	SUBTTL	CHECKPOINT MESSAGE FROM QUASAR

CHKPNT:	MOVE	T3,RCK.TY(G)		;GET OBJECT TYPE
	CAIE	T3,.OTBAT		;IS IT BATCH
	PUSHJ	P,ERROR			;NOT BATCH JOB,,,STOPCODE
					;QUASAR ERROR
	LOAD	S1,RCK.UN(G),RO.UNI	;GET UNIT NUMBER
	PUSHJ	P,FSTREA		;FIND THE STREAM
	JUMPF	.POPJ			;CAN'T FIND...IGNORE IT
	MOVE	S,S1			;PLACE STREAM INDEX IN S
	SKIPL	R,BASTBL(S)		;GET DATA BASE WORD
	POPJ	P,			;NO..STREAM INACTIVE..IGNORE
	MOVE	S1,RCK.IT(G)		;GET ITN FOR JOB
	CAME	S1,.JQITN(R)		;CHECK IF MATCH CURRENT JOB
	JRST	CHKE.1			;CHECKPOINT ERROR
	TLO	R,RL.CKP		;SET TO CHECKPOINT THE JOB
	MOVEM	R,BASTBL(S)		;RESTORE R TO BASTBL
	POPJ	P,			;RETURN

CHKE.1:	MOVEI	S2,[ITEXT (<Checkpoint Message For Stream ^D/STREAM(S)/ Specified Wrong Job>)]
	PUSHJ	P,WTOMSG		;SEND THE MESSAGE
	PUSHJ	P,S..IMQ		;INVALID MESSAGE FROM QUASAR..STOPCODE
	SUBTTL	MSGQSR	--	SETUP MESSAGE TO QUASAR

	;THIS ROUTINE WILL GET DATA AND SETUP FOR QUASAR MESSAGE

	;CALL	S1/	SIZE OF AREA TO CLEAR
	;
	;
	;RETURN	S2/	MESSAGE ADDRESS

MSGQSR:	MOVEI	S2,MSGADR		;GET MESSAGE ADDRESS
	PUSHJ	P,.ZCHNK		;CLEAR THE DATA
	STORE	S2,SABBLK+SAB.MS	;SAVE THE MESSAGE ADDRESS
	POPJ	P,			;RETURN

	SUBTTL	SNDQSR--SEND MESSAGE TO QUASAR

SNDQSR:	LOAD	S1,@SABBLK+SAB.MS,MS.CNT;GET THE MESSAGE COUNT
	STORE	S1,SABBLK+SAB.LN	;SAVE IN SABBLK
	MOVEI	S1,SAB.SZ		;SIZE OF BLOCK IN S1
	MOVEI	S2,SABBLK		;ADDRESS OF BLOCK
	$CALL	C%SEND			;SEND TO QUASAR
	JUMPT	.POPJ			;O.K..RETURN
	$STOP(SFQ,SEND FAILURE TO QUASAR)
	SUBTTL	SNDCHK--SETUP AND SEND STATUS MESSAGE TO QUASAR

SNDCHK:: TRNN	F,FR.LFO		;CHECK IF LOG FILE OPEN
	JRST	SNDSTS			;AVOID CHECKPOINT
	PUSHJ	P,L$CHKP##		;CHECKPOINT THE LOG
	JUMPF	.POPJ			;ERROR..RETURN FALSE BACK TO CALLER
SNDSTS:: MOVEI	S1,CHE.SZ			;SIZE OF THE MESSAGE
	PUSHJ	P,MSGQSR		;SETUP THE MESSAGE DATA AREA
	MOVX	S1,.QOCHE		;MESSAGE TYPE
	STORE	S1,.MSTYP(S2),MS.TYP	;SAVE TYPE IN MESSAGE
	MOVE	P2,S2			;PLACE MESSAGE ADDRESS IN P2
	MOVSI	S1,(POINT 7,0)		;BYTE POINTER SETUP
	HRRI	S1,CHE.ST(P2)		;STATUS AREA IN MESSAGE
	MOVEM	S1,.JSPTR(R)		;SAVE IN DATA BASE
	MOVX	S1,<CH.FST>		;SEND STATUS
	TRZE	F,FR.CHK		;WANT CHECKPOINT UPDATED ON DISK
	TXO	S1,<CH.FCH>		;YES..UPDATE CHECKPOINT(QUASAR)
	MOVEM	S1,CHE.FL(P2)		;UPDATE FLAG WORD
	SKIPG	S1,.JJOBN(R)		;NUMBER ASSIGNED
	PJRST	SETM.1			;NO..SEND MESSAGE AND EXIT
	STORE	S1,CHE.FL(P2),CH.JBN	;SAVE JOB NUMBER
	$TEXT	(STSOUT,< Job# ^D/.JJOBN(R)/^A>)	;JOB NUMBER
	TLNE	R,RL.OPR		;IN OPERATOR WAIT
	PJRST	SETM.2			;YES..SEND MESSAGE AND EXIT
	MOVE	S1,.JJOBN(R)		;GET THE JOB NUMBER
	MOVX	S2,JI.PRG		;GET PROGRAM NAME
	PUSHJ	P,I%JINF		;GET JOB INFO
	SKIPE	S2			;NO NAME..IGNORE THIS STATUS
	$TEXT	(STSOUT,< Running ^W/S2/^A>)
	SKIPE	S1,.JLABL(R)		;CHECK IF HAD LABEL
	TLNN	S1,770000		;WAS IT A LABEL
	SKIPA				;NO..IGNORE LABEL
	$TEXT	(STSOUT,< Last Label: ^W/S1/^A>)
	MOVE	S1,.JJOBN(R)		;GET JOB NUMBER
	MOVX	S2,JI.RTM		;GET THE RUNTIME
	PUSHJ	P,I%JINF		;GET THE JOB INFO
	MOVE	T1,S2			;PLACE VALUE IN T1
	IDIVI	T1,^D1000		;CONVERT TO SECONDS
	IDIVI	T1,^D3600		;GET HOURS IN T1
	IDIVI	T2,^D60			;GET MINUTES IN T2,,SEC..T3
	$TEXT	(STSOUT,< Runtime ^I/ITIME/^0>)
SETEND:	HRRZ	S1,.JSPTR(R)		;GET LAST ADDRESS
	SUBI	S1,-1(P2)		;COMPUTE THE LENGTH
	STORE	S1,.MSTYP(P2),MS.CNT	;SAVE THE MESSAGE COUNT
	MOVE	S1,.JQITN(R)		;THE TASK NAME
	MOVEM	S1,CHE.IT(P2)		;STORE
	HRLI	S1,.JINFO(R)		;CHECKPOINT/REQUEUE INFORMATION
	HRRI	S1,CHE.IN(P2)		;INTO THE MESSAGE
	BLT	S1,CHE.IN+<EQCKSZ-1>(P2)  ;MOVE ALL THE WORDS
	PJRST	SNDQSR			;SEND TO QUASAR AND RETURN


STSOUT:	IDPB	S1,.JSPTR(R)		;SAVE BYTE IN MESSAGE
	$RETT				;RETURN

SETM.1:	MOVEI	S1,[ASCIZ /Job Being Setup by BATCON/]
	PJRST	TEXSTS			;SEND STATUS TO QUASAR
SETM.2:	MOVEI	S1,[ASCIZ / Waiting for Operator Response/]
	PJRST	TEXSTS			;SEND STATUS TO QUASAR

TEXSTS:	$TEXT	(STSOUT,<^T/(S1)/^0>)	;PUT STATUS IN MESSAGE
	PJRST	SETEND			;FINISH OFF MESSAGE
	SUBTTL	OPERATOR ACTION MESSAGE FROM QUASAR

OPRACT:	MOVEI	T3,.OHDRS(G)		;GET START OF BLOCKS
	LOAD	S1,ARG.HD(T3),AR.TYP	;GET ARGUMENT TYPE
	CAIE	S1,.OROBJ		;IS IT OBJECT BLOCK
	PUSHJ	P,ERROR			;NO..ERROR
	LOAD	S1,ARG.DA+OBJ.TY(T3)	;GET OBJECT TYPE
	CAIE	S1,.OTBAT		;IS IT A BATCH TYPE
	PUSHJ	P,ERROR			;NO..ERROR
	LOAD	S1,ARG.DA+OBJ.UN(T3),OU.LRG ;GET THE STREAM NUMBER
	PUSHJ	P,FSTREA		;FIND THE STREAM
	JUMPF	.POPJ			;NO..IGNORE IT
	MOVE	S,S1			;PLACE RELATIVE INDEX IN S
	SKIPL	R,BASTBL(S)		;GET BASE AC FOR STREAM
	POPJ	P,			;NO...IGNORE MESSAGE
	SOS	.OARGC(G)		;DECREMENT ARGUMENT COUNT
	LOAD	S2,.MSTYP(G),MS.TYP	;GET THE MESSAGE TYPE
	LOAD	S1,ARG.HD(T3),AR.LEN	;GET LENGTH OF OBJECT BLOCK
	ADD	T3,S1			;GET ADDRESS OF NEXT ARGUMENT
	MOVSI	S1,-OACNUM		;NUMBER OF MESSAGES
OPRA.1:	HRRZ	T1,OACTAB(S1)		;GET MESSAGE TYPE
	CAMN	S2,T1			;HAVE A MATCH??
	JRST	OPRA.2			;YES,,,FOUND MATCH
	AOBJN	S1,OPRA.1		;NO..TRY AGAIN
	POPJ	P,			;INVALID MESSAGE TYPE..IGNORE
OPRA.2:	HLRZ	T1,OACTAB(S1)		;GET ROUTINE ADDRESS
	MOVE	P1,OACMSG(S1)		;GET MESSAGE NAME
	MOVEI	T4,OACTAB(S1)		;SAVE ADDRESS OF ENTRY
	MOVE	R,BASTBL(S)		;SETUP R
	MOVE	F,.JREGS+F(R)		;AND FLAG AC
	PUSHJ	P,MESLST		;GET LIST AND POSITION
	LOAD	S2,.MSTYP(G),MS.CNT	;GET MESSAGE SIZE
	ADDI	S2,IPC.DA		;SIZE OF BLOCK
	MOVE	S1,.JMLST(R)		;LIST NUMBER FOR MESSAGE
	;MEMORY OPTIMIZATION BY USING MINIMUM SIZE BLOCK
	CAIGE	S2,ALCSIZ-3		;GREATER OR EQUAL TO MINIMUM SIZE
	MOVEI	S2,ALCSIZ-3		;ALLOW FOR LIB OVERHEAD
	$CALL	L%CENT			;CREATE AN ENTRY
	MOVE	T2,S2			;SAVE ADDRESS IN T2
	CAIGE	T4,OACCUR		;CHECK POSITION IN LIST
	TLO	T1,B.DEFR		;DEFER PROCESSING OF MESSAGE
					;FOR PROCESS CONTEXT
	CAIG	T4,OACCNT		;STOP OR CONTINUE
	TLO	T1,B.STCN		;STOP OR CONTINUE
	MOVEM	T1,IPC.RT(T2)		;SAVE ROUTINE ADDR IN WORD 0
	ANDI	T3,777			;GET THE OFFSET
	ADDI	T3,IPC.DA(T2)		;CONVERT TO PLACE IN MESSAGE
	MOVEM	T3,IPC.AR(T2)		;SAVE NEXT ARGUMENT ADDRESS
	HRRI	S1,IPC.DA(T2)		;MESSAGE LIST AREA
	HRLI	S1,.MSTYP(G)		;SOURCE OF MESSAGE
	LOAD	S2,.MSTYP(G),MS.CNT	;GET LENGTH OF MESSAGE
	ADDI	S2,IPC.DA(T2)		;ENDING ADDRESS OF MESSAGE
	BLT	S1,-1(S2)		;MOVE THE DATA
	HRRM	P1,IPC.TX(T2)		;SAVE MESSAGE NAME IN BLOCK
	HLRM	P1,IPC.CD(T2)		;SAVE THE CODE IN BLOCK
	MOVEM	R,BASTBL(S)		;RESTORE R WITH RL.MES SET
	POPJ	P,			;RETURN

	;THE LINKED LIST CONTAINS THE MESSAGE PLUS A HEADER WORD
	;CONTAINING FLAGS IN LEFT AND ROUTINE ADDRESS IN RIGHT HALF

	;TABLE OF OPERATOR ACTION COMMANDS

	;THIS TABLE HAS ENTRIES OF TWO DIFFERENT TYPES
	;THOSE BEFORE OACCUR MUST BE DONE IN PROCESSES OWN CONTEXT
	;WHILE OTHERS CAN BE DONE IN BATCONS WITHOUT MESSING WITH
	;USER STACK OR FLAGS

OACTAB:	XWD	STOPJB,.OMPAU		;OPERATOR ACTION STOP
OACCNT:	XWD	CONTJB,.OMCON		;OPERATOR ACTION CONTINUE
	XWD	CANCJB,.OMCAN		;OPERATOR ACTION CANCEL
	XWD	REQUJB,.OMREQ		;OPERATOR ACTION REQUEUE
OACCUR:	XWD	EXAMIN,.OMSHC		;EXAMINE CONTROL FILE
	XWD	SENDJB,.OMSND		;SEND MESSAGE TO JOB
		OACNUM==.-OACTAB	;COUNT OF ENTRIES


ERROR:	$STOP(IMQ,INVALID MESSAGE FROM QUASAR)


	;MESSAGE NAMES TO CORRESPOND WITH OACTAB

OACMSG:	%STOPD,,[ASCIZ/Stopped/]		;STOP MESSAGE
	%RESET,,[ASCIZ/Continued/]		;CONTINUE MESSAGE
	%CNCLG,,[ASCIZ/Aborted/]		;ABORT MESSAGE
	%REQUE,,[ASCIZ/Requeued/]		;REQUEUE MESSAGE
	0,,[ASCIZ/Show-Control-File/]		;EXAMIN MESSAGE
	0,,[ASCIZ/Send/]			;SENDJB MESSAGE
	SUBTTL	SETUPJ--ROUTINE TO PROCESS SETUP MESSAGE

SETUPJ:	MOVE	T3,SUP.TY(G)		;GET OBJECT TYPE
	CAIE	T3,.OTBAT		;IS IT FOR BATCH
	PUSHJ	P,ERROR			;NOT A BATCH JOB,,STOPCODE
	LOAD	S1,SUP.UN(G),RO.UNI	;GET STREAM NUMBER
	MOVE	S,S1			;SAVE STREAM IN S
	PUSHJ 	P,FSTREA		;FIND THE STREAM IN S1
	JUMPT	SHUTDN			;YES...CHECK IF SHUTDOWN
	SETOM	S1			;-1,,IS A FREE STREAM
	PUSHJ	P,FSTREA		;SEE IF CAN FIND ONE
	SKIPT				;YES...FOUND FREE STREAM
	PJRST	SETE.1			;NO FREE STREAMS
	MOVEM	S,STREAM(S1)		;SAVE STREAM NUMBER IN TABLE
	MOVE	S,S1			;RELATIVE INDEX IN S
	MOVEI	S1,.JPAGS		;NUMBER OF PAGES NEEDED FOR THE DATA BASE
	$CALL	M%AQNP			;GET A PAGE FOR THE DATA BASE
	MOVEI	R,(S1)			;PUT THE PAGE NUMBER IN R
	PG2ADR	R			;CONVERT PAGE TO ADDRESS
	HRRZM	R,BASTBL(S)		;SAVE FOR THE DISPATCHER
	MOVSI	S1,SUP.TY(G)		;BATCH OBJECT TYPE
	HRRI	S1,.JQTYP(R)		;PLACE IN DATA BASE
	BLT	S1,.JQNOD(R)		;MOVE THE BLOCK
	MOVX	T1,%RSUOK		;GOOD RETURN FOR SETUP
	MOVEI	T2,E.STAR		;SETUP STARTED MESSAGE
	SETZM	T3			;CLEAR CODE VALUE
SETUPR:	MOVEI	S1,RSU.SZ		;GET THE MESSAGE SIZE
	PUSHJ	P,MSGQSR		;SETUP THE MESSAGE TO QUASAR
	MOVEM	T3,RSU.CD(S2)		;SAVE THE CODE
	MOVEM	T1,RSU.CO(S2)		;STORE IN MESSAGE
	MOVE	S1,[RSU.SZ,,.QORSU]		;GET HEADER WORD
	MOVEM	S1,.MSTYP(S2)		;STORE IN MESSAGE
	MOVSI	S1,.JQTYP(R)		;GET SOURCE TYPE FROM STREAM
	HRRI	S1,RSU.TY(S2)		;DESTINATION,,RESPONSE TYPE
	BLT	S1,RSU.NO(S2)		;MOVE TYPE,UNIT,NUMBER
	CAIN	T2,E.STAR		;WAS IT A START MESSAGE
	JRST	SETU.1			;NO SETUP ERROR
	$WTO	(<Setup Error>,<^I/JIBTXT/^I/@ERRTAB(T2)/>,RSU.TY(S2))
	PUSHJ	P,SHUT.1		;CLEAN UP STREAM
	SKIPA				;SKIP OVER SETUP O.K.
SETU.1:	$WTO	(<^I/@ERRTAB(T2)/>,,RSU.TY(S2))
	PJRST	SNDQSR			;SEND IT TO QUASAR AND RETURN


SETE.1:	MOVX	T1,%RSUDE		;CAN NOT SETUP,,DO NOT TRY AGAIN
	MOVEI	T2,E.NSTR		;NO FREE STREAMS
	SETZM	T3			;CLEAR STATUS CODE AC
	PJRST	SETUPR			;SEND REPLY
SETE.3:	MOVX	T1,%RSUNA		;NOT SETUP..TRY AGAIN
	MOVEI	T2,E.STRA		;STREAM ALREADY ACTIVE
	SETZM	T3			;CLEAR STATUS CODE AC
	PJRST	SETUPR			;SEND SETUP REPLY

	;SHUTDOWN MESSAGE
SHUTDN:	MOVE	S,S1			;PLACE RELATIVE INDEX IN S
	MOVE	S2,SUP.FL(G)		;GET FLAG WORDS
	TXNN	S2,<SUFSHT>		;IS IT A SHUTDOWN MESSAGE
	PJRST	SETE.3			;STREAM ALREAY ACTIVE..SETUP ERROR
SHUT.1:	SETOM	STREAM(S)		;MARK STREAM AVAILABLE
	MOVE	S2,BASTBL(S)		;GET BASTBL ADDRESS
	SETZM	BASTBL(S)		;CLEAR STREAM ENTRY
	ADR2PG	S2			;CONVERT TO PAGE NUMBER
	MOVEI	S1,.JPAGS		;NUMBER TO RELEASE
	PJRST	M%RLNP			;RELEASE IT AND RETURN
	;FIND A STREAM ROUTINE
	;CALLED WITH S1 STREAM TO LOCATE  ....-1...FREE STREAM

FSTREA:	MOVSI	S2,-DEFMJB		;GET MAX NUMBER OF JOBS
FSTR.1:	MOVE	T1,STREAM(S2)		;GET FIRST STREAM VALUE
	CAMN	T1,S1			;CHECK IF MATCH
	JRST	FSTR.2			;YES ,,,MATCH
	AOBJN	S2,FSTR.1		;TRY NEXT ENTRY
	$RETF				;CAN'T FIND ENTRY
FSTR.2:	HRRZ	S1,S2			;RELATIVE STREAM INDEX
	$RETT				;RETURN TRUE
	SUBTTL	ABORTJ--ABORT JOB BY USER REQUEST

ABORTJ:	MOVE	T3,ABO.TY(G)		;GET MESSAGE TYPE
	CAIE	T3,.OTBAT		;IS IT BATCH
	PUSHJ	P,ERROR			;FATAL ERROR..EXIT
	LOAD	S1,ABO.UN(G),RO.UNI	;GET UNIT NUMBER
	PUSHJ	P,FSTREA		;FIND THE STREAM
	JUMPF	.POPJ			;CAN'T FIND...IGNORE***
	MOVE	S,S1			;PLACE RELATIVE INDEX IN S
	SKIPL	R,BASTBL(S)		;GET PROCESS POINTER ADDRESS
	POPJ	P,			;NO...IGNORE IT
	MOVE	S1,ABO.IT(G)		;GET ITN OF JOB
	CAME	S1,.JQITN(R)		;IS IT SAME JOB
	POPJ	P,			;NO,,IGNORE IT
	PUSHJ	P,MESLST		;SET UP MESSAGE LIST AND POSITION
	LOAD	S2,.MSTYP(G),MS.CNT	;GET SIZE OF MESSAGE
	ADDI	S2,IPC.DA		;ONE MORE WORD FOR FLAGS,,ADDR
	MOVE	S1,.JMLST(R)		;LIST ADDRESS IN S1
	;MEMORY OPTIMIZATION BY USING MINIMUM SIZE BLOCK
	CAIGE	S2,ALCSIZ-3		;GREATER OR EQUAL TO MINIMUM SIZE
	MOVEI	S2,ALCSIZ-3		;ALLOW FOR LIB OVERHEAD
	$CALL	L%CENT		;CREATE AN ENTRY
	MOVE	T2,S2			;PLACE ADDRESS IN T2
	MOVEI	S1,CANUSR		;CANCEL USER ROUTINE
	MOVEM	S1,IPC.RT(T2)		;STORE IN LIST 
	MOVSI	S2,B.DEFR		;DEFER FOR PROCESS
	IORM	S2,IPC.RT(T2)		;PLACE IN ENTRY WORD
	SETOM	.MSCOD(G)		;MARK CODE AS SPECIAL
	HRRI	S1,IPC.DA(T2)		;MESSAGE LIST AREA
	HRLI	S1,.MSTYP(G)		;SOURCE OF MESSAGE
	LOAD	S2,.MSTYP(G),MS.CNT	;GET LENGTH OF MESSAGE
	ADDI	S2,IPC.DA(T2)		;ENDING ADDRESS OF MESSAGE
	BLT	S1,-1(S2)		;MOVE THE DATA
	MOVEI	S1,ABORTX		;ABORT TEXT STRING
	MOVEM	S1,IPC.TX(T2)		;SAVE IN MESSAGE
	MOVX	S1,%CNCLG		;CANCELING CODE
	MOVEM	S1,IPC.CD(T2)		;SAVE THE CODE
	MOVEM	R,BASTBL(S)		;RESTORE R
	POPJ	P,			;RETURN

MESLST:	TLOE	R,RL.MES		;IS MESSAGE LIST SETUP
	JRST	MESL.1			;YES..JUST POSITION
	$CALL	L%CLST			;CREATE A LINKED LIST
	MOVEM	S1,.JMLST(R)		;SAVE LIST NUMBER
MESL.1:	MOVE	S1,.JMLST(R)		;GET LIST NUMBER
	$CALL	L%LAST			;POSITION TO THE END
	AOS	.JMESC(R)		;BUMP MESSAGE COUNT
	POPJ	P,			;RETURN

ABORTX:	ASCIZ/Canusr/			;CANCEL BY USER
	SUBTTL	WTORMS--RESPONSE TO WTOR MESSAGE

WTORMS:	MOVE	S1,.MSCOD(G)		;GET MESSAGE CODE..ITN
	PUSHJ	P,FNDITN		;LOCATE THE STREAM
	JUMPF	.POPJ			;CAN'T FIND..RETURN
	TLZN	R,RL.OPR!RL.DIA		;CLEAR BOTH BITS IF ON
	POPJ	P,			;NOT ON...EXIT
	MOVEI	T3,.OHDRS(G)		;START OF MESSAGE BLOCKS
	LOAD	S1,ARG.HD(T3),AR.TYP	;GET THE BLOCK TYPE
	CAIE	S1,.CMTXT		;BETTER BE TEXT
	POPJ	P,			;NO..IGNORE MESSAGE ***
	LOAD	S1,ARG.HD(T3),AR.LEN	;GET THE SIZE OF THE BLOCK
	MOVE	T2,S1			;SAVE THE LENGTH
	CAIGE	S1,ALCSIZ		;GREATER THAN OR = TO MINIMUM SIZE
	MOVEI	S1,ALCSIZ		;USE MEMORY SIZE
	$CALL	M%GMEM			;GET SOME MEMORY
	DMOVEM	S1,.JOPER(R)		;SAVE S1 AND S2 IN DATA BASE
	HRLZI	T1,ARG.DA(T3)		;START OF THE TEXT
	HRRI	T1,(S2)			;DESTINATION
	ADD	T2,S2			;GET LENGTH OF BLOCK
	BLT	T1,-1(T2)		;MOVE THE DATA
	MOVEM	R,BASTBL(S)		;RESTORE R
	POPJ	P,			;RETURN




	SUBTTL	FNDITN	--	FIND STREAM BY ITN

;THIS ROUTINE WILL LOCATE THE STREAM AND SETUP S AND R 
;
;CALLED WITH S1/ ITN
;
FNDITN:	MOVSI	S2,-DEFMJB		;MAXIMUM NUMBER OF JOBS
FNDI.1:	SKIPL	R,BASTBL(S2)		;STREAM SETUP
	JRST	FNDI.2			;NO..GO TO NEXT
	CAMN	S1,.JQITN(R)		;CHECK THE ITN
	JRST	FNDI.3			;MATCH..SETUP S AND RETURN
FNDI.2:	AOBJN	S2,FNDI.1		;NO..CHECK NEXT ONE
	$RETF				;COULDN'T FIND..RETURN FALSE
FNDI.3:	HRRZ	S,S2			;GET THE RELATIVE STREAM NUMBER
	$RETT				;RETURN TRUE
	SUBTTL	PROMES--PROCESS ACTION MESSAGE FROM USER OR OPERATOR

PROMES:	TLNE	R,RL.MIP		;MESSAGE IN PROGRESS
	$RETF				;YES,,GIVE FALSE RETURN
	MOVE	S1,.JMLST(R)		;GET LIST NAME
	$CALL	L%FIRS			;POSITION TO FIRST
	JUMPF	.POPJ			;RETURN WHEN DONE
	MOVE	T2,S2			;SAVE MESSAGE ADDRESS
	MOVE	F,.JREGS+F(R)		;LOAD UP F
	MOVE	S1,IPC.RT(S2)		;CHECK IF SET
	TLNE	R,RL.KJB		;LOGGING IN OR OUT
	$RETF				;GIVE FALSE RETURN..TO WAIT
	TLNN	R,RL.LGI		;WAS JOB LOGGING IN
	JRST	PROM.1			;NO..PROCESS A MESSAGE
	TRNN	F,FR.JLI		;WAS JOB SETTING UP FOR LOGIN
	$RETF				;NO..RETURN FALSE TO WAIT
PROM.1:	TLNE	S1,B.STCN		;STOP OR CONTINUE??
	JRST	PROM.4			;YES..DO NOT CLEAR FLAGS
	TLNE	S1,B.DEFR		;CHECK IF DEFER FOR PROCESS
	JRST	PROM.3			;SET UP FOR PROCESS
	PUSHJ	P,@IPC.RT(S2)		;EXECUTE THE ROUTINE
	MOVEM	F,.JREGS+F(R)		;RESTORE F
PROM.2:	MOVE	S1,.JMLST(R)		;GET LIST NAME
	$CALL	L%DENT			;DESTROY THE ENTRY
	SOSLE	.JMESC(R)		;DECREMENT COUNT
	JRST	PROMES			;MORE TO PROCESS
	POPJ	P,			;ALL DONE

PROM.3:	TLZ	R,RL.OPR!RL.STP!RL.JIE!RL.DIA	;CLEAR R FLAGS
	TLZ	F,FL.NER!FL.PLS!FL.SIL	;CLEAR F FLAGS
PROM.4:	TLO	R,RL.MIP!RL.MSP		;MESSAGE IN PROGRESS..PROCESS WHEN RETURN
	MOVEM	F,.JREGS+F(R)		;RESTORE FLAG AC
	MOVEM	R,BASTBL(S)		;RESTORE DATA BASE AC
	MOVE	S1,.JREGS+14(R)		;GET PROCESS STACK AC
	PUSH	S1,IPC.RT(S2)		;PLACE ROUTINE ADDR ON STACK
	MOVEM	S1,.JREGS+14(R)		;SAVE STACK FOR PROCESS
	MOVE	S1,.JMLST(R)		;GET LIST NAME
	$CALL	L%RENT			;REMEMBER ENTRY
	SOS	.JMESC(R)		;DECREMENT COUNT
	$RETF				;FALSE RETURN SO WANT TRY NOW
	SUBTTL	SENDJB	--	SEND TEXT TO JOB

	;CALL	T2/  MESSAGE BLOCK ADDRESS

SENDJB:	PUSHJ	P,IDNOPR		;SETUP OPR LINE IN LOG
	MOVE	P1,IPC.AR(T2)		;GET LAST ARGUMENT
	LOAD	S1,ARG.HD(P1),AR.TYP	;GET THE ARGUMENT TYPE
	CAIE	S1,.CMTXT		;BETTER BE TEXT
	JRST	SEND.1			;NO..SEND ERROR ACK
	$TEXT	(SENDJ1,<^T/ARG.DA(P1)/>)	;OUTPUT THE TEXT
	$ACK	(<Send Completed>,,<.JQOBJ(R)>,IPC.DA+.MSCOD(T2))
	PJRST	L$BLK1##		;SEND BLANK CR,LF..NO TIME STAMP
SEND.1:	$ACK	(<Invalid Send Message>,,<.JQOBJ(R)>,IPC.DA+.MSCOD(T2))
	POPJ	P,			;RETURN


SENDJ1:	PUSHJ	P,L$OUT1##		;OUTPUT THE CHARACTER
	CAIE	CH,CHR.LF		;HIT A LINE FEED
	$RETT				;NO..RETURN
	PUSHJ	P,L$2TAB##		;SEND TWO TABS
	MOVEI	S1," "			;GET A BLANK
	PUSHJ	P,L$OUT1##		;DUMP IT OUT
	MOVEI	S1," "			;GET A BLANK
	PUSHJ	P,L$OUT1##		;DUMP IT OUT
	$RETT				;RETURN
	SUBTTL	EXAMIN	--	SHOW CONTROL FILE TO OPERATOR

	;CALL	T2/	MESSAGE BLOCK ADDRESS

EXAMIN:	$CALL	M%GPAG			;GET A PAGE
	MOVE	P1,S1			;SAVE THE PAGE ADDRESS
	MOVEI	S1,<PAGSIZ-^D30>*5	;GET MESSAGE SPACE LEAVING ROOM FOR $ACK
	MOVEM	S1,WTOCNT		;SAVE THE COUNT
	HRRI	S1,(P1)			;POINT TO THE PAGE
	HRLI	S1,(POINT 7,)		;MAKE BYTE POINTER
	MOVEM	S1,WTOPTR		;SAVE THE POINTER
	TRNN	F,FR.CTO		;IS CTL FILE OPEN
	JRST	EXAME1			;NO,,EXIT WITH ERROR
	MOVE	T1,IPC.AR(T2)		;GET FIRST ARGUMENT
	LOAD	S1,ARG.HD(T1),AR.TYP	;GET ARGUMENT TYPE
	CAIE	S1,.SHCLN		;CHECK IF LINES FIELD
	JRST	EXAME4			;INVALID EXAMIN COMMAND
	LOAD	P2,ARG.DA(T1)		;GET THE VALUE
	PUSHJ	P,SAVPOS		;SAVE POSITION OF CTL
EXAM.1:	MOVE	S1,.JCJFN(R)		;GET CTL IFN
	$CALL	F%IBYT			;GET A BYTE
	JUMPF	EXAME2			;EXIT EXAMIN ERROR
	JUMPE	S2,EXAM.1		;SKIP NULLS
	MOVE	S1,S2			;PLACE NUMBER IN S1
	PUSHJ	P,WTODAT		;OUTPUT BYTE TO MESSAGE
	JUMPF	EXAME3			;ERROR ..TERMINATES MESSAGE
	CAIG	S2,CHR.FF		;CHECK IF GREATER THAN FF
	CAIGE	S2,CHR.LF		;CHECK IF LINE FEED
	JRST	EXAM.1			;NO GET NEXT CHARACTER
	SOJG	P2,EXAM.1		;WANT MORE...GO TO EXAM.1
EXAM.2:	PUSHJ	P,EXAMAC		;SEND AC AND MESSAGE TO ORION
EXAM.3:	PJRST	REPOSI			;REPOSITION THE CONTROL FILE

EXAME1:	$TEXT	(WTODAT,<Control File ^F/.JQCFD(R)/ not Open .. Show Ignored^A>)
	PJRST	EXAMAC			;SEND AC TO ORION
EXAME2:	$TEXT	(WTODAT,<^T/CRLF/	*** END OF DATA ***^A>)
	JRST	EXAM.2			;FINISH OUT EXAMIN COMMAND
EXAME3:	MOVEI	S1,^D15*5		;GET EXTRA ROOM
	MOVEM	S1,WTOCNT		;SAVE THE COUNT
	$TEXT	(WTODAT,<		*** End of Show Data Page ***^A>)
	JRST	EXAM.2			;SEND AND REPOSITION
EXAME4:	$TEXT	(WTODAT,<Invalid Show Control-File Command .. Command Ignored>)
	JRST	EXAM.2			;FINISH OFF THE COMMAND

EXAMAC:	$ACK(<^T/@IPC.TX(T2)/>,<^I/JIBTXT/^T/(P1)/>,.JQOBJ(R),IPC.DA+.MSCOD(T2),<$WTJBN(.JJOBN(R))>)
	MOVE	S1,P1			;GET THE PAGE
	PJRST	M%RPAG			;RELEASE THE PAGE AND RETURN

WTODAT:	SOSG	WTOCNT			;DECREMENT COUNT
	$RETF				;ABORT AND RETURN
	IDPB	S1,WTOPTR		;DEPOSIT BYTE
	$RETT				;RETURN
	SUBTTL	CLRSTR	--	CLEAN UP STREAM WHEN INACTIVE

CLRSTR:	MOVE	S1,[IOWD TPSIZE,TOPPDL] ;GET TOP LEVEL PDL FIRST
	PUSH	S1,(P)		;PLACE RETURN ADDRESS ON STACK
	MOVE	P,S1		;GET NEW STACK POINTER
	SOS	STACTV		;DECREMENT THE STREAM COUNT
	CAMN	S,HIACTV	;WAS STREAM TO GO IDLE THE HIGHEST ACTIVE
	  PUSHJ	P,FHIACT	;YES, FIND NEW HIACTV
	PUSHJ	P,RELREL	;RELEASE IT AND THE ASSIGNMENT
IFN FTJSYS,<
	MOVE	S1,.JPLSO(R)	;PTYS OUTPUT LINKED LIST
	$CALL	L%DLST		;DESTROY THE LIST
>  ;END OF IFN FTJSYS
	SKIPE	S1,.JLPAG(R)	;PAGE FOR LOG FILE GONE
	$CALL	M%RPAG		;NO..RELEASE THE PAGE
	SKIPN	.JWTOF(R)	;WTO MESSAGE SETUP
	JRST	CLRS.1		;NO...EVERYTHING O.K.
	MOVE	S1,.JWADR(R)	;GET MESSAGE PAGE ADDRESS
	$CALL	M%RPAG		;RELEASE THE PAGE
CLRS.1:	SKIPN	S1,.JOPER(R)	;ANY MESSAGES LEFT
	JRST	CLRS.2		;NO..BYPASS
	MOVE	S2,.JOPER+1(R)	;GET MESSAGE SIZE AND ADDRESS
	PUSHJ	P,M%RMEM	;RELEASE THE MEMORY
CLRS.2:	TLNN	R,RL.MES	;MESSAGE LIST BUILT??
	JRST	CLRDAT		;NO,,SKIP DESTROYING LIST
CLRS.3:	MOVE	S1,.JMLST(R)	;GET LIST NUMBER
	$CALL	L%FIRS		;GET FIRST ENTRY IN QUEUE
	JUMPF	CLRS.4		;DESTROY THE LIST
	MOVE	T2,S2		;PUT ADDRESS IN T2
	MOVEI	S1,E.JLOG	;JOB LOGGED OUT
	MOVEM	S1,.JERRO(R)	;SAVE MESSAGE ERROR
	TLO	F,FL.ERR	;SEND ERROR MESSAGE
	PUSHJ	P,MSGOUT	;SEND THE MESSAGE
	MOVE	S1,.JMLST(R)	;GET LIST NAME
	$CALL	L%DENT		;DELETE THE ENTRY
	JRST	CLRS.3		;CHECK FOR MORE
CLRS.4:	MOVE	S1,.JMLST(R)	;GET LIST NUMBER
	$CALL	L%DLST		;DESTROY THE LIST
CLRDAT:	MOVE	S1,.JOBST(R)	;GET THE COUNT OF JOBSTS
	ADDM	S1,JOBSCT	;ADD TO TOTAL FOR ALL JOBS
	TLZ	R,777777	;CLEAR INITIAL SETTINGS
	MOVEM	R,BASTBL(S)	;UPDATE R
	POPJ	P,		;RETURN
	SUBTTL	FHIACT	--	FIND NEW HIACTV STREAM..INACTIVE WAS OLD HIACTV

FHIACT:	PUSH	P,S		;SAVE CURRENT STREAM
	SKIPL	BASTBL(S)	;IS THIS STREAM ACTIVE
	  SOJG	S,.-1		;NO, LOOK FOR ONE BELOW
	MOVEM	S,HIACTV	;FOUND 1 OR NONE BUT IS OK
	POP	P,S
	POPJ	P,

;SUBROUTINE TO WAKE ME UP FOR VARIOUS REASONS

IFN FTUUOS,<
WAKEME:	MOVNI	T1,1		;JOB -1 IS ME
	WAKE	T1,		;ISSUE THE WAKE
	  JFCL			;REALLY CAN'T FAIL
	POPJ	P,
>  ;END IFN FTUUOS

IFN FTJSYS,<
WAKEME:	POPJ	P,		;JUST RETURN
>  ;END OF IFN FTJSYS
	SUBTTL	NEXTJB--PROCESS NEXTJOB MESSAGE

NEXTJB:	MOVE	T3,.EQROB+.ROBTY(G)	;GET OBJECT TYPE
	CAIE	T3,.OTBAT		;IS IT BATCH
	PUSHJ	P,ERROR			;INVALID TYPE..STOPCODE
	LOAD	S1,.EQROB+.ROBAT(G),RO.UNI ;GET UNIT NUMBER
	PUSHJ	P,FSTREA		;FIND STREAM IN S1
	JUMPF	ERROR			;COULD NOT FIND STREAM,,STOPCODE

	MOVE	S,S1			;RELATIVE INDEX FOR STREAM
	SKIPL	R,BASTBL(S1)		;GET STREAM ENTRY
	PJRST	FIREUP			;NO..O.K.,,,FIREUP JOB AND RETURN
	PJRST	SETE.3			;YES,,,ERROR


	SUBTTL	FIREUP--FIREUP A JOB FOR PROCESSING
;SUBROUTINE TO START UP A NEW JOB ( EXTRACT VARIABLES, SET RUNABLE)

FIREUP:	MOVEI	S1,.JSIZE		;GET THE SIZE OF THE DATA BASE
	MOVE	S2,R			;GET THE ADDRESS
	MOVSI	T4,.JQTYP(R)		;GET THE OBJECT BLOCK
	HRRI	T4,T1			;INTO T1 - T3
	BLT	T4,T3			;MOVE THE DATA
	$CALL	.ZCHNK			;ZERO THE DATA PAGES
	MOVSI	T4,T1			;GET THE DATA
	HRRI	T4,.JQTYP(R)		;MOVE DATA INTO PAGE
	BLT	T4,.JQNOD(R)		;RESTORE THE DATA

	;NOW SETUP THE INCORE DATA BASE FROM NEXTJB
	;CODE FOR MOVING THE EQ


	MOVE	S1,.EQITN(G)		;GET THE ITN FOR THE JOB
	MOVEM	S1,.JQITN(R)		;PLACE IN DATA BASE
	HRLI	S1,.EQJBB(G)		;START OF JOB INFO BLOCK
	HRRI	S1,.JQJBB(R)		;END OF JOB INFO BLOCK
	BLT	S1,.JQJBB+JIBSIZ-1(R)	;MOVE THE BLOCK
	HRLI	S1,.EQLIM(G)		;GET START OF LIMIT WORDS
	HRRI	S1,.JQLIM(R)		;GET DESTINATION OF LIMIT WORDS
	BLT	S1,.JQLIM+EQLMSZ-1(R)	;MOVE THE LIMIT WORDS
	GETLIM	S1,.JQLIM(R),ONOD	;GET THE OUTPUT/LOCATION NODE
	MOVEM	S1,.JQLOC(R)		;SAVE AS THE LOCATION

	HRLI	S1,.EQCHK(G)		;GET ADDRESS OF CHECKPOINT WORDS
	HRRI	S1,.JINFO(R)		;GET DESTINATION FOR WORDS
	BLT	S1,.JINFO+EQCKSZ-1(R)	;SAVE THEM IN DATA BASE

	HRLI	S1,.EQACT(G)		;GET ADDRESS OF ACCOUNT STRING
	HRRI	S1,.JQACT(R)		;GET DESTINATION FOR STRING
	BLT	S1,.JQACT+10-1(R)	;SAVE ACCOUNT STRING
	LOAD	T2,.EQLEN(G),EQ.LOH	;GET LENGTH OF THE REQUEST HEADER

IFN	FTJSYS,<
	MOVE	S1,.EQSIS(G)		;GET SPRINT SPOOL WORD
	MOVEM	S1,.JQSIS(R)		;SAVE WORD
	HRLI	S1,.EQOWN(G)		;GET USER NAME
	HRRI	S1,.JQNAM(R)		;DESTINATION FOR USER NAME
	BLT	S1,.JQNAM+10-1(R)	;MOVE THE NAME

	HRLI	S1,.EQCON(G)		;GET CONNECTED DIRECTORY
	HRRI	S1,.JQCON(R)		;DESTINATION FOR CONN. DIR
	BLT	S1,.JQCON+12-1(R)	;SAVE CONNECTED DIRECTORY

	MOVE	S1,.EQSIS(G)		;GET SPOOL INFO WORD
	MOVEM	S1,.JQSIS(R)		;SAVE WORD FOR SPOOLED FILES
>;	END	FTJSYS

IFN FTUUOS,<	;THE PATH IS OPTIONAL ON TOPS10, CHECK FOR IT
	MOVE	S1,.EQOID(G)		;GET PPN INFO
	MOVEM	S1,.JQPPN(R)		;SAVE PPN
	CAIGE	T2,.EQPSZ		;ENOUGH ROOM FOR THE PATH SPEC
	  JRST	FIRE.0			;NO, DON'T BOTHER COPYING IT
	HRLI	S1,.EQPAT(G)		;WHERE IT IS IF PRESENT
	HRRI	S1,.JQPAT(R)		;INTO INTERNAL BLOCK
	BLT	S1,.JQPAT+5(R)		;MOVE IT ALL
>  ;END OF IFN FTUUOS

FIRE.0:	ADDI	T2,(G)			;FIND FILE PARAMETERS FOR THE CTL FILE
	DMOVE	S1,.FPINF(T2)
	DMOVEM	S1,.JQCFP(R)		;SAVE THE PARAMETERS AND STARTING POINT
	LOAD	T3,.FPLEN(T2),FP.LEN	;FIND THE FILE DESCRIPTOR
	ADDI	T3,(T2)			;AS MESSAGE+LENGTH OF HEADER+LENGTH OF PARMS
	LOAD	T4,.FDLEN(T3),FD.LEN	;SIZE OF THE DESCRIPTOR
	ADDI	T4,.JQCFD-1(R)		;END OF THE BLT
	HRLI	T1,0(T3)			;THE CTL FILE STRUCTURE
	HRRI	T1,.JQCFD(R)		;WHERE FNDCTL WANTS IT
	BLT	T1,0(T4)			;COPY ALL AND SFD'S IF THERE
	LOAD	T4,.FDLEN(T3),FD.LEN	;GET FD SIZE AGAIN
	ADDI	T3,(T4)			;C = LOG FILE PARAMETERS
	MOVE	S1,.FPINF(T3)		;GET INFO WORD
	MOVEM	S1,.JQLFP(R)		;AS THE LOG FILE MOD WORD
	LOAD	T4,.FPLEN(T3),FP.LEN	;SIZE OF LOG FILE PARM HEADER
	ADDI	T4,(T3)			;POINT TO LOG FILE DESCRIPTOR
	LOAD	T3,.FDLEN(T4),FD.LEN	;SIZE OF LOG FILE FD
	ADDI	T3,.JQLFD-1(R)		;LAST LOCATION TO MOVE TO
	HRLI	T1,0(T4)			;THE LOG FILE NOW
	HRRI	T1,.JQLFD(R)		;WHERE THE ROUTINES WANT IT
	BLT	T1,0(T3)			;MOVE THE FULL SPEC
	HRLI	S1,.EQCHK(G)		;CHECKPOINT/REQUEUE INFORMATION
	HRRI	S1,.JINFO(R)		;KEEP IT IN THE JOB DATA BASE
	BLT	S1,.JINFO+<EQCKSZ-1>(R)	;GET ALL THE WORDS
	HRLI	R,RL.INI		;SET THIS STREAM IS NOW ACTIVE
	MOVEM	R,BASTBL(S)		;STORE NEW SETTING
	MOVE	F,[FL.INI,,FR.INI]	;INITIALIZE THE OTHER FLAG REG
	MOVEM	F,.JREGS+F(R)		;STORE NEW SETTINGS
	SETOM	.JJOBN(R)		;INIT THE JOB NUMBER FIELD
					;IN CASE CAN NOT LOG IN
	SUBTTL	TOPS10 PTY STARTUP CODE

IFN FTUUOS,<
FIRE.1:	MOVE	S1,S		;USE THE RELATIVE STREAM NUMBER FOR THE CHANNEL
	LSH	S1,^D23		;SHIFT TO CHANNEL FIELD
	MOVEM	S1,.JPCHN(R)	;SAVE CHANNEL NUMBER
	MOVSI	T1,(1B0!1B2)	;WANT ASCII MODE ON A REAL PTY
	MOVSI	T2,'PTY'	;GET GENERIC PTY
	HRLI	T3,.JPOUT(R)	;XWD OUTPUT,INPUT
	HRRI	T3,.JPINP(R)
	MOVE	S1,[OPEN 0,T1]	;OPEN THE PTY
	IOR	S1,.JPCHN(R)	;PUT IN CHANNEL NUMBER
	XCT	S1		;EXECUTE THE OPEN
	  JRST	FIRE.N		;OPEN FAILURE,,RELEASE PTY,,EXIT
	MOVSI	T1,400000	;NOT IN USE BIT
	HRRI	T1,.JPTYO+1(R)	;FIRST IN RING
	MOVEM	T1,.JPOUT(R)	;SET FOR BUFFERED OUTPUT
	HRRI	T1,.JPTYI+1(R)	;SAVE FOR INPUT SIDE
	MOVEM	T1,.JPINP(R)
	MOVSI	T1,(POINT 7,0)	;BYTE SIZES
	MOVEM	T1,.JPINP+1(R)
	HRRI	T1,.JPTYO+3(R)	;COUNTS ARE ZERO FROM ABOVE BLT
	MOVEM	T1,.JPOUT+1(R)	;FOR INPUT AND OUTPUT
	MOVSI	T1,PTYBLK-2	;PLACE SIZE-2 IN THE LEFT HALF

	IFE	<PTYBFR-1>,<	;ONLY 1 BUFFER EACH WAY
	HRRI	T1,.JPTYO+1(R)	;RING LOOPS ON ITSELF
	MOVEM	T1,.JPTYO+1(R)
	HRRI	T1,.JPTYI+1(R)	;SAME FOR INPUT
	MOVEM	T1,.JPTYI+1(R)
	>
	IFG	<PTYBFR-1>,<	;MULTIPLE BUFFERS
	MOVEI	T2,PTYBFR-1	;LOOP COUNT
	HRRI	T1,.JPTYO+1+PTYBLK(R) ;POINT TO SECOND BUFFER
	JRST	.+2		;SKIP FOR THE FIRST BUFFER
	HRRI	T1,PTYBLK(T1)	;POINT TO NEXT BUFFER
	MOVEM	T1,-PTYBLK(T1)	;STORE ADDR INTO PREVIOUS BUFFER
	SOJG	T2,.-2		;DO FOR ALL BUFFERS
	HRRI	T1,.JPTYO+1(R)	;POINT BACK TO FIRST
	MOVEM	T1,.JPTYO+1+<<PTYBFR-1>*PTYBLK>(R) ;LAST LINKS TO FIRST
	MOVEI	T2,PTYBFR-1	;NOW DO THE SAME FOR INPUT SIDE
	HRRI	T1,.JPTYI+1+PTYBLK(R) ;AGAIN POINT TO SECOND BUFFER
	JRST	.+2		;SKIP FOR THE FIRST BUFFER
	HRRI	T1,PTYBLK(T1)	;BUMP TO NEXT
	MOVEM	T1,-PTYBLK(T1)	;STORE ADDRESS OF THIS IN PREVIOUS
	SOJG	T2,.-2		;REPEAT PROCESS FOR ALL BUFFERS
	HRRI	T1,.JPTYI+1(R)	;FIRST BUFFER
	MOVEM	T1,.JPTYI+1+<<PTYBFR-1>*PTYBLK>(R) ;LINK LAST TO FIRST
	>
>  ;END IFN FTUUOS
	SUBTTL	TOPS20 PTY SETUP CODE

IFN FTJSYS,<
FIRE.1:	MOVN	T2,NUMPTY		;GET # OF PTYS IN SYSTEM
	HRLZS	T2
FIRE.2:	MOVSI	S1,.DVDES+.DVPTY	;GET PTY DESIGNATOR
	HRRI	S1,(T2)			;TRY TO GET NEXT PTY
	DVCHR				;GET CHARACTERISTICS OF THIS PTY
	TXNN	S2,DV%AV		;IS IT AVAILABLE?
	  JRST FIRE.4			;NO,TRY NEXT PTY
	MOVE	S2,S1			;SET UP FOR DEVST
	HRROI	S1,DEVNAM		;TURN IT INTO AN ASCII STRING
	DEVST				;GET STRING FOR DEVICE
	  JRST FIRE.4			;ERROR TRY NEXT ONE
	MOVEI	S2,":"			;TERMINATED BY A COLON
	IDPB	S2,S1			;PUT COLON ON STRING
	MOVEI	S2,0			;PLACE NULL ON END
	IDPB	S2,S1			;ENDED WITH A 0 BYTE
	MOVX	S1,GJ%SHT		;SHORT FORM OF JFN
	HRROI	S2,DEVNAM		;NAME FOR OPEN
	GTJFN
	  JRST FIRE.4			;NOT AVAILABLE
	MOVE	S2,[7B5+OF%RD+OF%WR]	;NOW TRY TO OPEN IT
	MOVEM	S1,.JPCHN(R)		;PTY CHANNEL NUMBER
	OPENF
	  JRST FIRE.3			;NOT AVAILABLE
	ADD	T2,FIRPTY		;TURN PTY UNIT # INTO TTY #
	TRO	T2,400000		;MAKE IT A TTY DESIGNATOR
	HRRZM	T2,.JPTTY(R)		;STORE TTY DESIGNATOR
	PUSHJ	P,SETPTY		;SET HALF DUPLEX ON PTY
	MOVE	S1,.JPCHN(R)		;JFN FOR PTY
	HRL	S2,STRCHN(S)		;GET THE PTY CHANNEL
	TXO	S2,<MO%WFI+MO%OIR>	;WAIT FOR INPUT, OUTPUT READY
	HRRI	S2,.MOAPI		;ATTACH TO INTERRUPT SYSTEM
	MTOPR				;JSYS TO ATTACH PTY
	ERJMP	FIRE.N			;ERROR EXIT
	MOVEI	S2,.MOBAT		;SET BATCH FUNCTION
	MOVEI	T1,.MOJCB		;A = S2 + 1 , SET THE BATCH PTY BIT
	MTOPR				;AFFECTS JOBS LOGGING IN ON THIS PTY
	JRST	FIRE.5			;GOT A PTY
FIRE.3:	MOVE	S1,.JPCHN(R)		;JFN FOR PTY
	RLJFN				;RELEASE THE JFN
		JFCL			;GET NEXT
FIRE.4:	AOBJN	T2,FIRE.2		;TRY NEXT PTY
	JRST	FIRE.E			;ERROR..EXIT..CAN'T GET PTY
	SUBTTL	SET HALF DUPLEX FOR PTY
SETPTY:	MOVEI	S1,101			;REFER TO THE TERMINAL WE'RE ON.
	GTTYP				;ASK THE SYSTEM WHAT TYPE WE ARE.
	MOVE	S1,.JPTTY(R)		;REFERENCE THE PTY.
	STTYP				;SET THE PTY TYPE TO THE SAME AS OURSELF.
HLFDUP:	MOVE	S1,.JPTTY(R)		;GET THE JFN FOR PTY
	RFMOD				;READ THE CURRENT SETTINGS
	TRC	S2,3B33			;CHECK IF HALF DUPLEX SET
	TRCN	S2,3B33			;WAS IT SET?
	  POPJ P,			;YES...RETURN
	IORI	S2,3B33			;NO..TURN IT ON
	STPAR				;SET IT UP
	POPJ	P,			;RETURN
FIRE.5:	$CALL	L%CLST			;CREATE LIST FOR PTY OUT
	MOVEM	S1,.JPLSO(R)		;SAVE LIST NAME
	MOVEI	S1,PTYBLK*PTYBFR*5	;PTY BUFFER SIZE
	MOVEM	S1,.JPOUT+2(R)		;SAVE COUNT FOR OUTPUT TO PTY
	MOVE	S1,[POINT 7,.JPTYO(R)]	;BUFFER BYTE POINTER
	MOVEM	S1,.JPOUT+1(R)		;SAVE BUFFER POINTER
>  ;END OF IFN FTJSYS

	CAMLE	S,HIACTV		;IS THIS NOW THE HIGHEST ACTIVE STREAM
	  MOVEM	S,HIACTV		;YES, SET NEW VALUE
	HRLI	T1,-.JPSIZ		;BUILD PDL FOR THE STREAM
	HRRI	T1,.JPLST-1(R)
	PUSH	T1,[NEWJOB]		;START STREAM AT 'NEWJOB'
	MOVEM	T1,.JREGS+14(R)		;SAVE AS PROCESSOR REGISTER P (17)
	AOS	STACTV			;ADD ANOTHER JOB
	POPJ	P,			;RETURN TO DISPATCHER

; HERE WHEN WE CANNOT GET A PTY FOR A JOB, GIVE IT BACK TO QUASAR
;AT	FIRE.N	IF ALREADY ACQUIRED A PTY CHANNEL BUT NO THE PTY ITSELF
;	FIRE.E	IF COULDN'T GET A PTY CHANNEL (A BUG IN THE CHANNEL ALLOCATOR)

FIRE.N:	PUSHJ	P,RELREL		;RELEASE THE PTY ASSIGNMENT
FIRE.E:	PUSHJ	P,CLRDAT		;CLEAN UP DATA FROM STREAM
	MOVX	T1,%RSUNA		;NOT AVAILABLE,,TRY AGAIN SOON
	MOVEI	T2,E.NPTY		;NO PTYS AVAILABLE
	MOVX	T3,%NPTYS		;NO PTYS AVAILABLE CODE
	PJRST	SETUPR			;SEND SETUPR ..WITH NEGATIVE ACK
					;WHICH WILL FORCE JOB REQ BY QSR.
	SUBTTL	Job Processor - Start the Stream

;ENTRY AT NEWJOB FOR FRESH START. HEADERS,LOGIN,SET COMMANDS...

NEWJOB:	$WTOJ	(<Begin>,<^R/.JQJBB(R)/>,.JQOBJ(R),<$WTNOD(.JQLOC(R))>)
	PUSHJ	P,L$INIT##	;INITIALIZE LOG FILE DATA
	$TEXT	(L$OUT1,<			^H/[-1]/

BATCON Version	^V/[%%.BAT]/			GLXLIB Version	^V/[GLXVRS]/>)
	$TEXT	(L$OUT1,<
	    ^R/.JQJBB(R)/ in Stream ^D/STREAM(S)/
>)
	GETLIM	S2,.JQLIM(R),UNIQ		;[4125] GET UNIQUE VALUE
	MOVEI	P1,[ASCIZ/No/]			;ASSUME NO
	CAIE	S2,%EQUNO			;[4125] IS IT UNIQUE
	   MOVEI P1,[ASCIZ/Yes/] 		;YES, SAY SO
	MOVEI	P2,[ASCIZ/No/]			;ASSUME NOT RESTARTABLE
	GETLIM	S2,.JQLIM(R),REST		;GET RESTART FIELD
	SKIPN	S1,.JCHRQ(R)			;ANY CHECKPOINT INFO
	   SKIPA				;NO..CHECK VALUE NOW
	 TXNN	S1,<BA.ORQ!BA.URQ!BA.CHK>	;WAS IT REQ OR CHKPNT
	   CAIE	S2,%EQRNO			;CHECK IF RESTARTABLE
	   MOVEI P2,[ASCIZ/Yes/] 		;RESTARTABLE.. SAY YES
	MOVEI	T4,[ASCIZ/Log/]			;DEFAULT TO LOG
	GETLIM	S1,.JQLIM(R),OUTP		;GET OUPUT VALUE
	CAIN	S1,%EQOLE			;/OUT:ERROR
	  MOVEI	T4,[ASCIZ/Error/]  		;YES
	CAIN	S1,%EQONL			;/OUT:Nolog
	  MOVEI	T4,[ASCIZ/Nolog/]  		;YES
	HRRZ	T1,.JQLIM+1(R)			;GET TIME FIELD
	IDIVI	T1,^D3600			;CONVERT TO HOURS IN T1
	IDIVI	T2,^D60				;CONVERT TO MINUTES IN T2
	GETLIM	S1,.JQLIM(R),BLOG		;GET LOG OPTIONS FOR WRITING
	MOVEI	S2,[ASCIZ/Append/]		;DEFAULT IS APPEND
	CAIN	S1,%BAPND			;APPEND..
	JRST	NEWJ.1				;YES
	CAIN	S1,%BSCDE			;SUPERSEDE
	MOVEI	S2,[ASCIZ/Supersede/]		;SET TO SUPERSEDE
	CAIN	S1,%BSPOL			;OR CREATE IN SPOOL AREA
	MOVEI	S2,[ASCIZ/Spool /]		;SET SPOOL
NEWJ.1:	GETLIM	S1,.JQLIM(R),OINT		;OPERATOR INTERVENTION FIELD
	MOVEI	P4,[ASCIZ/Yes/]			;ALLOWED..DEFAULT
	CAIE	S1,.OPINY			;YES
	MOVEI	P4,[ASCIZ/No/]			;NOT ALLOWED
	$TEXT	(L$OUT1,<	OUTPUT:	 ^T/(T4)/^T/TABS/TIME-LIMIT: ^I/ITIME/
	UNIQUE:	 ^T/(P1)/^T/TABS/BATCH-LOG:  ^T/(S2)/>)
	$TEXT	(L$OUT1,<	RESTART: ^T/(P2)/^T/TABS/ASSISTANCE: ^T/(P4)/
						SEQUENCE:   ^D/.JQJBB+JIB.SQ(R),JB.SEQ/>)
	SKIPE	CORCHK				;WANT CORE CHECKING
	$TEXT	(L$OUT1,<				CORE:^D/.JQLIM+1(R),LHMASK/P>)
	$TEXT	(L$OUT1,<
	Input from =^7/[76]/ ^F/.JQCFD(R)/
	Output to  =^7/[76]/ ^F/.JQLFD(R)/

>)
	PUSHJ	P,LOGINJ			;LOGIN THE JOB
	PUSHJ	P,LOGSET			;SETUP JOB AFTER LOGIN
	PJRST	JOBSTA				;START JOB PROCESSING

TABS:	ASCIZ/				/	;4 TABS
	SUBTTL	LOGINJ	--	LOGIN A JOB ON PTY

IFN	FTUUOS,<
LOGINJ:	PUSHJ	P,SNDUPC		;SEND A ^C
	PUSHJ	P,IODISP		;WAIT FOR I/O, RETURN FOR MORE INPUT
	SKIPE	.JRTIM(R)		;TIMESTAMP NEEDED?
	PUSHJ	P,L$LPER##		;OUTPUT MONITOR PROMPT
	$TEXT	(LOGPTY,<LOGIN ^O/.JQPPN(R),LHMASK//^O/.JQPPN(R),RHMASK/^A>)
	MOVEI	T4,.JQPAT(R)		;GET THE LOGIN PATH
	SKIPN	.JQPAT(R)		;ANY PPN IN THE PATH SPEC
	  JRST	LOGI.3			;NO, AVOID SENDING BAD DATA
	PUSHJ	P,SETSFD		;SET AS IF AN SFD SPEC
	TLNE	T4,-1			;IS D A PPN
	  JRST	[CAMN T4,.JQPPN(R)  	;YES, ARE THE PPNS THE SAME
		  JRST LOGI.3		;YES, SKIP THIS OUTPUT
		MOVEI T4,SFDPAT-3  	;INSURE FINDING A ZERO
		JRST .+1]		;RESUME IN-LINE CODE
	MOVEM	T4,.JLABL(R)		;SAVE THE POINTER FOR NOW
	MOVEI	S1,"["			;[ FOR START OF PPN PATH BLOCK
	PUSHJ	P,LOGPTY		;OUTPUT THE CHARACTER
	MOVE	S1,.JQPAT(R)		;GET PATH PPN
	CAMN	S1,.JQPPN(R)		;SAME AS LOGGED IN PPN
	  JRST	[MOVEI S1,CHR.CA	;SEND A COMMA
		PUSHJ	P,LOGPTY	;SEND TO PTY AND LOG
		JRST LOGI.1]		;GO STRAIGHT TO PATH SPEC
	$TEXT	(LOGPTY,<^O/.JQPAT(R),LHMASK/,^O/.JQPAT(R),RHMASK/^A>)
LOGI.1:	AOS	S1,.JLABL(R)		;BUMP TO NEXT SFD LEVEL
	SKIPN	S1,2(S1)		;IS THERE ANOTHER
	  JRST	LOGI.2			;NO, END OF THE SPEC
	$TEXT	(LOGPTY,<,^W/S1/^A>)	;SEND SFD PATH
	JRST	LOGI.1			;CONTINUE FOR ALL LEVELS
LOGI.2:	MOVEI	S1,"]"			;END PATH BLOCK
	PUSHJ	P,LOGPTY		;OUPUT THE CHARACTER
LOGI.3:	$TEXT	(LOGPTY,< /DEFER/SPOOL:ALL/TIME:^D/.JQLIM+1(R),RHMASK//ACCOUNT:^T/.JQACT(R)//BATNAM:^W/.JQJBB+JIB.JN(R)//BATSEQ:^D/.JQJBB+JIB.SQ(R),JB.SEQ//REQID:^D/.JQJBB+JIB.ID(R)/^A>)
	SKIPE	CORCHK			;WANT CORE CHECKING?
	$TEXT	(LOGPTY,</CORE:^D/.JQLIM+1(R),LHMASK/P^A>)
	MOVX	S1,<B.REMT>		;HAVE REMOTE STATION LOGIC
	TDNN	S1,FLAGS		;CHECK AGAINST GLOBAL FLAG WORD
	  JRST	LOGI.4			;END THE LINE
	$TEXT	(LOGPTY,</LOCATE:^O/.JQLOC(R)/^A>)
LOGI.4:	$TEXT	(LOGPTY,</NAME:"^A>)
	$TEXT	(PTYSCN,<^W6/.JQJBB+JIB.NM(R)/^W/.JQJBB+JIB.NM+1(R)/^A>)
	MOVEI	S1,CHR.QT		;SEND QUOTE
	PUSHJ	P,LOGPTY		;OUTPUT CHARACTER
	POPJ	P,			;RETURN
>  ;END OF IFN FTUUOS

IFN FTJSYS,<
LOGINJ:	SETOM	.JREOL(R)		;FAKE OUT IN CASE OF PROBLEMS
	TRO	F,FR.JLI		;SET START OF JOB LOGGING IN
	PUSHJ	P,SNDUPC		;SEND A ^T
	PUSHJ	P,IODISP		;CONTEXT SWITCH AND WAIT FOR I/O
	TRZN	F,FR.JLI		;DID IT GET RESET FOR ERROR
	JRST	[ AOS	S1,.JLOGI(R)	;BUMP LOGIN TRIES
		CAILE	S1,FULLCT	;PAST FULL COUNT
		PJRST	ANLY.4 		;YES..REQUEUE THE JOB
		TLZ	R,RL.JIE	;CLEAR JOB IN ERROR
		PUSHJ	P,QTS		;STALL AND TRY AGAIN
		JRST	LOGINJ ]	;NO..TRY AGAIN
	PUSHJ	P,SETTIM		;SETUP TIME FOR JOB
	PUSHJ	P,SETLOC		;SETUP LOCATION
	SKIPE	.JRTIM(R)		;TIMESTAMP NEEDED?
	PUSHJ	P,L$LPER##		;OUTPUT MONITOR PROMPT
	TLNE	R,RL.JIE		;IS JOB IN ERROR NOW?
	   PUSHJ P,ANALYZ		;YES..ANALYZE THE ERROR
	$TEXT	(LOGPTY,<LOGIN ^T/.JQNAM(R)/^A>);SEND  USER NAME
	$TEXT	(PTYDAT,< FOO ^A>)	;ADD DUMMY PASSWORD FOR  PTY
	$TEXT	(LOGPTY,< ^T/.JQACT(R)/^A>);AND ACCT. STRING
	POPJ	P,			;RETURN
>  ;END OF IFN FTJSYS
	SUBTTL	LOGSET	--	SETUP JOB AFTER LOGIN


IFN	FTUUOS,<
LOGSET:	PUSHJ	P,SNDCLF		;FORCE OUT CR ,LF AND BUFFER
	PUSHJ	P,IODISP		;WAIT FOR OUTPUT 
	TLNE	J,JL.ULI		;IS USER LOGGED IN
	TLNE	R,RL.JIE		;DID LOGIN FAIL
	  PUSHJ	P,ANALYZ		;YES, ANALYZE THE LOGIN ERROR
	TRNE	F,FR.LFO		;IS LOG FILE OPEN
	  JRST LOGS.1			;BYPASS LOG OUTPUT
	PUSHJ	P,L$OUTP##		;DUMP THE DATA
	JUMPF	LOGEXT			;ERROR.. FINISH OFF THE JOB
LOGS.1:	MOVE	S1,[2,,S2]		;SETUP FOR JBSET.
	HRRZ	S2,J			;GET JOB NUMBER
	HRLI	T1,.STBSN		;FUNCTION TO SET BATCH STREAM
	HRR	T1,.JQSTR(R)		;SAVE THE STREAM NUMBER
	JBSET.	S1,			;DO THE JBSET.
	  JFCL				;IGNORE THE ERROR
	GETLIM	T1,.JQLIM(R),OINT	;GET OPERATOR INTERVENTION FLAG
	CAIE	T1,.OPINN		;NO INTERVENTION ALLOWED?
	POPJ	P,			;NO..JUST RETURN
	TLO	F,FL.NOP		;SET NO OPERATOR INTERVENTION FLAG
	MOVE	S1,[2,,S2]		;SETUP FOR JBSET.
	HRRZ	S2,J			;GET JOB NUMBER
	HRLI	T1,.STWTO		;SET WTO FIELDS
	HRRI	T1,.OBNWR		;NO WTOR ALLOWED	
	JBSET.	S1,			;DO THE FUNCTION
	  JFCL				;***IGNORE ERRORS
	POPJ	P,			;RETURN
>;END FTUUOS

IFN FTJSYS,<
LOGSET:	PUSHJ	P,SNDCLF		;FORCE CR,LF, BUFFER
	PUSHJ	P,WAITOU		;WAIT FOR I/O
	TLNE	J,JL.ULI		;USER LOGGED IN
	TLNE	R,RL.JIE		;DID LOGIN FAIL
	  PUSHJ	P,ANALYZ		;YES, ANALYZE THE LOGIN ERROR
	TRNE	F,FR.LFO		;IS LOG FILE OPEN
	  JRST LOGS.1			;BYPASS LOG OUTPUT
	PUSHJ	P,L$OUTP##		;DUMP THE DATA
	JUMPF	LOGEXT			;ERROR.. FINISH OFF THE JOB
LOGS.1:	PUSHJ	P,HLFDUP		;INSURE LINE STILL HALF DUPLEX
	HRLI	S1,2			;LENGTH OF 2
	HRRI	S1,.MSIMC		;INCREMENT MOUNT COUNT
	MOVEI	S2,T1			;GET ADDRESS OF ARGUMENT BLOCK
	HRROI	T1,.JQCON(R)		;CONNECTED DIRECTORY
	MOVE	T2,.JJOBN(R)		;GET THE JOB NUMBER
	MSTR				;DO THE MSTR
	ERJMP	LOGS.2			;IGNORE FOR NOW
LOGS.2:	MOVX	S1,AC%CON+3		;FLAGS,,LENGTH IN 1
	MOVEI	S2,T1			;ADR IN 2
	HRROI	T1,.JQCON(R)		;ADR POINTS TO STR-DIR STRING
	HRROI	T2,[ASCIZ / /]		;ADR+1 POINTS TO PSW (DUMMY)
	HRRZ	T3,.JJOBN(R)		;ADR+2 POINTS TO JOB NUMBER
	ACCES				;CONNECT THE JOB
	ERJMP	LOGS.3			;DON'T WAIT IF IT FAILED
	PUSHJ	P,IOWAIT		;GET RESPONSE FROM ACCES JSYS
LOGS.3:	HRRZ	S1,.JJOBN(R)		;GET THE JOB NUMBER
	MOVEI	S2,.SJDFS		;SET DEFAULT SPOOLING
	MOVEI	T1,.SJSPD		;A = S2 + 1, SET DEFERRED
	SETJB				;SET IT FOR THE JOB
	ERJMP	.+1			;IGNORE THE ERROR..
	HRRZ	S1,.JJOBN(R)		;GET THE JOB NUMBER
	MOVEI	S2,.SJBAT		;SET BATCH INFO
	SETZM	T1			;CLEAR DATA WORD
	MOVE	T2,.JQSTR(R)		;GET STREAM NUMBER
	STORE	T2,T1,OB%BSN		;SAVE BATCH STREAM NUMBER IN WORD
	TXO	T1,OB%BSS		;SET THE STREAM SET FLAG
	GETLIM	T2,.JQLIM(R),OINT	;GET OPERATOR INTERVENTION FLAG
	CAIE	T2,.OPINN		;NO INTERVENTION ALLOWED?
	JRST	LOGS.4			;DO THE FUNCTION
	TLO	F,FL.NOP		;SET NO OPERATOR INTERVENTION FLAG
	MOVX	T2,.OBNWR		;NO INTERVENTION ALLOWED
	STORE	T2,T1,OB%WTO		;SAVE THE DATA
LOGS.4:	SETJB				;DO THE FUNCTION
	ERJMP	.POPJ			;***IGNORE ERROR RETURN
	POPJ	P,			;RETURN
>;END FTJSYS

	;ROUTINE TO FINISH OFF A JOB

LOGEXT:	PUSHJ	P,ATOKJB		;LOG THE JOB OUT
	PJRST	CLOS.1			;CLOSE IT OUT
	SUBTTL	JOBSTA	--	JOB STARTUP AFTER LOGIN COMPLETED

JOBSTA:	AOS	S1,JOBTOT		;INCREMENT BATCON JOB TOTALS
	MOVEM	S1,.JOBCT(R)		;JOB COUNT FOR JOB
	TLZ	R,RL.LGI		;CLEAR LOGIN SEQUENCE NOW
	SKIPN	S1,.JCHRQ(R)		;IS THERE CHECKPOINT/REQUEUE INFO
	  JRST	NORM.2			;FIRST TIME..CHECK IF RESTARTABLE
	TXNN	S1,<BA.JOB>		;BETTER BE SET
	$STOP	(URJ,UNRECOGNIZED RESTART JOB)
	TXNE	S1,<BA.ORQ!BA.URQ!BA.CHK>;ANY REQ OR CHKPNT
	  JRST	CKPNTS			;YES,,CHECK FOR CHECKPOINT RESTART
	GETLIM	S2,.JQLIM(R),REST 	;GET RESTART DATA
	CAIE	S2,%EQRNO		;IS IT RESTARTABLE
	   JRST	CKPNTS			;TREAT IT AS RESTARTABLE
				;USER MODIFIED AFTER CRASH BUT BEFORE RESTART
	MOVEI	T1,[ASCIZ/BTNJNR Job Canceled after a Restart, It is not Restartable/]
NORM.1:	PUSHJ	P,L$CMNT##		;SET UP FOR COMMENT
	$TEXT	(L$OUT1,<? ^T/(T1)/>)	;OUTPUT MESSAGE TO LOG
	TRO	F,FR.LSL		;LIST SKIPPED LINES(WHOLE CTL)
	JRST	FINSRC			;GO TO %FIN::
NORM.2:	MOVX	S1,<BA.JOB>		;GET SEEN JOB FLAG
	IORM	S1,.JCHRQ(R)		;UPDATE FLAG WORD
	GETLIM	S2,.JQLIM(R),REST	;GET RESTART DATA
	CAIE	S2,%EQRNO		;IS IT RESTARTABLE
	  JRST	CKPNTS			;YES, GO GET STARTING POINT
	TRO	F,FR.CHK		;UPDATE CHECKPOINT..JOB SCHEDULED
CKPNTS:	SKIPN	S1,.JCHRQ+1(R)		;GET WHERE TO START PARAMETER
	  MOVE	S1,.JQCFP+1(R)		;GET /TAG OR /START VALUE (NO CHKPNT)
	TLNN	S1,777777		;IS IT A RESTART LABEL
	  JRST	CKLINE			;NO, TRY A LINE NUMBER
	MOVEM	S1,.JLABL(R)		;SAVE FOR LABFND
	PUSHJ	P,L$CMNT##		;PREPARE FOR A COMMENT
	$TEXT	(L$OUT1,<BTNBLA Beginning Processing at Label ^W/.JLABL(R)/>)
	TRO	F,FR.FIN		;THIS SEARCH MAY SKIP A %FIN::
	PUSHJ	P,SNDSTS		;SEND THE UPDATED STATUS TO QUASAR
	JRST	LABSRC			;SEARCH FOR THE LABEL
CKLINE:	CAIG	S1,1			;IS STARTING LINE .G.1
	  JRST CKLI.2			;START JOB NOW
	MOVEM	S1,.JLABL(R)		;SAVE THE COUNT OF LINES
	PUSHJ	P,L$CMNT##		;PREPARE FOR A COMMENT
	$TEXT	(L$OUT1,<BTNBLI Beginning Processing on Line ^D/.JLABL(R)/>)
CKLI.1:	SOSG	.JLABL(R)		;PASSED OVER ENOUGH YET
	  JRST CKLI.2			;START JOB NOW
	PUSHJ	P,GETCTL		;GET A CHARACTER
	PUSHJ	P,CMNT.3		;USE THE SILENCED COPY COMMENT
	JRST	CKLI.1			;SKIP OVER JUST ENOUGH
CKLI.2:	PUSHJ	P,SNDCHK		;UPDATE THE DISK AND QUASAR
	JUMPT	HONO.0			;O.K. START THE JOB
	PJRST	CLOSJB			;ABORT THE JOB
	SUBTTL	Job Processor - Honor Job's Input Request

HONORJ:	PUSHJ	P,IODISP
	SKIPA			;HAVE STATUS ALREADY
HONO.0:	PUSHJ	P,GJBSTS	;GET STATUS NOW
	TLNN	J,JL.UJA	;IS THERE A JOB STILL THERE
	  JRST	[PUSHJ	P,L$OUTP##	;OUTPUT THE LOG
		TLO R,RL.NLG	;SUPPRESS PRINTING OF THE LOG FILE
		JRST CLOS.1]	;SO JUST DISMISS THIS JOB
	TLNE	F,FL.TLE	;DID THIS JOB EXCEED ITS TIME LIMIT
	  JRST	TIMERR		;YES, CANCEL OR GIVE EXTRA TIME
	TLNE	R,RL.DIA	;DOES JOB WANT DIALOGUE MODE INPUT
	  JRST	REDOPR		;YES, READ NEXT LINE FROM THE OPERATOR
HONO.1:	TLZ	F,FL.LAB	;CLEAR A LABEL FOUND FLAG
	TLO	R,RL.FCI	;LOOKING FOR THE FIRST CHARACTER
	PUSHJ	P,GETCTL	;GET THE FIRST CHARACTER OF THIS LINE
HONO.2:	TLZ	R,RL.FCI	;CLEAR FLAGS
	SETZM	.JREOL(R)	;CLEAR END OF LINE SENT
	PUSHJ	P,CLASSF	;CLASSIFY THE CHARACTER WE HAVE
	  JRST	CNTLLI		;LINE TERMINATORS ARE ALSO SPEC. ACTION
	  JRST	CNTLLI		;SPECIAL ACTION CHARACTER
	  JRST	CPYLOP		;LINE STARTS WITH A NUMBER, IS USER DATA
	PUSHJ	P,DECRBP	;A LETTER, CHECK FOR A LABEL
	PUSHJ	P,SAVPOS	;SAVE CURRENT CTL FILE POSITION
	PUSHJ	P,GETSIX	;GET THE POSSIBLE LABEL
	TLON	F,FL.LAB	;ALREADY FIND 1 LABEL ON THIS LINE
	CAIE	CH,":"		;DID IT END WITH A COLON
	  JRST	NOTLAB		;NO, CANNOT BE A LABEL
	PUSH	P,S1		;SAVE S1 SINCE GETCTL WILL MODIFY IT
	PUSHJ	P,GETCTL	;GET THE NEXT CHARACTER
	POP	P,S1		;RESTORE LABEL IN S1
	CAIE	CH,":"		;IS IT LABEL::
	  JRST	NOTLAB		;NO, THAT IS THE ONLY KIND WE CAN 'FALL INTO'
	MOVEM	S1,.JLABL(R)	;SAVE THE LABEL[4062]
	IDENT	[ASCIZ/ BLABL	/] ;IDENTIFY THE LABELED LINE
	MOVE	T1,.JLABL(R)	;GET LABEL FOR LUUO INTO T1[4062]
	PUSHJ	P,L$LSIX##	;LOG THE LABEL (SIXBIT)
	PUSHJ	P,L$LCOL##	;LOG ONE COLON
	PUSHJ	P,L$LCOL##	;LOG THE SECOND ONE
	PUSHJ	P,L$CRLF	;PUT OUT CRLF
HONO.3:	PUSHJ	P,SKPBL1	;SKIP ANY BLANKS AFTER THE LABEL
HONO.4:	TLO	F,FL.LAB	;NO MORE LABELS ON THIS LINE
	TLNN	J,JL.UJA	;IS THERE A JOB STILL THERE
	  JRST	[PUSHJ	P,L$OUTP##	;OUTPUT THE LOG
		TLO R,RL.NLG	;SUPPRESS PRINTING OF THE LOG FILE
		JRST CLOS.1]	;SO JUST DISMISS THIS JOB
	CAIE	CH,CHR.CR	;IS THIS A NULL STATEMENT
	  JRST	HONO.2		;NO, TREAT THIS AS A LINE IDENTIFIER
	PUSHJ	P,GETCTL	;CHEW UP THE LINE FEED TOO
	JRST	HONO.1		;NOW MAY HAVE A LABEL
;HERE WHEN A LINE DOES NOT BEGIN WITH A LABEL

NOTLAB:	TLNE	J,JL.UML	;NOT A LABEL, IS USER AT MONITOR LEVEL
	  JRST	MONLIN		;YES, S1=MONIOR COMMAND OR BATCH COMMAND
	PUSHJ	P,REPOSI	;REPOSITION THE POINTERS
	PUSHJ	P,GETCTL	;GET THE FIRST CHARACTER OF THE LINE
	JRST	CPYLOP		;COPY TO THE USER JOB

;HERE WHEN DIALOGUE MODE IS IN EFFECT, READ FROM THE OPERATOR

REDOPR:	SETZ	S1,		;CLEAR S1..NO TEXT TO FOR RESPONSE
	PUSHJ	P,SNWTOR	;SEND WTOR MESSAGE
	PUSHJ	P,OPRRES	;GET THE RESPONSE
	TLNN	J,JL.UJA	;IS THERE A JOB STILL THERE
	  JRST	CLOS.1		;NO, JUST DISMISS IT
	TLNE	R,RL.DIA	;IS THE JOB STILL WAITING
	  JRST	REDOPR		;YES, OPERATOR MUST RESPOND
	IDENT	[ASCIZ/ BAOPR	From Operator: /] ;IDENTIFY THE OPERATOR RESPONSE
	PUSH	P,F		;SAVE F IN CASE SILENCE IS SET
	TLZ	F,FL.SIL	;THIS LINE MUST GO TO THE LOG FILE
	TXTJOB	@.JOPER+ARG.DA(R)	;SEND RESPONSE WITH TERMINATORS
	SKIPL	.JREOL(R)	;HAVE END OF LINE
	TXTJOB	CRLF		;NO..END THE LINE
	DMOVE	S1,.JOPER(R)	;GET LENGTH AND ADDRESS OF RESPONSE AREA
	$CALL	M%RMEM		;RETURN THE RESPONSE DATA
	SETZM	.JOPER(R)	;CLEAR COUNT WORD
	SETZM	.JOPER+1(R)	;AND ADDRESS WORD
	POP	P,S1		;RESTORE OLD F
	TLNE	S1,FL.SIL	;WAS SILENCE SET
	  TLO	F,FL.SIL	;YES, SET IT AGAIN
	PUSHJ	P,PTYSND	;OUTPUT THE PTY BUFFER
	SETOM	.JREOL(R)	;INDICATE AN END OF LINE SENT
	JRST	HONORJ		;END THIS DIALOGUE
;HERE IF LINE STARTS WITH A SPECIAL ACTION CHARACTER. DETERMINE WHICH ONE

CNTLLI:	TLZ	F,FL.PER	;CLEAR A FLAG
	CAIE	CH,CHR.FF	;IS IT VERTICAL PAPER MOTION IN CLOUMN 1
	CAIN	CH,CHR.VT	;LOOK FOR FORM FEED AND VERTICAL TAB
	  JRST	VERTMO		;YES, PRETEND COLUMN 2 IS COLUMN 1
	CAIE	CH,";"		;A COMMENT LINE
	CAIN	CH,"!"		;AS DEFINED BY THE STANDARD
	  JRST	CMNTLI		;YES, COPY THE COMMENT LINE
	CAIN	CH,"*"		;CUSP OR USER INPUT
	  JRST	USRINP		;YES, IS USER MODE INPUT
	CAIN	CH,"="		;SPECIAL USER LINES
	  JRST	EQUINP		;YES, IS USER MODE DATA
	CAIN	CH,"%"		;ONE OF THE RESERVED LABELS
	  JRST	DECLAB		;YES, SET UP SEARCH FOR A DIGITAL LABEL
	CAIE	CH,MONCHR	;MONITOR LEVEL ( . OR @ )
	  JRST	CPYLOP		;IF NONE OF THE ABOVE SPECIALS, IS USER DATA
	TLO	F,FL.PER	;REMEMBER A PERIOD WAS SEEN
	PUSHJ	P,SAVPOS	;SAVE THE CURRENT POSITION
	PUSHJ	P,GETSIX	;GET A COMMAND

IFE <MONCHR-".">,<		;IF PROMPT IS A DOT, RESLVE THE AMBIGUITY OF .NUM
	JUMPN	S1,MONLIN	;SOMETHING IS PRESENT, SEE IF A BATCH COMMAND
	CAIG	CH,"9"		;SEE IF LINE IS .NUMBER
	CAIGE	CH,"0"		;SEE IF THE TERMINATOR IS A VALID DIGIT
	  JRST	MONSND		;SEND THE LINE TO THE MONITOR
	PUSHJ	P,REPOSI	;REPOSITION THE CTL FILE
	TLZ	F,FL.PER	;CLEAR A FLAG
	MOVEI	CH,MONCHR	;WILL SEND A PERIOD TO THE JOB
	JRST	CPYLOP		;THIS LINE IS USER DATA
>  ;END OF IFE

MONLIN:	TLNN	S1,007700	;CANNOT BE A BATCH COMMAND IF 1 LETTER
	  JRST	MONSND		;SEND SINGLE LETTER COMMANDS TO THE MONITOR
	MOVE	T1,[-NBACMD,,BACMDS] ;AOBJN FOR TABLE LOOKUP
	PUSHJ	P,TABSRC	;DO THE TABLE SEARCH FOR COMMAND IN S1
	  JRST	MONSND		;NOT FOUND, GIVE TO THE MONITOR
	  JRST	MONSND		;GIVE AMBIGUOUS ONES TO THE MONITOR ALSO
	SKIPL	T3,BADISP(T3)	;GET DISPATCH, SEE IF VALID IF JOB IS IN ERROR
	TLNN	R,RL.JIE	;NOT VALID, IS THE JOB IN ERROR
	  JRST	(T3)		;OK TO DO THE COMMAND
MONSND:	PUSHJ	P,REPOSI	;REPOSITION THE FILE
	TLNE	R,RL.JIE	;IS THE JOB IN ERROR NOW
	  JRST	USRERR		;YES, BUT NO .IF(XXXX) STUFF, LOOK FOR ERROR PACKETS
	PUSHJ	P,INMONM	;MAKE SURE THE JOB'S IN MONITOR MODE
	TLNE	F,FL.SIL	;IS THIS OUTPUT TO BE SILENCE
	  TLZ	F,FL.PER	;YES, CLEAR POSSIBLE PERIOD FLAG
	TLZE	F,FL.PER	;DID THE LINE START WITH A PERIOD
	  PUSHJ	P,L$LPER##	;YES, ECHO A PERIOD FOR CLEANLINESS
	JRST	MONSUP		;COPY THE REST OF THE LINE (SUPPRESS TRAILING BLANKS)
;RULES FOR THE COMMAND TABLE
;	1)COMMANDS ARE UNIQUE IN 4 LETTERS
;	  1.1)EXCEPT BACKTO AND BACKSPACE (MONITOR COMMAND TAKES PRECEDENCE)
;	2)IF THE SECOND ARGUMENT IS PRESENT, THE COMMAND CAN BE EXECUTED
;	  EVEN IF THE JOB IS IN ERROR
;	3)IF THE THIRD ARGUMENT IS PRESENT, IT IS THE DISPATCH ADDRESS

DEFINE	CMDTBL<
	LSTOFF
	X	BACKSP,,MONSND	;SEND ANY ABBREVIATION OF BACKSP TO THE MONITOR
	X	BACKTO,		;GOTO A PRIOR LABEL
	X	CHKPNT,		;TAKE A CHECK POINT
	X	ERROR,		;DEFINE AN ADDITIONAL ERROR CHARACTER
	X	GOTO,		;PROCEED AT ANOTHER PLACE
	X	IF,E		;ERROR TESTING
	X	MESSAG,		;$MESSAGE FOR MINI-BATCH STANDARD
	X	NOERRO,		;TURN OFF ALL ERRORS (EXCEPT TIME EST EXCEEDED)
	X	NOOPER,E	;LEAVE DIALOGUE MODE
	X	OPERAT,		;ENTER DIALOGUE MODE WITH A SPECIFIC CHARACTER
	X	PLEASE,		;TRAP SYSTEM PLEASE COMMANDS
	X	REQUEU,		;REQUEUE THIS JOB
	X	REVIVE,		;RESUME NORMAL LISTING MODE
	X	SILENC,		;TURN OFF ALL OUTPUT
	LSTON
	>

DEFINE	X(A,B,C)<
	<SIXBIT\A\>
	>
BACMDS:	CMDTBL		;GENERATE THE COMMAND TABLE
NBACMD==.-BACMDS	;NUMBER OF COMMANDS

DEFINE	X(A,B,C)<
	IFB <C>,<
		IFB <B>,<EXP BB'A>
		IFNB <B>,<XWD 400000,BB'A>>
	IFNB <C>,<
		IFB <B>,<EXP C>
		IFNB <B>,<XWD 400000,C>>
	>
BADISP:	CMDTBL		;GENERATE THE DISPATCH TABLE
;HERE IF LINE IS FOR USER LEVEL INPUT

EQUINP:	TLO	F,FL.SUP	;SET SUPPRESSION OF FINAL CR-LF
USRINP:	JSP	P2,ISCMNT	;SEE IF THIS LINE IS A COMMENT TO THE LOG FILE
	TLNN	F,FL.SIL	;IS THE LOG FILE SILENCED
	  PUSHJ	P,L$PLOG##	;NO, ECHO THE CHARACTER
CPYLIN:	PUSHJ	P,GETCTL	;GET THE NEXT CHARACTER
CPYL.1:	TLNE	F,FL.SUP	;WANT TO SUPPRESS THE CR-LF
	  JRST	CPYL.2		;YES, SEE IF THIS IS THE LINE FEED
CPYSND:	PUSHJ	P,CHKSND	;SEND IT TO THE JOB, CHECK RESULT
	CAIE	CH,CHR.LF	;DID WE SEND THE LINE FEED
	  JRST	CPYLIN		;NO, CONTINUE COPY
CPYOUT:	SETOM	.JREOL(R)	;MARK END OF LINE SENT
	PUSHJ	P,PTYSND	;SEND THE PTY BUFFER
;FIXED BY 4070
;IFN	FTJSYS,<
;	PUSHJ	P,QTS		;GIVE THE JOB SOME TIME[4061]
;>;END FTJSYS
	JRST	HONORJ		;AND WAIT FOR NEXT INPUT REQUEST
CPYL.2:	CAIE	CH,CHR.LF	;YES, SEE IF THIS IS THE LINE FEED
	CAIN	CH,CHR.CR	;OR THE CARRIAGE RETURN
	  SKIPA			;YES, SUPPRESS THEM
	JRST	CPYSND		;NO, SEND THIS CHARACTER
	CAIE	CH,CHR.LF	;ANOTHER CHECK
	  JRST	CPYLIN		;IGNORE THE CARRIAGE RETURN
	TLZ	F,FL.SUP	;CLEAR SUPPRESSION ON THE LINE FEED
	JRST	CPYOUT		;OUTPUT THE CURRENT BUFFERS
VERTMO:	JSP	P2,ISCMNT	;SEE IF THIS LINE IS A COMMENT TO THE LOG FILE
	PUSHJ	P,SNDCHR	;SEND THE FF OR VT
	JRST	CPYOUT		;SEND THE BUFFER AND WAIT
;HERE TO SUPPRESS TRAILING BLANKS ON A MONITOR COMMAND LINE

MONSUP:	SKIPE	.JRTIM(R)	;NEED A TIME STAMP
	 TLNE	F,FL.SIL	;YES BUT IS THE OUTPUT SILENCED
	  SKIPA			;NEVER MIND THE STAMP
	   PUSHJ P,L$LSTP##	;OUTPUT ONE NOW
	SETZ	P1,		;WILL COUNT BLANKS
MONS.1:	PUSHJ	P,GETCTL	;GET A CHARACTER FROM THE CTL FILE
	CAIE	CH,CHR.LF	;END OF THE LINE
	 CAIN	CH,CHR.CR	;THE CARRIAGE RETURN
	  JRST	CPYSND		;YES, SEND THAT, THE LINE FEED, AND DONE
	CAIN	CH," "		;A BLANK TO SUPPRESS
	  AOJA	P1,MONS.1	;YES, COUNT IT AND GET ANOTHER
	JUMPE	P1,MONS.2	;JUMP IF NO BLANKS PRECEEDED IT
	MOVE	P2,CH		;SAVE THE CHARACTER
	MOVEI	CH," "		;GET A BLANK
	PUSHJ	P,CHKSND	;SEND IT TO THE JOB, CHECK RESULT
	SOJG	P1,.-1		;SEND AS MANY AS NEEDED, CLEAR THE COUNTER
	MOVE	CH,P2		;GET THE ORIGINAL BACK
MONS.2:	PUSHJ	P,CHKSND	;SEND IT TO THE JOB, CHECK RESULT
	JRST	MONS.1		;GET ANOTHER

;HERE TO DETERMINE IF THIS LINE IS A COMMENT OR TO BE SENT AS USER DATA

CPYLOP:	MOVEI	P2,CPYL.1	;FAKE OUT A JSP
ISCMNT:	TLNN	R,RL.JIE	;IS THE JOB IN ERROR STATE
	TLNE	J,JL.UML	;OR IS THE JOB AT MONITOR LEVEL
	  JRST	CMNTLI		;YES, THIS LINE IS A COMMENT
	JRST	(P2)		;NO, SEND THIS LINE TO THE USER JOB

;HERE TO COPY A COMMENT LINE TO THE LOG FILE (CH IS THE FIRST CHARACTER)

CMNTLI:	PUSHJ	P,CPYCMT	;USE THE SUBROUTINE FOR THIS
	TLZ	F,FL.SUP	;IF COPIED A COMMENT LINE, CLEAR SUPRESSION
	JRST	HONO.1		;RESUME READING THE CTL FILE

;HERE TO SEND A CHARACTER TO THE SUBJOB, CHECK IF JOB IS STILL AROUND

CHKSND:	PUSHJ	P,SNDCHR	;FIRST, SEND THE CHARACTER, LOG IT
	TLNE	J,JL.UJA	;IS THE JOB STILL THERE
	  POPJ	P,		;YES, RETURN FOR MORE DATA
	PUSHJ	P,SNDUPC	;NO, ADD CONTROL C AND DUMP THE BUFFER
	PUSHJ	P,IOWAIT	;WAIT FOR MONITOR TO TYPE "?"
	JRST	CLOS.1		;AND DISMISS THE JOB
	SUBTTL	Job Processor - Execute Batch Commands

;GOTO COMMAND - PROCEED AT ANOTHER PLACE

BBGOTO:	PUSHJ	P,GETLAB	;GET A LABEL AND ECHO THE BATCH COMMAND LINE
	SKIPE	.JLABL(R)	;WAS THERE ONE
	  JRST	LABSRC		;YES, GO LOOKING
GOTO.1:	MOVEI	T1,[ASCIZ/BTNNLS No label specified or illegal syntax./]
	JRST	NORM.1		;OUTPUT ERROR AND GO TO %FIN::

;BACKTO COMMAND - GOTO A PRIOR LABEL

BBBACK:	MOVE	S1,.JCJFN(R)	;JFN FOR CTL FILE
	$CALL	F%CHKP		;TAKE CHECKPOINT OF FILE
	MOVEM	S1,.JBAKP(R)	;SAVE POINTER
	PUSHJ	P,GETLAB	;GET A LABEL AND ECHO THIS LINE
	SKIPN	.JLABL(R)	;WAS THERE ONE
	  JRST	GOTO.1		;NO GIVE AN ERROR
	HRRZ	S1,J		;GET THE MONITOR JOB NUMBER
	MOVX	S2,JI.RTM	;GET THE RUNTIME
	PUSHJ	P,I%JINF	;GET THE JOB INFO
	CAMG	S2,.JRUNT(R)	;USER MUST DO SOMETHING TO GET RUNTIME
	  JRST	BACK.1		;OTHERWISE COULD BE A::.BACKTO A
	MOVEM	S2,.JRUNT(R)	;SAVE FOR NEXT BACKTO COMMAND
	TRO	F,FR.BAK!FR.FIN	;SET SOME SEARCH FLAGS
	MOVE	S1,.JCJFN(R)	;JFN FOR FILE
	MOVEI	S2,0		;BEGINNING OF FILE
	$CALL	F%POS		;POSITION FILE FOR BACKTO
	JRST	LABSRC		;GO FIND THE LABEL
BACK.1:	MOVEI	T1,[ASCIZ/BTNBPL Your use of BACKTO has caused a possible loop./]
	JRST	NORM.1		;ISSUE ERROR AND GOTO %FIN::

;CHKPNT COMMAND - TAKE A CHECKPOINT

BBCHKP:	PUSHJ	P,GETLAB	;GET THE REQUEUE LABEL AND ECHO THIS LINE
	MOVX	S1,<BA.CHK>	;GET CHECKPOINT FLAG
	IORM	S1,.JCHRQ(R)	;TURN ON CHECKPOINT FLAG IN CHECK WORDS
	SKIPN	S1,.JLABL(R)	;WAS THERE A LABEL
	  JRST	GOTO.1		;NO, IS AN ERROR
	MOVEM	S1,.JCHRQ+1(R)	;STORE THE RESTART LABEL
	TRO	F,FR.CHK	;UPDATE CHECKPOINT DATA TO DISK
	PUSHJ	P,SNDCHK	;SEND STATUS UPDATE AND CHECKPOINT
	JUMPT	HONO.1		;O.K.RESUME THE CTL FILE
	JRST	CLOSJB		;ERROR..CLOSE OUT THE JOB

;REQUEUE COMMAND - REQUEUE THIS JOB (OPTIONAL RESTART LABEL)

BBREQU:	PUSHJ	P,GETLAB	;GET THE OPTIONAL LABEL, ECHO THIS LINE
	MOVX	S1,<BA.URQ>	;GET REQUEUE BY USER
	IORM	S1,.JCHRQ(R)	;TURN ON USER REQUEUE IN CHECK WORDS
	MOVEI	S1,E.RUSR	;REQUEUED BY THE USER
	MOVEM	S1,.JERRO(R)	;REASON FOR ENDING
	SKIPE	S1,.JLABL(R)	;WAS THERE A LABEL
	  MOVEM	S1,.JCHRQ+1(R)	;STORE THE RESTART LABEL
	IDENT	[ASCIZ / BTNJRQ	JOB REQUEUED/]
	PUSHJ	P,L$CRLF##	;CRLF TO JOB
	SETZM	.JREQI(R)	;CLEAR FLAG WORD FOR REQUEUE
	JRST	REQEXT		;GIVE AN AFTER, LOGOUT, AND REQUEUE
;NOERROR COMMAND - TURN OFF ALL ERRORS (EXCEPT TIME EST EXCEEDED)

BBNOER:	TLO	F,FL.NER	;SET NOERROR IN EFFECT
BAEXIT:	PUSHJ	P,BALINE	;ECHO THE BATCH COMMAND
	JRST	HONO.1		;RESUME READING THE CTL FILE

;NOOPERATOR COMMAND - LEAVE DIALOGUE MODE

BBNOOP:	SETZ	S1,		;CLEAR THE DIALOGUE CHARACTER
	DPB	S1,LDOPCH	;CLEAR IT
	JRST	BAEXIT		;AND EXIT THROUGH COMMON CODE

;ERROR COMMAND - DEFINE AN ADDITIONAL ERROR CHARACTER

BBERRO:	TLZ	F,FL.NER	;CLEAR NOERROR MODE
	JSP	T4,ER..OP	;CALL COMMON ROUTINE FOR ERROR/OPERATOR
	XWD	0,[ASCIZ/ERROR/] ;DEFAULT CHARACTER,,STRING NAME OF CALLER
LDERCH:	POINT	9,.JERCD(R),8	;HOW TO LOAD/STORE THE CHARACTER

;OPERATOR COMMAND - ENTER DIALOGUE MODE WITH THE SPECIFIED CHARACTER

BBOPER:	JSP	T4,ER..OP	;CALL THE COMMON PROCESS (IT WILL NO RETURN HERE)
	XWD	"$",[ASCIZ/OPERATOR/] ;DEFAULT IS $,CALLER IS OPERATOR
LDOPCH:	POINT	9,.JERCD(R),17	;HOW TO LOAD/STORE THE CHARACTER

;PLEASE COMMAND - OUTPUT A MESSAGE TO THE OPERATOR (OPTIONALLY WAIT)
;MESSAGE COMMAND - THE PLEASE COMMAND FOR THE MINI-BATCH STANDARD

BBMESS:
BBPLEA:	TLO	F,FL.PLS	;SET PLEASE IN PROGRESS
	PUSHJ	P,STAWTO	;GIVE A HEADER TO THE OPERATOR
	PUSHJ	P,BALINE	;ECHO LINE TO THE LOG AND TO THE OPERATOR
	TLZN	F,FL.PLS	;IS PLEASE STILL SET
	  JRST	[PUSHJ P,OUTEXT	;END THE TTY LINE
		JRST HONO.1]	;RESUME READING THE CTL FILE
	PUSHJ	P,SNWTOR	;SEND WTOR
	PUSHJ	P,OPRRES	;GET THE OPERATOR RESPONSE
	PUSHJ	P,IDNOPR	;IDENTIFY LINE TO OPERATOR
	$TEXT	(SENDJ1,<From Operator: ^T/@.JOPER+1(R)/^A>)
	PUSHJ	P,L$CRLF##	;PUT OUT CR, AND LINE FEED
	DMOVE	S1,.JOPER(R)	;GET THE SIZE AND ADDRESS
	PUSHJ	P,M%RMEM	;RELEASE THE MEMORY
	SETZM	.JOPER(R)	;CLEAR VALUE
	SETZM	.JOPER+1(R)	;CLEAR ADDRESS WORD
	JRST	HONO.0		;START AT THE BEGINNING

;SILENCE COMMAND - TURN OFF THE LOG FILE
;REVIVE COMMAND - TURN IT BACK ON

BBSILE:	TLOA	F,FL.SIL	;SET SILENCE MODE
BBREVI:	  TLZ	F,FL.SIL	;CLEAR SILENCE MODE
	JRST	BAEXIT		;END OF THESE COMMANDS
;IF COMMAND - DO SOME ERROR TESTING

BBIF:	PUSHJ	P,SKPBLK	;SKIP OVER ANY BLANKS
	CAIE	CH,"("		;NEED THE OPENING PAREN
	  JRST	IF...E		;BAD IF COMMAND
	PUSHJ	P,GETSIX	;GET THE ARGUMENT
	JUMPE	S1,IF...E	;BAD COMMAND
	PUSHJ	P,SKPBLK	;SKIP MORE BLANKS
	CAIE	CH,")"		;BETTER BE THE CLOSURE
	  JRST	IF...E		;REAL BAD COMMAND
	MOVE	T1,[-NIFCMD,,IFCMDS] ;AOBJN FOR TABLE LOOKUP
	PUSHJ	P,TABSRC	;LOOK FOR THE COMMAND IN S1
	  JRST	IF...E		;NOT FOUND
	  JRST	IF...E		;AMBIGUOUS
	JRST	@IFDISP(T3)	;PROCESS THE IF COMMAND
IF...E:	PUSHJ	P,BALINE	;OUTPUT THE LINE
	MOVEI	T1,[ASCIZ/BTNIIC Illegal IF command argument or syntax error./]
	JRST	NORM.1		;GIVE ERROR AND GOTO %FIN::


;DEFINE THE LEGAL ARGUMENTS FOR IF COMMANDS. RULES:
;	1)COMMANDS ARE UNIQUE IN 4 LETTERS

DEFINE	CMDTBL<
	LSTOFF
	X	ERROR,	;TEST IF AN ERROR OCCURRED
	X	NOERRO,	;TEST IF NO ERRORS HAVE OCCURRED
	LSTON
	>

DEFINE	X(A)<
	<SIXBIT\A\>
	>

IFCMDS:	CMDTBL		;GENERATE THE ARGUMENT TABLE
NIFCMD==.-IFCMDS	;NUMBER OF THEM

DEFINE	X(A)<
	EXP	FF'A
	>

IFDISP:	CMDTBL		;GENERATE THE DISPATCH TABLE
;HERE TO PROCESS THE IF COMMAND

;FFERRO PROCESSES THE .IF(ERROR)statement FORM

;FFNOER PROCESSES THE .IF(NOERROR)statement FORM

;EXIT IS VIA IFTRUE IF THE CONDITION IS TRUE AND THE STATEMENT IS TO BE EXECUTED
;OR IFFALS IF THE CONDITION IS FALSE AND THE STATEMENT IS TO BE SKIPPED

FFERRO:	TLZN	R,RL.JIE	;DID AN ERROR OCCUR
	  JRST	IFFALS		;NO, IF(ERROR) IS FALSE
IFTRUE:	IDENT	[ASCIZ/ TRUE	/] ;IDENTIFY TRUE LINE
	PUSHJ	P,REPOSI	;BACK TO THE START OF THIS LINE
	TLZE	F,FL.PER	;NEED A PERIOD
	  PUSHJ	P,L$LPER##	;YES, ECHO ONE FOR CLEANLINESS
IFTR.1:	PUSHJ	P,GETCTL	;CAN COPY EVERYTHING UP TO THE CLOSE PAREN
	PUSHJ	P,L$PLOG##	;OUTPUT THIS ONE
	CAIE	CH,")"		;ALL AFTER THAT IS ANOTHER COMMAND
	  JRST	IFTR.1		;CONTINUE
	PUSHJ	P,L$CRLF##	;END THIS LINE
	JRST	HONO.3		;FIND THE OBJECT STATEMENT AND EXECUTE IT

FFNOER:	TLZN	R,RL.JIE	;DID AN ERROR OCCUR
	  JRST	IFTRUE		;NO, .IF(NOERROR) IS TRUE
IFFALS:	IDENT	[ASCIZ/ FALSE	/] ;IDENTIFY THE FALSE LINE
	PUSHJ	P,REPOSI	;BACK UP THE LINE
	PUSHJ	P,BALI.1	;COPY THE ENTIRE LINE AS A COMMENT
	JRST	HONO.1		;PROCESS THE NEXT STATEMENT

;HERE TO GET A LABEL FOR COMMANDS LIKE GOTO (AND ECHO A BATCH COMMAND LINE)

GETLAB:	TRO	F,FR.RSC	;ALREADY HAVE CH
	PUSHJ	P,GETSIX	;GET A SIXBIT LABEL
	MOVEM	S1,.JLABL(R)	;STORE IT (EVEN IF NONE)
BALINE:	IDENT	[ASCIZ/ BATCH	/] ;IDENTIFY THIS LINE
	PUSHJ	P,REPOSI	;REPOSITION TO THE BEGINNING OF THE LINE
BALI.1:	TLZE	F,FL.PER	;DID LINE START WITH A PERIOD
	  PUSHJ	P,L$LPER##	;YES, ECHO ONE FOR CLEANLINESS
	PUSHJ	P,GETCTL	;GET THE CHARACTER
	PJRST	CMNT.1		;ECHO IT AND THE LINE, THEN RETURN
;HERE TO GET THE CHARACTER FOR .ERROR AND .OPERATOR
;CALL VIA JSP T4,ER..OP (DOES NOT RETURN TO CALLER)
;	0(S1) = XWD DEFAULT CHARACTER , [ASCIZ/CALLERS NAME/]
;	1(S1) = POINT STATEMENT TO STORE THE CHARACTER

ER..OP:	HLR	S2,(T4)		;GET THE DEFAULT CHARACTER
	DPB	S2,1(T4)	;STORE IT NOW
	PUSHJ	P,SKPBLK	;SKIP OVER ANY BLANKS (TABS)
	CAIE	CH,CHR.CR	;IS IT THE CARRIAGE RETURN
	PUSHJ	P,COMTRM	;THIS IS THE SAME CHECK AS IN GETONE
	  JRST	BAEXIT		;YES, RETURN WITH DEFAULT SET
	CAIE	CH,";"		;LINE HAVE A COMMENT
	CAIN	CH,"!"		;OTHER COMMENT CHARACTER
	  JRST	BAEXIT		;YES, STOP NOW
	CAIG	CH,40		;ONLY VALID IF ABOVE 40 OCTAL
	  JRST	ER...1		;BAD CHARACTER SPECIFIED
	DPB	CH,1(T4)	;STORE THE SPECIFIED CHARACTER
	JRST	BAEXIT		;AND RETURN THROUGH COMMON CODE
ER...1:	SETZ	S2,		;ON ERROR, CLEAR ANY DEFAULT CHARACTER
	DPB	S2,1(T4)	;STORE A NULL CHARACTER
	HRRZ	S1,(T4)		;GET ADDRESS OF CALLERS NAME
	MOVEM	S1,TEMP2	;SAVE IN A TEMP
	PUSHJ	P,BALINE	;ECHO THE BATCH COMMAND
	$TEXT	(L$OUT1,<BTNICS Illegal character specified for ^T/TEMP2/
>)			;END THE MESSAGE 
	JRST	FINSRC		;GOTO %FIN::

;HERE FOR THE FIRST LOOK AT DIGITAL RESERVED LABELS (%XXXXX::)

USRERR:	TLZE	F,FL.PER	;ENTERED AT USRERR FROM MONSND
DECLAB:	  PUSHJ	P,DECRBP	;BACK UP OVER THE % SIGN (OR .)
	TRO	F,FR.LSL	;LIST LINES SKIPPED
	TLNN	R,RL.JIE	;IS THE JOB IN ERROR
	  JRST	FINSRC		;NO, LOOK FOR % FIN
	PUSHJ	P,SYSPRG	;WHERE DID THE PROGRAM COME FROM
	  SKIPA	S1,[SIXBIT/%CERR/] ;SYS
	MOVE	S1,[SIXBIT/%ERR/] ;USER
	MOVEM	S1,.JLABL(R)	;SAVE THE LABEL
	JRST	LABSRC		;NOW SEARCH FOR IT

;HERE TO SET UP FOR A SEARCH FOR %FIN:: OR %TERR::

TIMERR:	MOVEI	S1,E.TLMT	;TIME LIMIT EXCEEDED
	MOVEM	S1,.JERRO(R)	;SAVE ERROR CODE FOR END STATEMENT
	TLO	F,FL.ERR	;SET ERROR CONDITION FLAG
	TLOE	F,FL.%XT	;TIME EST EXCEEDED GIVE EXTRA TIME
	  JRST	CLOSJB		;ALREADY DID, KLUNK THE JOB NOW
	TRO	F,FR.LSL	;LIST LINES SKIPPED FOR TIME LIMIT EXCEEDED
	SKIPA	S1,[SIXBIT/%TERR/]  ;SET UP FOR SEARCH
FINSRC:	MOVE	S1,[SIXBIT/%FIN/] ;LABEL WE WANT
	MOVEM	S1,.JLABL(R)
	JRST	LABSRC		;NOW SEARCH FOR IT
;HERE TO ACTUALLY DO THE LABEL SEARCH.  .JLABL(R) HAS THE LABEL

LABSRC:	TRO	F,FR.%SG	;INCLUDE % SIGNS IN LABELS
	TLO	R,RL.FCI	;FAKE OUT CLOSJB IF WE NEVER FIND THE LABEL
LABS.0:	TRNE	F,FR.LSL	;LISTING SKIPPED LINES
	  PUSHJ	P,SAVPOS	;YES, SAVE OUT CURRENT POSITION
	PUSHJ	P,GETONE	;GET THE FIRST CHARACTER OF THIS LINE
	  JRST	LABS.5		;END OF LINE CHARACTER
	  CAIE	CH,"%"		;SPECIAL CHARACTER, IS IT % SIGN
	  JRST	LABS.4		;A NUMBER OR OTHER SPECIAL, IS NOT A LABEL
	TRO	F,FR.RSC	;LINE STARTS WITH A LETTER, RE-GET IT IN GETSIX
	PUSHJ	P,GETSIX	;GET A POSSIBLE LABEL
	CAIN	CH,":"		;FIELD END WITH A COLON
	  JRST	LABFND		;YES, FOUND A LABEL
LABS.4:	TRNE	F,FR.LSL	;IS THE POSITION ON THE STACK
	  JRST	LABS.3		;YES, LIST THE SKIPPED LINE
	JRST	LABS.S		;MIGHT ALREADY BE A TERMINATOR
LABS.1:	PUSH	P,S1		;SAVE S1 SINCE GETCTL WILL MODIFY IT
	PUSHJ	P,GETCTL	;GET THE NEXT CHARACTER
	POP	P,S1		;RESTORE LABEL IN S1
LABS.S:	CAIE	CH,CHR.LF	;END OF THIS LINE YET
	  JRST	LABS.1		;IGNORE MORE CHARACTERS
LABS.2:	TRNN	F,FR.BAK	;END OF A LINE, DOING A BACKTO
	  JRST	LABS.0		;NO, CHECK FOR A LABEL ON THIS LINE
	MOVE	S1,.JCJFN(R)	;JFN FOR CONTROL FILE
	$CALL	F%CHKP		;CHECKPOINT THE FILE
	CAML	S1,.JBAKP(R)	;PASS IT UP YET
	  JRST	CLOSJB		;YES, REPORT THE ERROR
	JRST	LABS.0		;NO, LOOK FOR A LABEL ON THIS LINE
LABFND:	TRNN	F,FR.FIN	;CAN WE SKIP OVER A %FIN::
	 CAME	S1,[SIXBIT/%FIN/] ;NO, IS THIS %FIN::
	  SKIPA			;SEE IF LABEL WE ARE SEARCHING FOR
	   JRST	FINFND		;FOUND A %FIN::, SEARCH IS COMPLETED
	CAME	S1,.JLABL(R)	;IS IT THE ONE WE WERE LOOKING FOR
	  JRST	LABS.4		;NO, CONTINUE SEARCH
	CAMN	S1,[SIXBIT/%TERR/]  ;LOOKING FOR TIME LIMIT RECOVERY
	  JRST	FINF.2		;YES, AND THIS IS IT, GIVE %EXTRA
LABF.1:
LABF.2:	IDENT	[ASCIZ/ BLABL	/] ;IDENTIFY LABELED LINE
	SIXLOG	.JLABL(R)	;OUTPUT THE LABEL FOUND
	PUSHJ	P,L$LCOL##	;ADD A COLON
	PUSHJ	P,GETCTL	;GET THE NEXT CHARACTER (MAYBE ANOTHER COLON)
	PUSH	P,CH		;SAVE IT FOR NOW
	CAIN	CH,":"		;WAS IT A COLON
	  PUSHJ	P,L$PLOG##	;YES, OUTPUT IT
	PUSHJ	P,L$CRLF##	;END THE LINE
	TRZ	F,FR.%SG!FR.BAK!FR.LSL!FR.FIN	;CLEAR SEARCH TYPE FLAGS
	TLZ	R,RL.JIE!RL.DIA	;AFTER A SUCCESSFUL FIND, CLEAR JOB IN ERROR
	POP	P,CH		;RESTORE THAT CHARACTER
	CAIN	CH,":"		;WAS IT THE SECOND COLON
	  JRST	HONO.3		;YES, FIND THE OBJECT STATEMENT AND EXECUTE IT
	PUSHJ	P,SKPBLK	;SKIP THIS IF A BLANK (AND ANY OTHERS)
	JRST	HONO.4		;NOW EXECUTE THE OBJECT STATEMENT
LABS.3:	PUSHJ	P,REPOSI	;REPOSITION THE CTL FILE
	PUSHJ	P,GETCTL	;GET THE FIRST CHARACTER
	PUSHJ	P,CPYCMT	;COPY IT AND THE REST AS A COMMENT LINE
	JRST	LABS.2		;RETURN TO BACKTO CHECK
LABS.5:	CAIE	CH,CHR.FF	;CHECK EOL CHARACTER FOR FORM FEED-VERTICAL TAB
	CAIN	CH,CHR.VT	;CHARACTER AFTER THEM CAN START A NEW LABEL
	  MOVEI	CH,CHR.LF	;PRETEND A LINE FEED TO END THIS LINE
	JRST	LABS.4		;IF LISTING LINES, IT WILL COME OUT A FF OR VT
;HERE WHEN A %FIN:: HAS BEEN FOUND   S1=SIXBIT/%FIN/

FINFND:	CAMN	S1,.JLABL(R)	;WERE WE SEARCHING FOR %FIN::
	  JRST	FINF.1		;YES, SKIP THE MESSAGE
	PUSHJ	P,L$BLNK##	;GET A BLANK LINE IN THE LOG FILE
	PUSHJ	P,L$CMNT##	;PREPARE A COMMENT LINE
	TXTLOG	[ASCIZ/BTNFFS Found %FIN while searching for /]
	SIXLOG	.JLABL(R)	;OUTPUT THE LABEL
	TXTLOG	[ASCIZ/, proceeding from %FIN/]
	PUSHJ	P,L$CRL2##	;FINISH LINE AND ADD 1
	MOVE	S1,[SIXBIT/%FIN/]  ;NEED TO RESET THE LABEL SEARCHED FOR
	MOVEM	S1,.JLABL(R)	;SO WE CAN PRINT IT OUT AT LABF.2
FINF.1:	PUSHJ	P,CHKCLS	;SEE IF A CLOSE/DUMP IS NEEDED
FINF.2:	TLZN	F,FL.TLE	;DID THE JOB EXCEED THE TIME LIMIT
	  JRST	LABF.1		;NO, RESUME NORMAL ROUTE
	PUSHJ	P,INMONM	;MAKE SURE THE JOBS IN MONITOR MODE
	HRRZ	T3,.JQLIM+1(R)	;GET THE JOBS TIME EST
	IMULI	T3,%EXTRA	;COMPUTE THE EXTRA TIME AVAILABLE
	IDIVI	T3,^D100	;AS A PERCENTAGE OF THE ORIGINAL EST
	CAIGE	T3,%EXTRA	;BUT LETS BE REASONABLE ABOUT IT
	  MOVEI	T3,%EXTRA	;USING %EXTRA HERE IS PROBABLY OK

IFN FTUUOS,<
	MOVE	T1,[2,,T2]	;SET UP FOR JBSET
	HRRZ	T2,J		;GET THE JOB NUMBER
	HRLI	T3,.STTLM	;SET TIME FUNCTION
	JBSET.	T1,		;TRY IT WITH THE UUO
>  ;END OF IFN FTUUOS

	  PUSHJ	P,SETTIM	;SEND THE COMMAND IF THAT FAILED
	JRST	LABF.1		;AND RETURN TO NORMAL SEARCH
	SUBTTL	Job Processor - Perform Auto KJOB and Dismiss the Job

CLOSJB:: TLNE	R,RL.KJB	;WHAT ARE WE DOING HERE
	  JRST	CLOS.3		;IN LOTS OF TROUBLE, GO DISMISS THE JOB
	TRNN	F,FR.%SG	;WAS A LABEL SEARCH IN PROGRESS
	  JRST	CLOS.0		;NO, SKIP THE ERROR MESSAGE
	LDB	S1,[POINT 6,.JLABL(R),5] ;GET THE FIRST SIXBIT CHARACTER
	CAIN	S1,'%'		;WAS IT ONE OF THE % LABELS
	  JRST	CLOS.4		;YES, GIVE A DIFFERENT MESSAGE
	PUSHJ	P,L$BLNK##	;LOG A BLANK LINE
	PUSHJ	P,L$CMNT##	;LOG A COMMENT
	$TEXT	(L$OUT1,<? BTNCNF Could not find Label ^A>)
CLOS.5:	SIXLOG	.JLABL(R)	;OUTPUT THE LABEL
	PUSHJ	P,L$CRL2##	;FINISH LINE AND ADD ONE
	SKIPN	.JERRO(R)	;ALREADY HAVE AN ERROR
	TLOE	F,FL.ERR	;ERROR FLAG ON...ELSE SET IT
	JRST	CLOS.0		;YES..ALREADY HAD AN ERROR
	MOVEI	S1,E.UERR	;USER ERROR
	MOVEM	S1,.JERRO(R)	;SAVE ERROR CODE FOR END
CLOS.0:
IFN	FTUUOS,<		;NOT NEEDED ON -20  USE LGOUT JSYS
	TLNE	R,RL.FCI	;HIT EOF WHILE LOOKING FOR FIRST CHARACTER
	TLNN	J,JL.UML	;IS JOB AT MONITOR LEVEL
	  PUSHJ	P,INMO.1	;JUNK SENT OR AT USER LEVEL, GET TO THE MONITOR
>;END FTUUOS
	PUSHJ	P,CHKCLS	;CHECK IF A CLOSE/DUMP IS NEEDED
	PUSHJ	P,ATOKJB	;PERFORM THE AUTO KJOB

CLOS.1:: TLNN	R,RL.FLS	;FLUSHING THE JOB
	PUSHJ	P,CTLDIS	;DISPOSE OF THE CTL FILE (MAYBE)
CLOS.3:	PUSHJ	P,REMCTL	;REMOVE ANY OLD CTL FILE ASSIGNMENTS
				;DELSPL MUST FOLLOW CTL SINCE IT USES .JQCFD(R)
	PUSHJ	P,DELSPL	;REMOVE ANY SPOOLED FILES FOR THIS JOB
	MOVEI	S1,REL.FD	;GET MINIMUM RELEASE MESSAGE
	PUSHJ	P,MSGQSR	;SETUP MESSAGE TO QUASAR
	MOVX	T2,<INSVL.(REL.FD,MS.CNT)!INSVL.(.QOREL,MS.TYP)>
	MOVEM	T2,.MSTYP(S2)	;STORE LENGTH AND TYPE
	MOVE	T2,.JQITN(R)	;TASK NAME GIVEN BY QUASAR
	MOVEM	T2,REL.IT(S2)	;STORE IT
	MOVE	T2,.JJOBN(R)	;GET THE JOB NUMBER
	MOVE	T3,.JQLFP(R)	;GET THE LOG FILE BITS
	TXNE	T3,FP.DEL	;TO BE DELETED
	  TXO	T2,RL.DLG	;YES, SET A BIT
	TXNE	T3,FP.SPL	;SPOOLED FILE
	   TXO	T2,RL.SPL!RL.DLG ;SET SPL AND DEL.ALWAYS DELETE SPOOL FILES
	TLNE	R,RL.FLS	;FLUSHING THE JOB
	JRST	CLOS.D		;YES..IGNORE OUTPUT REQUESTS FOR LOG
	GETLIM	T3,.JQLIM(R),OUTP	;GET OUTPUT VALUE
	CAIN	T3,%EQOLG	;PRINT THE LOG
	  JRST	CLOS.8		;YES..PRINT THE LOG
	CAIN	T3,%EQOLE	;OR PRINT IT IF AN UNHANDLED ERROR
	TRNN	F,FR.UHE	;YES..WAS THERE AN UNHANDLED ERROR
	   JRST	CLOS.D		;NEITHER, DON'T REQUEST PRINTING
CLOS.8:	MOVEM	T2,REL.BJ(S2)	;STORE FLAGS AND JOB NUMBER

IFN FTUUOS,<
	MOVE	T2,.JQLFD+.FDSTR(R)	;GET THE LOG FILE STRUCTURE
	CAMN	T2,[SIXBIT/NUL/]	;HAVE I BEEN WRITING ON NUL:
	  JRST	CLOS.6		;YES, SKIP THE SPEC
>  ;END IFN FTUUOS

IFN FTJSYS,<
	MOVE	T2,.JQLFD+.FDFIL(R)	;GET LOG FILE DEVICE WORD
	AND	T2,[-1,,777400]	;WAS IT NUL:
	CAMN	T2,[ASCII /NUL:/]	;IS IT "NUL"?
	JRST	CLOS.6		;YES, IGNORE ALL OF THIS
>  ;END IFN FTJSYS

	HRLI	T2,.JQLFD(R)	;GET SOURCE OF BLT
	HRRI	T2,REL.FD(S2)	;GET DESTINATION OF BLT
	LOAD	T3,.JQLFD+.FDLEN(R),FD.LEN
	LOAD	T4,.MSTYP(S2),MS.CNT ;GET LENGTH OF THE MESSAGE
	ADD	T4,T3		;ADD LENGTH OF THE FD
	STORE	T4,.MSTYP(S2),MS.CNT ;STORE MESSAGE LENGTH
	ADDI	T3,-1(T2)		;COMPUTE END OF BLT
	BLT	T2,0(T3)		;BLT THE FD FOR THE LOG

CLOS.6:	TRNN	F,FR.LFO	;WAS LOG FILE OPEN
	JRST	CLOS.C		;NO..DO NOT RELEASE
	PUSHJ	P,L$OUTP##	;FORCE OUT THE DATA
	MOVE	S1,.JLJFN(R)	;LOG FILE JFN
	$CALL	F%REL		;CLOSE THE FILE
	SKIPT			;CONTINUE IF O.K.
	PUSHJ	P,CLOS.E	;NOTE THE ERROR AND CONTINUE
	TRZ	F,FR.LFO	;MARK LOG FILE AS CLOSED
CLOS.C:	PUSHJ	P,CLOS.M		;SEND CLOSE MESSAGE
	PUSHJ	P,CLRSTR	;CLEAN UP STREAM
	PUSHJ	P,SNDQSR	;SEND ANSWER TO QUASAR
	JRST	STEXIT		;EXIT FROM STREAM
CLOS.4:	PUSHJ	P,L$BLNK##	;GET A BLANK LINE BEFORE THE MESSAGE
	PUSHJ	P,L$CMNT##	;PREPARE THE LOG FILE FOR A COMMENT
	$TEXT	(L$OUT1,<BTNECF End of Control File while searching for ^A>)
	JRST	CLOS.5		;ADD THE LABEL AND AUTO KJOB THIS JOB

CLOS.D:	MOVEM	T2,REL.BJ(S2)	;SAVE FLAGS IN RELEASE MESSAGE
	TRNN	F,FR.LFO	;WAS LOG FILE OPEN
	JRST	CLOS.C		;NO..IGNORE DELETE
	TXNN	T2,RL.DLG	;DELETE THE LOG FILE
	JRST	CLOS.6		;JUST RELEASE THE JOB AND LOG
	MOVE	S1,.JLJFN(R)	;GET LOG FILE JFN
	$CALL	F%DREL		;DELETE AND RELEASE LOG FILE

	SKIPT			;CONTINUE IF O.K.
	PUSHJ	P,CLOS.E	;NOTE THE ERROR AND CONTINUE
	TRZ	F,FR.LFO	;CLEAR LOG FILE OPEN FLAG
	JRST	CLOS.C		;FINISH OFF THE STREAM

CLOS.E:	$WTO	(<BATCON Log Error>,<^I/JIBTXT/^I/LOGERR/>,.JQOBJ(R),<$WTNOD(.JQLOC(R))>)
	POPJ	P,		;RETURN

CLOS.M:	MOVEI	T1,[ASCIZ/End/]	;ENDED NORMALLY MESSAGE
;	TLNE	F,FL.ERR		;ANY ERRORS
;	MOVEI	T1,[ASCIZ/Enderr/]	;YES..HAD ERRORS
	MOVEI	S2,[ITEXT(<
-- Job ^I/@ERRTAB(T2)/ -->)]
	SKIPN	T2,.JERRO(R)	;GET ERROR CODE IF ANY
	MOVEI	S2,NULTXT		;NULL FIELD
CLOS.J:	$WTOJ	(<^T/(T1)/>,<^R/.JQJBB(R)/^I/(S2)/>,.JQOBJ(R),<$WTNOD(.JQLOC(R))>)
	POPJ	P,			;RETURN
	SUBTTL	QSRUPD	--	UPDATE DEVICE STATUS TO QUASAR

	;THIS ROUTINE WILL SEND QUASAR A DEVICE STATUS MESSAGE
	;CALLED WITH T1/ STATUS CODE

QSRUPD:	MOVEI	S1,STU.SZ		;GET STATUS SIZE
	PUSHJ	P,MSGQSR		;SETUP MESSAGE TO QUASAR
	MOVEM	T1,STU.CD(S2)		;SAVE THE CODE
	MOVE	S1,[STU.SZ,,.QOSTU]	;GET HEADER WORD
	MOVEM	S1,.MSTYP(S2)		;STORE IN MESSAGE
	MOVSI	S1,.JQTYP(R)		;GET SOURCE TYPE FROM STREAM
	HRRI	S1,STU.RB(S2)		;DESTINATION,,RESPONSE TYPE
	BLT	S1,STU.RB+OBJ.SZ-1(S2)	;MOVE TYPE,UNIT,NUMBER
	PJRST	SNDQSR			;SEND TO QUASAR AND RETURN
	SUBTTL	IDNOPR	--	IDENTIFY LINE TO OPERATOR
IDNOPR:	PUSHJ	P,L$BLNK##	;OUTPUT A BLANK LINE
	IDENT	[ASCIZ/ BAOPR	/] ;IDENTIFY THIS LINE
	POPJ	P,		;RETURN
CRLF:	ASCIZ /
/

MESDEL:	MOVE	S1,.JMLST(R)		;GET LIST NAME
	$CALL	L%PREM			;GET REMEMBERED ENTRY
	SKIPE	T1,IPC.CD(S2)		;GET THE ACTION CODE
	PUSHJ	P,QSRUPD		;SEND UPDATED STATUS TO QUASAR
	MOVE	S1,.JMLST(R)		;GET LIST NUMBER
	PJRST	L%DENT			;DELETE AND RETURN

;HERE TO PROCESS OPERATOR REQUEST TO REQUEUE THIS JOB

	;***PROCESS THE REASON INFO TO LOG...
REQUJB:
IFN	FTUUOS,<
	;NOT NEEDED ON THE -20 BECAUSE OF LGOUT JSYS
	PUSHJ	P,INMO.1		;PUT AT MONITOR LEVEL
>;END FTUUOS
	PUSHJ	P,IDNOPR		;IDENTIFY BAOPR MESSAGE
	PUSHJ	P,JOBOUT		;CHECK AND SEND JOB MESSAGE
	$TEXT	(L$OUT1,<Job Requeued By Operator>)
	PUSHJ	P,L$BLK1##		;SEND BLANK CR,LF..NO TIME STAMP
	MOVX	S1,RQ.HBO		;HELD BY OPERATOR FOR REQUEUE
	MOVEM	S1,.JREQI(R)		;SAVE REQUEUE FLAG WORD
	MOVEI	S1,E.ROPR		;REQUEUED BY OPERATOR
	MOVEM	S1,.JERRO(R)		;SAVE CODE FOR END
	MOVX	S1,<BA.ORQ!BA.JOB>	;OPERATOR REQUEUE
	IORM	S1,.JCHRQ(R)		;SAVE IN CHECKPOINT WORDS
REQEXT:	PUSHJ	P,REQMSG		;SET JOB FOR LOGOUT
	MOVX	S1,REQ.SZ		;REQUEUE MESSAGE SIZE
	PUSHJ	P,MSGQSR		;SETUP MESSAGE TO QUASAR
	MOVE	S1,[REQ.SZ,,.QOREQ]	;HEADER WORD
	MOVEM	S1,.MSTYP(S2)		;SAVE IN MESSAGE
	MOVE	S1,.JREQI(R)		;GET REQUEUE FLAG WORD
	IORM	S1,REQ.FL(S2)		;SAVE IN REQUEUE FLAG WORD
	MOVE	S1,.JQITN(R)		;THE TASK NAME
	MOVEM	S1,REQ.IT(S2)		;STORE
	HRLI	S1,.JINFO(R)		;CHECKPOINT/REQUEUE INFORMATION
	HRRI	S1,REQ.IN(S2)		;INTO THE MESSAGE
	BLT	S1,REQ.IN+<EQCKSZ-1>(S2)  ;MOVE ALL THE WORDS
	PUSHJ	P,SNDQSR		;SEND IT TO QUASAR
	PUSHJ	P,CLRSTR		;CLEAN UP STREAM
	PJRST	STEXIT			;EXIT FROM STREAM
	SUBTTL	CANCJB--CANCEL A JOB ROUTINE

CANCJB:
IFN	FTUUOS,<
	;NOT NEEDED ON THE -20 BECAUSE OF LGOUT JSYS
	PUSHJ	P,INMO.1		;PUT AT MONITOR LEVEL
>;END FTUUOS
	PUSHJ	P,IDNOPR	;PUT OUT BAOPR LINE
	MOVE	S1,.JMLST(R)	;GET LIST NAME
	$CALL	L%PREM		;GET REMEMBERED ENTRY
	MOVE	T2,S2		;GET MESSAGE ADDRESS
	SETZB	T3,T4		;CLEAR T3 AND T4
	SKIPN	P1,IPC.DA+.OARGC(T2)	;ANY ARGUMENT LEFT
	JRST	CANC.3		;NO..DEFAULT BOTH
	MOVE	S1,IPC.AR(S2)	;GET ARGUMNET POINTER
CANC.1:	LOAD	T1,ARG.HD(S1),AR.TYP	;GET ARGUMENT TYPE
	CAIN	T1,.CANTY		;TYPE FIELD
	JRST	CANC.4			;YES..PROCESS TYPE
	CAIN	T1,.ORREA		;REASON FIELD
	JRST	CANC.5			;YES..SETUP POINTER
CANC.2:	LOAD	T1,ARG.HD(S1),AR.LEN	;GET ARGUMENT LENGTH
	ADD	S1,T1			;BUMP TO NEXT ARGUMENT
	SOJG	P1,CANC.1		;PROCESS ARGUMENTS
CANC.3:	SKIPN	T3			;ANY ERROR TYPE GIVEN
	MOVX	T3,.CNERR		;ERROR PROCESSING
	SKIPN	T4			;ANY REASON
	MOVEI	T4,[ASCIZ/No Reason Given/]
	HLLZ	T1,CANCTB-1(T3)		;GET ERROR FLAGS
	IORM	T1,R			;PLACE IN R
	HRRZ	T3,CANCTB-1(T3)		;GET THE TEXT FOR ERROR TYPE
	MOVEI	S1,E.COPR		;CANCELED BY THE OPERATOR
	MOVEM	S1,.JERRO(R)		;SAVE CODE FOR END MESSAGE
	$TEXT	(L$OUT1,<Job Aborted By Operator with ^T/(T3)/>)
	$TEXT	(CANC.6,<			REASON:	^T/(T4)/>)
	PUSHJ	P,L$CRLF		;PUT CR.LF AND SETUP FOR TIMESTAMP
	TLO	F,FL.SPL		;WANT TO ADD TEXT
	MOVEI	S1,CANTXT		;GET CANCEL TEXT ARGUMENTS
	PUSHJ	P,MSGOUT		;SEND THE MESSAGE
	PUSHJ	P,MESDEL	;DELETE THE ENTRY
	TLNE	R,RL.JIE	;CHECK IF JOB IN ERROR
	  JRST	HONO.0		;YES, JIE IS SET, RESUME WITH THE CTL FILE
	TRO	F,FR.UHE	;AN UNEXPECTED CONDITION
	JRST	CLOSJB		;GO KILL THE JOB
CANC.4:	SKIPG	T3,ARG.DA(S1)		;VALID ERROR TYPE
	MOVEI	T3,.CNERR		;ASSUME ERROR PROCESSING
	CAILE	T3,.CNPRG		;WITHIN RANGE
	MOVEI	T3,.CNERR		;ASSUME ERROR PROCESSING
	JRST	CANC.2			;CHECK NEXT ARGUMENT
CANC.5:	MOVEI	T4,ARG.DA(S1)		;GET ADDRESS OF REASON
	JRST	CANC.2			;PROCESS ARGUMENTS

CANTXT:	ITEXT	(<
^T/(T4)/ with ^T/(T3)/>)

CANC.6:	PUSHJ	P,L$OUT1##		;OUTPUT THE CHARACTER
	CAIE	CH,CHR.LF		;HIT A LINE FEED
	$RETT				;RETURN
	PUSHJ	P,L$2TAB##		;SEND TWO TABS
	PUSHJ	P,L$2TAB##		;SEND TWO TABS
	$RETT				;RETURN

	;TABLE OF CANCEL OPTIONS AND FLAGS

CANCTB:	XWD	RL.JIE,[ASCIZ/Error-Processing/]
	XWD	0,[ASCIZ/Noerror-Processing/]
	XWD	RL.FLS,[ASCIZ/Purge/]
	SUBTTL	STOPJB AND CONTJB ROUTINES

STOPJB:	TLNE	R,RL.STP		;STOPPED ALREADY?
	JRST	STOP.1			;YES..GIVE ERROR MESSAGE
	PUSHJ	P,GJBSTS		;GET CURRENT STATUS
	TLNN	R,RL.LGI		;IS JOB LOGGING IN NOW
	TLNE	J,JL.UDI!JL.UJC		;INPUT ,,OR JACCT SET
	JRST	STOP.0			;BYPASS CHECK
	TRO	F,FR.SCC		;SENT ^C TO STOP JOB
	PUSHJ	P,INMO.1		;PUT AT MONITOR LEVEL
STOP.0:	PUSHJ	P,IDNOPR		;IDENTIFY OPERATOR LINE
	PUSHJ	P,JOBOUT		;SEND JOBMSG
	$TEXT	(L$OUT1,<Job Stopped By Operator>)
	SETOM	.JRTIM(R)		;MARK TIME STAMP NEEDED
JUSTCL:	TLO	R,RL.STP		;STREAM STOPPED
	TLZ	R,RL.MIP		;CLEAR MESSAGE IN PROGRESS
	JRST	QTS			;WAIT FOR CONTINUE
STOP.1:	PUSHJ	P,JOBOUT		;OUTPUT THE MESSAGE DATA
	JRST	JUSTCL			;SET FLAGS AND EXIT

	;ROUTINE TO SEND JOBMSG TO OPERATOR

JOBOUT:	MOVE	S1,.JMLST(R)		;GET LIST NUMBER
	$CALL	L%PREM			;GET REMEMBERED ENTRY
	MOVE	T2,S2			;PLACE ADDRESS IN T2
	PUSHJ	P,MSGOUT		;SEND THE MESSAGE
	PJRST	MESDEL			;DELETE THE ENTRY AND RETURN
	SUBTTL	CONTJB--CONTINUE JOB BY OPERATOR
CONTJB:	TLZN	R,RL.STP		;STOPPED ..CLEAR
	JRST	CONT.1			;MUST ACK MESSAGE
					;IN CASE IN OPER WAIT
	IDENT	[ASCIZ / BAOPR	Job Continued By Operator
/]
	SETOM	.JRTIM(R)		;SET TIME-STAMP NEEDED
	TRNN	F,FR.SCC		;SENT ^C TO JOB
	JRST	CONT.1			;NO..SKIP CONTINUE TO JOB
	MOVEI	CH,MONCHR		;MONITOR CHARACTER TO LOG
	PUSHJ	P,L$PLOG##		;OUTPUT THE CHARACTER
	$TEXT	(LOGPTY,<CONTINUE>)	;SEND CONTINUE TO JOB
	SETOM	.JRTIM(R)		;NEED A TIME STAMP
	PUSHJ	P,PTYSND		;SEND THE BUFFER
CONT.1:	TLZ	R,RL.MIP		;CLEAR MESSAGE IN PROGRESS
	PUSHJ	P,JOBOUT		;SEND JOBMSG 
	JRST	QTS			;CONTEXT SWITCH AND SCHEDULE


	;QTS IS CALLED TO EXIT FROM STOP AND CONTINUE IN CASE JOB
	;IS STILL IN WAITING FOR THE OPERATOR
	SUBTTL	CANUSR--CANCEL FROMA USER REQUEST

;HERE TO PROCESS USER REQUEST TO KILL THE JOB

CANUSR:
IFN	FTUUOS,<
	;NOT NEEDED ON THE -20 BECAUSE OF LGOUT JSYS
	PUSHJ	P,INMO.1		;PUT AT MONITOR LEVEL
>;END FTUUOS
	MOVE	S1,.JMLST(R)	;GET THE MESSAGE LIST
	$CALL	L%PREM		;GET PREVIOUS REMEMBERED ENTRY
	MOVEI	T2,IPC.DA(S2)	;GET ADDRESS OF MESSAGE
	PUSHJ	P,L$BLNK##	;FORCE OUT BLANK LINE
	IDENT	[ASCIZ/ BAUSR	Job Canceled by User /]
	$TEXT	(L$OUT1,<^P/ABO.ID(T2)/^A>)		;KILLERS PPN
	MOVEI	S1,E.CUSR	;CANCELED BY THE USER
	MOVEM	S1,.JERRO(R)	;SAVE FOR END MESSAGE
	MOVE	S1,ABO.ID(T2)	;GET PPN OR USER NUMBER
	MOVEM	S1,.JARG1(R)	;SAVE ARGUMENT ONE FOR MESSAGE
	PUSHJ	P,L$BLNK##	;ISOLATE THE LINE
	TLO	R,RL.FCI	;SET A FLAG FOR CLOSJB
	TLZ	R,RL.JIE	;AVOID THE CLOSE/DUMP PAIR
	TRO	F,FR.UHE	;AN UNEXPECTED CONDITION
	PUSHJ	P,MESDEL	;DELETE THE MESSAGE
	JRST	CLOSJB		;CANCEL IT NOW
	SUBTTL	ATOKJB	--	LOGOUT FOR THE -10

IFN	FTUUOS,<
ATOKJB:: PUSHJ	P,GJBSTS	;GET CURRENT STATUS
	TLNN	J,JL.ULI	;IS JOB LOGGED IN
	POPJ	P,		;NO..RETURN
	TLZ	F,FL.SIL	;CLEAR SILENCE IF WE ARE GOING TO KJOB THIS JOB
	PUSHJ	P,PREKJB	;SET UP FOR AUTO LOGOUT
	PUSHJ	P,INMONM	;MAKE SURE THE JOBS IN MONITOR MODE
	SKIPE	.JRTIM(R)	;NEED A TIME STAMP
	  PUSHJ	P,L$LPER##	;YES, OUTPUT (SOMETHING), THAT WILL STAMP IT
KJOB.0:	TLNN	J,JL.ULI	;IS THE JOB THERE NOW
	  POPJ	P,		;NO, THAT WAS EASY
	TLO	R,RL.KJB	;MARK ON THE WAY OUT
	MOVEI	S1,""""		;GET A QUOTE
	DPB	S1,LDOPCH	;SET AS DIALOGUE MODE SIGNAL
	$TEXT	(LOGPTY,<^T/KJSTR/>)	;SEND KJOB STRING 
KJOB.1:	SETOM	.JRTIM(R)	;FORCE TIME STAMP TO ALIGN
	PUSHJ	P,PTYSND	;SEND TO THE PTY
KJOB.W:	PUSHJ	P,IODISP	;WAIT FOR RETURN TO MONITOR MODE
	TLNN	J,JL.ULI	;DID THE JOB GO AWAY
	  POPJ	P,		;YES..RETURN
KJOB.2:	TLZ	R,RL.DIA	;NO, CLEAR OUTPUT TO THE OPERATOR
	PUSHJ	P,INMO.1	;GET BACK TO MONITOR MODE
	$WTOR	(<BATCH Logout Error>,<^I/JIBTXT/^I/LGOTXT/>,.JQOBJ(R),.JQITN(R))
	PUSHJ	P,OPRRES	;WAIT FOR THE RESPONSE
	JRST	KJOB.0		;SEE IF JOB IS STILL THERE (OR TRY AGAIN)

>;END FTUUOS

LGOTXT:	ITEXT	(<Unable to LOGOUT Batch Job # ^D/.JJOBN(R)/
Please Kill the Job and then
RESPOND (message number) GO>)
	SUBTTL	ATOKJB	--	LOGOUT FOR THE -20

IFN	FTJSYS,<
ATOKJB:: PUSHJ	P,GJBSTS		;GET CURRENT STATUS
	TLNN	J,JL.ULI		;IS USER LOGGED IN
	  POPJ	 P,			;NO..JUST RETURN
	TLO	R,RL.KJB		;SET FOR KJOB
	TLZ	F,FL.SIL		;CLEAR THE SILENCE
	PUSHJ	P,L$CRLF		;GET TO NEW LINE
	MOVE	S1,.JJOBN(R)		;GET THE JOB NUMBER
	LGOUT				;LOG OUT THE JOB
	  JFCL				;IGNORE ERRORS
	PUSHJ	P,INPPTY		;GET PTY OUTPUT FIRST
	JUMPF	KJOB.0			;NO INPUT BYPASS JOB CHECK
	PUSHJ	P,GJBSTS		;GET CURRENT STATUS
	TLNN	J,JL.ULI		;IS USER LOGGED IN
	  POPJ	 P,			;NO..JUST RETURN
KJOB.0:	PUSHJ	P,WAITOU		;WAIT FOR OUTPUT
	TLNN	J,JL.ULI		;USER STILL LOGGED IN
	  POPJ	P,			;NO..RETURN
	$WTOR	(<BATCH Logout Error>,<^I/JIBTXT/^I/LGOTXT/>,.JQOBJ(R),.JQITN(R))
	PUSHJ	P,OPRRES		;WAIT FOR THE RESPONSE
	JRST	KJOB.0			;SEE IF JOB IS STILL THERE (OR TRY AGAIN)
>;END FTJSYS
	SUBTTL	IOWAIT	--	Routine for Output/Input Waiting

IOW.01:	PUSHJ	P,QTS		;WAIT FOR NEXT WAKE UP
IOW.02:
IFN	FTJSYS,<
	SKIPN	.JFLAG(R)	;ANY INTERRUPT OCCUR
	PJRST	IOW.01		;NO..WAIT AGAIN
	TRO	F,FR.STS	;SET UPDATE STATUS FROM INTERRUPT FLAG
>;END FTJSYS

IOWAIT:	PUSHJ	P,GJBSTS	;GET THE STATUS OF THE JOB

IOW.03:	TLNN	J,JL.UDI!JL.UOA	;JOB WANT INPUT OR HAS OUTPUT
	  JRST	IOW.01		;NO, GO BACK AND WAIT
	TLNN	J,JL.UOA	;WAS IT OUTPUT AVAILABLE
	  JRST	[TLNE F,FL.SIL	;JOB WANTS INPUT, IN SILENCE MODE
		  SETOM .JRTIM(R) ;YES, KEEP OUTPUT ALIGNED
		TRZ	F,FR.STS ;CLEAR STATUS FLAG
		 POPJ P,]	;RETURN TO THE CALLER
	PUSHJ	P,INPPTY	;INPUT THE BUFFER
READPY:	PUSHJ	P,GETPTY	;GET CHARACTER FROM PTY
	JUMPT	READ.0		;PROCESS THE INPUT
IFN	FTJSYS,<
	TLZ	J,JL.UOA	;CLEAR OUTPUT AVAILABLE FLAG
	MOVSI	S1,JL.UDI	;GET INPUT FLAG
	TLNE	J,JL.UDI	;IS IT SET?
	IORM	S1,.JFLAG(R)	;HOLD FOR INTERRUPT?
>;END FTJSYS
	JRST	IOWAIT		;CHECK STATUS AGAIN
READ.0:	AOSE	.JREOL(R)	;HAS A LINE TERMINATOR BEEN SENT
	SKIPE	.JRTIM(R)	;OR IS THIS THE FIRST CHARACTER OF A LINE
	  PUSHJ	P,ERRCHK	;YES, CHECK FOR ERROR INDICATORS
	TLNE	R,RL.JIE	;DID ERRCHK FIND AN ERROR
	  TLZ	F,FL.SIL	;YES, CLEAR SILENCE FOR THIS JOB
	TLNE	R,RL.QTS!RL.DIA	;SHOULD THE OPERATOR SEE THIS CHARACTER
	  JRST	[MOVE S1,CH	;GET CHARACTER IN S1
		PUSHJ P,OUTDAT	;OUTPUT CHARACTER
		JRST .+1]	;CONTINUE IN LINE
	TLNE	F,FL.SIL	;IS THE JOB OUTPUT TO BE SUPPRESSED
	  JRST	READ.2		;YES, DON'T INCLUDE IN THE LOG FILE
	PUSHJ	P,L$PLOG##	;ECHO THE CHARACTER
READ.1:	SKIPN	.JRTIM(R)	;END OF LINE SENT?
	JRST	READPY		;CONTINUE READING
	TLZE	R,RL.QTS	;DOING QUOTES
	PUSHJ	P,OUTEXT	;END WTO
	JRST	READPY		;CONTINUE READING
READ.2:	SETZM	.JRTIM(R)	;CLEAR TIME STAMP NEEDED
	CAIG	CH,CHR.FF	;DO VERTICAL PAPER MOTION CHECK HERE
	CAIGE	CH,CHR.LF	;SO ERRCHK CAN BE CALLED EVEN IF SILENCE IS SET
	  JRST	READ.1		;NOT ONE OF LF,VT,FF RESUME NORMAL PATH
	SETOM	.JRTIM(R)	;SET TIME STAMP TO RECOGNIZE COLUMN 1
	JRST	READ.1		;RESUME
	SUBTTL	WAITOU	--	WAIT FOR OUTPUT BEFORE PROCEEDING

	;THIS ROUTINE WILL WAIT FOR OUTPUT BEFORE CONTINUING
	;INORDER TO GIVE JOB A CHANCE TO GET SCHEDULED ON -20

IFN	FTJSYS,<
WAITOU:	SETZM	.JWAIT(R)		;CLEAR WAIT COUNT ***
WAIT.1:	PUSH	P,.JLPTR(R)		;GET OUTPUT POINTER
	AOS	.JWAIT(R)		;BUMP THE COUNT
	PUSHJ	P,QTS			;OUTPUT RETURNED
	PUSHJ	P,IODISP		;WAIT FOR I/O, RETURN FOR MORE INPUT
	POP	P,S1			;PLACE POINTER IN S1
	CAMN	S1,.JLPTR(R)		;ANY OUTPUT HAPPEN
	JRST	WAIT.1			;NO..TRY AGAIN TILL SOMETHING HAPPENS
	PUSHJ	P,GJBSTS		;GET LATEST STATUS
	MOVE	S1,.JWAIT(R)		;GET THE COUNT
	ADDM	S1,JOBWCT		;WAIT COUNT TOTALS
	$RETT				;RETURN TRUE
>;END FTJSYS
;HERE TO CHECK PTY OUTPUT FOR ERROR INDICATORS/QUOTES/DIALOGUE MODE

ERRCHK:	CAIE	CH,"?"		;STANDARD ERROR CHARACTER
	  JRST	ERRC.2		;NO, LOOK FOR ADDITIONAL CHARACTER
	TLNE	R,RL.LGI	;HERE DURING LOGIN SEQUENCE
	  JRST	ERRLGI		;YES, GET LOGIN ERROR CODE
	PUSHJ	P,GJTIML	;GET SUBJOBS REMAINING TIME LIMIT
	JUMPN	S1,ERRC.1	;JUMP IF NOT TIME LIMIT EXCEEDED
	TLOA	F,FL.TLE	;SET THE TIME LIMIT FLAG
ERRC.1:	 TLNN	F,FL.NER	;IGNORE ERRORS ?
	  TLO	R,RL.JIE	;NOPE (OR TIME LIMIT EXCEEDED), SET ERROR IN JOB
	JRST	ERRC.3		;AVOID DUPLICATE WORK
ERRC.2:	TLNE	F,FL.NER	;IGNORE ERRORS ?
	  JRST	ERRC.3		;YES, LOOK FOR QUOTES, OPERATOR
	LDB	S1,LDERCH	;LOAD THE ERROR CHARACTER INTO S1
	CAIN	CH,(S1)		;IS THIS THE ONE
ERRC.4:	  TLO	R,RL.JIE	;YES, SET ERROR FLAG
ERRC.3:	LDB	T1,LDOPCH	;GET THE DIALOGUE MODE SIGNAL
	CAIN	CH,(T1)		;IS THIS IT
	  TLO	R,RL.DIA	;YES, SET JOB IN DIALOGUE MODE
	CAIN	CH,""""		;IS IT A COMMENT TO THE OPERATOR
	  TLO	R,RL.QTS	;YES, SET QUOTES MODE
	SKIPN	.JWTOF(R)	;WTO FLAG SET..IN MIDDLE OF WTO
	TLNN	R,RL.QTS!RL.DIA	;NEED TO IDENTIFY THE OUTPUT TO THE OPERATOR
	  POPJ	P,		;NO, RETURN
	PJRST	STAWTO		;YES,,TYPE OUT SUBJOB INFORMATION NOW
;HERE TO GET THE ERROR CODE FROM LOGIN IN THE FORM ?(n)LGNxxx message

ERRLGI:	PUSHJ	P,L$PLOG##	;SEND THE ?
	SETZ	S1,		;EVENTUAL ERROR CODE
IFN	FTJSYS,<
	TRZN	F,FR.JLI	;WAS JOB BEING SETUP FOR LOGIN 
	JRST	ERRL.2		;NO..JUST SET THE OTHER BITS
;*** TEMPORARY FIX FOR NOW
;	MOVSI	S1,JL.UDI	;GET USER DESIRES INPUT
;	IORM	S1,.JFLAG(R)	;SAVE AS HUNGRY TO FAKE FOR NOW
>;END FTJSYS

IFN FTUUOS,<
	PUSHJ	P,NXTPTY	;GET THE NEXT CHARACTER
	CAIE	CH,"("		;ERROR CODE FOLLOWS?
	  JRST	ERRSTO		;NO, STORE 0 AND RETURN
ERRL.1:	PUSHJ	P,L$PLOG##	;OUTPUT THE (
	PUSHJ	P,NXTPTY	;GET THE CODE NUMBER
	MOVEI	S2,-"0"(CH)	;CONVERT TO BINARY
	CAILE	S2,^D9		;WAS IT A DIGIT
	  JRST	ERRSTO		;NO, STORE ERROR SO FAR AND RETURN
	IMULI	S1,^D10		;POSITION OTHER DIGITS
	ADDI	S1,(S2)		;INCLUDE THIS DIGIT
	JRST	ERRL.1		;ECHO THIS DIGIT AND GET MORE
ERRSTO:	CAIN	S1,1		;IS IT LOGIN ERROR # 1
	  POPJ	P,		;YES, THATS A WARNING, EXIT NOW
>  ;END OF IFN FTUUOS

ERRL.2:	TLO	R,RL.JIE	;INDICATE JOB IN ERROR
	HRRM	S1,.JERCD(R)	;STORE THE ERROR CODE
	POPJ	P,		;RETURN TO INLINE CODE
	SUBTTL	Job Processor - Error Analysis, Processing, and Reporting

;HERE TO INTERROGATE THE LOGIN FAILURE

ANALYZ:

IFN FTUUOS,<
	TLNE	R,RL.JNA	;DID A JOB NUMBER EVER GET ASSIGNED
	  JRST	ANLY.1		;YES, LOOK AT THE ERROR CODE
ANLY.0:	TLNE	J,JL.ULI	;USER LOGGED IN NOW
	  POPJ	P,		;YES, THAT'S INCONSISTENT
	JRST	ANLY.4		;OUR ERROR SEND SETUP RETRY
				;GO REQUEUE THIS JOB
ANLY.1:	HRRZ	S1,.JERCD(R)	;GET THE ERROR CODE FROM LOGIN
	CAIE	S1,4		;IS THE SYSTEM AVAILABLE
	  JRST	ANLY.2		;YES, LOOK FURTHUR
	TLNE	J,JL.ULI	;IS THE USER LOGGED IN NOW
	  POPJ	P,		;THAT TOO IS INCONSISTENT
	JRST	ANLY.4		;SETUP RETRY,,LATER
ANLY.2:	CAIN	S1,5		;LOGMAX EXCEEDED
	  JRST	ANLY.0		;YES, TREAT AS "JOB CAPACITY EXCEEDED"
	CAIN	S1,2		;IS IT JOB SEMI-FATAL
	  JRST	ANLY.4		;YES, REQUEUE THE JOB
	PUSHJ	P,SNDUPC	;SEND ^C TO KILL JOB SLOT
>  ;END OF IFN FTUUOS
IFN	FTJSYS,<
	TLNE	J,JL.ULI		;USER LOGGED IN NOW
	  POPJ	P,			;YES..JUST RETURN
	MOVX	S1,EQ.IAS		;GET INVALID ACCOUNT FLAG
	TDNN	S1,.JQJBB+JIB.SQ(R)	;CHECK IF SET
	  PJRST ANLY.4			;YES..ASSUME NO JOB SLOTS AND REQUEUE
>;END FTJSYS

ANLY.3:	PUSHJ	P,L$OUTP##	;OUTPUT PAGE OF DATA
	JUMPF	LOGEXT		;FAIL..EXIT AND FLUSH
	TLNE	J,JL.ULI	;ALL OTHERS KLUNK THE JOB, IS IT LOGGED IN NOW
	  JRST	CLOSJB		;YES, LEAVE JIE SET AND KILL THE JOB
	PUSHJ	P,L$BLNK##		;LOG A BLANK LINE
	$WTO(<Batch Login Error>,<BATCH Login Failed .. Job Canceled>,.JQOBJ(R),<$WTNOD(.JQLOC(R))>)
	IDENT	[ ASCIZ / BTNJBC	Job has been Canceled -- LOGIN FAILURE
/]
	MOVX	S1,E.JLOF	;JOB LOGIN FAILURE
	MOVEM	S1,.JERRO(R)	;SAVE THE ERROR CODE
	TLO	F,FL.ERR	;MARK THE ERROR CONDITION
	PUSHJ	P,L$BLK1	;CR,LF NO TIME-STAMP
	JRST	CLOS.1		;AND DISMISS THE JOB

ANLY.4:	PUSHJ	P,L$BLNK##	;OUTPUT A BLANK LINE
	IDENT	[ASCIZ / BTNJRQ	JOB REQUEUED
/]
	MOVEI	S1,E.NJOB	;NO JOBS AVAILABLE
	MOVEM	S1,.JERRO(R)	;SAVE THE ERROR CODE
	PUSHJ	P,L$BLK1	;CR,LF NO TIME-STAMP
	PUSHJ	P,REQMSG	;PREPARE TO CLOSE JOB,,FOR REQUEUE
	PUSHJ	P,CLRSTR	;CLEAN UP THE STREAM
	MOVX	T1,%RSUNA	;SETUP UNAVAILABLE
	MOVEI	T2,E.NJOB	;NO JOBS AVAILABLE
	MOVX	T3,%SFULL	;SYSTEM FULL..NO JOB SLOTS
	PUSHJ	P,SETUPR	;SEND SETUP..RETRY
	JRST	STEXIT		;EXIT FROM STREAM

;	SUBROUTINE TO CLOSE OUT JOB BEFORE REQUEUE OF JOB TO QUASAR
REQMSG:	PUSHJ	P,REMCTL	;REMOVE AND CTL ASSIGNMENTS
	TLNE	J,JL.ULI	;IS THE JOB LOGGED IN NOW
	  PUSHJ P,ATOKJB	;KILL THE JOB
	TRNN	F,FR.LFO	;WAS LOG FILE OPEN
	POPJ	P,		;NO LOG FILE..JUST RETURN
	PUSHJ	P,L$OUTP##	;OUTPUT PAGE OF DATA
	MOVE	S1,.JLJFN(R)	;GET LOG FILE IFN
	$CALL	F%REL		;RELEASE THE IFN
	SKIPT			;O.K..SEND MESSAGE AND RETURN
	PJRST	CLOS.E		;NOTE ERROR AND CONTINUE
	TRZ	F,FR.LFO	;CLEAR LOG FILE OPEN
REQM.1:	PJRST	CLOS.M		;SEND END MESSAGE AND RETURN
	SUBTTL	Job Processor - Random Little Routines

;SUBROUTINE TO GET JOB STATUS AND SET BITS AS NEEDED

GJBSTS:	PUSHJ	P,JOBSTS	;GET JOB STATUS FOR JOB
	MOVEM	J,.JSTAT(R)	;SAVE FOR BATOPR IF IT WANTS IT
	SKIPG	.JJOBN(R)	;IS THERE A JOB NUMBER STORED
	  HRREM	J,.JJOBN(R)	;NO, SAVE THIS ONE FOR RELEASE OPERATION
	TLNE	J,JL.UJA	;USER JOB NUMBER ASSIGNED
	  TLO	R,RL.JNA	;YES, REMEMBER IT GOT AT LEAST THAT FAR
	POPJ	P,		;RETURN TO CALLER

;SUBROUTINE TO SEND 'SET TIME N' TO THE JOB

SETTIM:	SKIPE	.JRTIM(R)	;NEED TO ALIGN THE OUTPUT
	  PUSHJ	P,L$LPER##	;YES, OUTPUT A DOT (OR SOMETHING)
	$TEXT	(LOGPTY,<^T/TIMSTR/^D/.JQLIM+1(R),RHMASK/^A>)
	PUSHJ	P,SNDCLF	;SEND CR-LF AND FORCE BUFFER
	JRST	IODISP		;WAIT FOR NEXT INPUT BEFORE RETURNING
	SUBTTL	SETLOC	--	SET JOB LOCATION FOR THE -20

	;THIS ROUTINE WILL SET THE JOBS LOCATION IF IT IS NOT THE CENTRAL SITE
	

IFN	FTJSYS,<
SETLOC:	MOVE	S1,.JQLOC(R)		;GET THE OUTPUT NODE
	CAMN	S1,MYNODE		;IS IT SAME AS MINE?
	POPJ	P,			;YES..JUST RETURN
	SETZB	T3,T4			;CLEAR T3 AND T4
	MOVE	T1,[POINT 6,.JQLOC(R)]	;GET THE LOCATION
	MOVE	T2,[POINT 7,T3]		;PLACE TO STORE STRING
	MOVEI	P1,6			;MAXIMUM LENGTH
SETL.1:	ILDB	S2,T1			;GET A BYTE
	JUMPE	S2,SETL.2		;O.K. SET THE LOCATION
	ADDI	S2,40			;CONVERT TO ASCII CHARACTER
	IDPB	S2,T2			;SAVE THE BYTE
	SOJG	P1,SETL.1		;CHECK NUMBER OF CHARACTERS
SETL.2:	MOVE	S1,.JJOBN(R)		;GET THE JOB NUMBER
	MOVX	S2,.SJLLO		;SETUP LOCATION
	HRROI	T1,T3			;GET STRING
	SETJB				;SET IT UP
	ERJMP	.+1			;IGNORE ERROR FOR NOW
	POPJ	P,			;RETURN
>;END FTJSYS
;SUBROUTINE TO PLACE A JOB IN OPERATOR WAIT

OPRRES:	TLO	R,RL.OPR	;MARK WAITING FOR THE OPERATOR
	MOVX	T1,%OREWT	;STATUS CODE TO QUASAR
	PUSHJ	P,QSRUPD	;UPDATE STATUS TO QUASAR
	PUSHJ	P,QTS		;WAIT FOR HIS(HER) RESPONSE
	MOVX	T1,%RESET	;RESET STATUS TO QUASAR
	PUSHJ	P,QSRUPD	;SEND IT TO QUASAR
	JRST	GJBSTS		;GET THE STATUS AND RETURN

;SUBROUTINE TO COPY A COMMENT LINE TO THE LOG FILE

CPYCMT:	TLNE	F,FL.SIL	;IS THE OUTPUT TO BE SUPPRESED
	  JRST	CMNT.3		;YES, DONT OUTPUT COMMENT LINES EITHER
	CAIE	CH,CHR.FF	;SEE IF THE FIRST CHARACTER IS FF OR VT
	CAIN	CH,CHR.VT	;IF SO, THEN A ONE CHARACTER COMMENT LINE
	  JRST	[SETZM .JRTIM(R)	;CLEAR TIME STAMP NEEDED
		JRST L$PLOG##]	;OUTPUT FORM FEED OR VERTICAL TAB AND RETURN
CMNT.0:	PUSH	P,CH		;SAVE FIRST CHARACTER
	PUSHJ	P,L$CMNT##	;PREPARE LOG FILE FOR A COMMENT
	POP	P,CH
CMNT.1:	SKIPE	.JRTIM(R)	;DID ONE OF CHARACTER MOVE PAPER
	  JRST	CMNT.0		;YES, START A FRESH COMMENT LINE
	PUSHJ	P,L$PLOG##	;DEPOSIT INTO THE LOG FILE
	TLNN	F,FL.PLS	;DOING A PLEASE COMMAND
	  JRST	CMNT.2		;NO, AVOID THE FOLLOWING
	CAIE	CH,CHR.A1	;IS IT AN ALTMODE
	  JRST	CMNT.5		;NO, JUST OUTPUT THIS CHARACTER
	TLZ	F,FL.PLS	;YES, CLEAR PLEASE COMMAND
	MOVEI	CH,"$"		;ECHO THE ALTMODE AS A $
CMNT.5:	MOVE	S1,CH		;PUT CHARACTER IN S1
	PUSHJ	P,OUTDAT	;PLACE CHARACTER IN MESSAGE
CMNT.2:	CAIN	CH,CHR.LF	;END OF A LINE YET
	  POPJ	P,		;YES, RETURN TO READING OF CTL FILE
	PUSHJ	P,GETCTL	;GET ANOTHER CHARACTER
	JRST	CMNT.1		;CONTINUE COPYING
CMNT.3:	CAIE	CH,CHR.FF	;DOES THE LINE START WITH A FORM FEED
	CAIN	CH,CHR.VT	;OR A VERTICAL TAB
	  POPJ	P,		;YES, THAT IS A ONE CHARACTER COMMENT LINE
CMNT.4:	CAIN	CH,CHR.LF	;END OF THE COMMENT LINE YET
	  POPJ	P,		;YES, RETURN TO CALLER
	PUSHJ	P,GETCTL	;GET ANOTHER CHARACTER TO IGNORE
	JRST	CMNT.4		;ANY SEE IF DONE YET
;SUBROUTINE TO PUT A JOB INTO MONITOR MODE

INMONM:
IFN	FTJSYS,<
	PUSHJ	P,GJBSTS	;GET CURRENT STATUS
>;END FTJSYS
	TLNE	J,JL.UML	;IS IT ALREADY THERE
	  POPJ	P,		;YES, RETURN
INMO.1:	TLNN	J,JL.ULI	;IS THE USER STILL LOGGED IN
	POPJ	P,		;NO..RETURN
	TLNN	J,JL.UDI	;NO, IS IT IN INPUT WAIT
INMO.2:	  PUSHJ	P,SNDUPC	;NO, SEND 2 CONTROL C'S
	PUSHJ	P,SNDUPC
	PUSHJ	P,IODISP	;WAIT FOR RESPONSE
IFN	FTJSYS,<
	PUSHJ	P,GJBSTS	;GET STATUS
>;END FTJSYS
	TLNE	J,JL.UML	;IS IT NOW AT MONITOR LEVEL
	  POPJ	P,		;YES, RETURN
;	PUSHJ	P,SNDUPC	;JUST TO MAKE SURE
	AOS	INMONE		;BUMP MONITOR MODE ERROR COUNT
	PUSHJ	P,IODISP		;CONTEXT SWITCH
IFN	FTJSYS,<
	PUSHJ	P,GJBSTS	;GET STATUS
>;END FTJSYS
	TLNE	J,JL.UML	;IS IT NOW AT MONITOR LEVEL
	  POPJ	P,		;YES, RETURN
	TRZE	F,FR.TBL	;TROUBLE GETTING TO MONITOR LEVEL
	JRST	INMO.3		;YES..BEEN HERE..CLEANUP
	$WTO(<Batch Monitor Level Error>,<^I/JIBTXT/Batch Job ^D/.JJOBN(R)/ Having trouble getting to
 Monitor Level J = ^O/J/ .. Will Try Again>,.JQOBJ(R))
	TRO	F,FR.TBL	;SET IN TROUBLE FLAG
	PUSHJ	P,QTS		;STALL FOR TIME
	JRST	INMO.2		;TRY AGAIN
INMO.3:	$WTO(<Batch Fatal Monitor Level Error>,<^I/JIBTXT/Batch Job ^D/.JJOBN(R)/ Can Not Get to Monitor Level
Retry Failed J = ^O/J/>,.JQOBJ(R))
	TLNN	J,JL.ULI	;IS THE JOB STILL THERE
	  JRST	CLOS.1		;NO, DISMISS THE JOB
	JRST	INMONM		;YES, TRY TO DO IT AGAIN

;SUBROUTINE TO SKIP BLANKS(TABS) IN THE CTL FILE

SKPBL1:	PUSHJ	P,GETCTL	;ENTER HERE IF CH IS NOT SET AT THE FIRST
SKPBLK:	CAIE	CH," "		;A BLANK
	CAIN	CH,CHR.HT	;OR A TAB
	  JRST	SKPBL1		;SKIP OVER THEM
	POPJ	P,		;RETURN WITH THE FIRST NON-BLANK CHARACTER
	SUBTTL	CHANNEL RELEASE ROUTINES FOR PTYS
;HERE TO RELEASE THE A CHANNEL AND ASSIGNMENT

IFN FTUUOS,<
RELREL:	MOVE	S1,[RELEASE 0,0]	;RELEASE THE CHANNEL
	IOR	S1,.JPCHN(R)		;PUT CHANNEL NUMBER IN PLACE
	XCT	S1			;EXECUTE RELEASE UUO
	POPJ	P,			;AND RETURN
>  ;END IFN FTUUOS

IFN FTJSYS,<
RELREL:	MOVE	S1,.JPCHN(R)	;PTY JFN
	CLOSF			;CLOSE THE PTY AND RELEASE JFN
		JRST	ERRPRT	;PTY CLOSE ERROR
	POPJ	P,		;RETURN
>  ;END OF IFN FTJSYS


IFN	FTUUOS,<
SETSFD:	SKIPN	1(T4)		;ANY SFD SPECIFICATION
	  JRST	[MOVE T4,(T4)	;NO SET D TO PPN
		TLNN  T4,-1	;IS PPN = XWD 0,#
		 HRLOI T4,377777 ;YES...SOMEONE MADE A BAD QUEUE FILE
		POPJ	P,]	;AND RETURN
	HRLI	T4,(T4)		;SOURCE OF THE PATH
	HRRI	T4,SFDPAT+2	;TO THE PATH BLOCK
	BLT	T4,SFDPAT+7	;MOVE THE WHOLE SPEC
	MOVEI	T4,SFDPAT	;POINT TO IT FOR UUOS
	POPJ	P,		;RETURN
>;END FTUUOS
GETCTL:	TRNN	F,FR.CTO	;IS CTL FILE OPEN
		PUSHJ	P,FNDCTL ;NO..OPEN IT
	MOVE	S1,.JCJFN(R)	;GET CTL JFN
	$CALL	F%IBYT		;GET A BYTE FROM FILE
	JUMPF	GETCT1		;END OF CONTROL FILE..EXIT
	JUMPE	S2,GETCTL	;IGNORE NULLS
	MOVE	CH,S2		;PUT IN CH FOR COMPATIBILITY
	JRST	GETCT4		;CHECK OTHER CONDITIONS
GETCT1:	JRST	CLOSJB		;END OF CTL..END JOB
;HERE TO CONVERT UPARROWS TO CONTROL CHARACTERS (MAYBE)

GETCT4:	TLZN	F,FL.UPA	;HERE THE SECOND TIME FOR THIS CALL
	CAIE	CH,"^"		;NO, IS THIS AN UPARROW
	  POPJ	P,		;RETURN WITH THIS CHARACTER
	TLO	F,FL.UPA	;MARK RECURSIVE CALL
	PUSHJ	P,GETCTL	;GET THE NEXT AFTER THE UPARROW
	CAIN	CH,"^"		;TWO IN A ROW
	  POPJ	P,		;YES, RETURN ONLY ONE
	CAIG	CH,172		;CONVERT TO UPPER CASE
	CAIGE	CH,141
	  SKIPA			;NOT A LOWER CASE LETTER
	SUBI	CH," "		;MAKE UPPER CASE OUT OF IT
	CAIG	CH,137		;NOW SEE IF THIS CHAR CAN BE A CONTROL CHAR
	CAIGE	CH,"A"
	  JRST	GETCT5		;NO, MUST BACK SOME STUFF UP
	SUBI	CH,100		;MAKE A CONTROL CHARACTER
	POPJ	P,		;RETURN WITH IT
GETCT5:	PUSHJ	P,DECRBP	;BACK UP OVER THE OTHER CHARACTER
	MOVEI	CH,"^"		;GET THE ORIGINAL UPARROW
	POPJ	P,		;AND RETURN WITH IT
	SUBTTL	CONTROL FILE MANIPULATION ROUTINES
;SUBROUTINE TO PERFORM POST JOB DISPOSAL OF THE CTL FILE
CTLDIS:	TRNN	F,FR.CTO	;CONTROL FILE OPEN??
	POPJ	P,		;NO,,FORGET THIS
	LOAD	S1,.JQCFP(R),FP.DEL	;GET DELETE CTL FLAG
	JUMPE	S1,CPOPJ	;0..DO NOT DELETE..EXIT
	MOVE	S1,.JCJFN(R)	;GET JFN FOR CTL
	$CALL	F%DREL		;RELEASE JFN AND DELETE FILE
	TRZ	F,FR.CTO	;CLEAR CONTROL FILE OPEN FLAG
	POPJ	P,		;RETURN

;HERE TO REMOVE ANY OLD CTL FILE ASSIGNMENTS AT DISMISSAL OF THE JOB

REMCTL:	TRNN	F,FR.CTO	;CHECK IF CTL STILL OPEN
	POPJ	P,		;NO ,,,EXIT
	MOVE	S1,.JCJFN(R)	;GET THE FILE JFN
	$CALL	F%REL		;CLOSE AND RELEASE CTL FILE
	TRZ	F,FR.CTO	;CLEAR CONTROL FILE OPEN FLAG
	POPJ	P,		;RETURN
	SUBTTL TOPS-20 POSITIONING ROUTINES

SAVPOS:	TRNN	F,FR.CTO	;CHECK IF FILE OPEN
		JRST	SAVP.1	;NO SPECIAL CASE
	MOVE	S1,.JCJFN(R)	;GET CTL JFN
	$CALL	F%CHKP		;TAKE CHECKPOINT
	MOVEM	S1,.JCUSI(R)	;SAVE RELATIVE POSITION
	POPJ	P,		;RETURN TO PROCESSING
SAVP.1:	TLO	F,FL.UPA		;GET EXACTLY ONE CHARACTER
	PUSHJ	P,FNDCTL	;OPEN FILE
	SETZM	.JCUSI(R)	;POSITION TO BEGINNING
	POPJ	P,		;RETURN TO MAINLINE

REPOSI:	MOVE	S1,.JCJFN(R)	;GET JFN FOR CTL
	MOVE	S2,.JCUSI(R)	;GET RELATIVE POSITION
	$CALL	F%POS		;POSITION FILE TO PROPER PLACE
	POPJ	P,		;RETURN TO MAINLINE

DECRBP:	MOVE	S1,.JCJFN(R)	;GET CTL JFN
	$CALL	F%CHKP		;CHECKPOINT THIS POSITION
	MOVE	S2,S1		;RELATIVE POSITION INTO S2
	MOVE	S1,.JCJFN(R)	;GET CTL JFN
	SUBI	S2,1		;BACK UP 1 PLACE
	$CALL	F%POS		;POSITION FILE TO PROPER PLACE
	POPJ	P,		;RETURN
	SUBTTL	FNDCTL--OPEN CONTROL FILE ROUTINE
FNDCTL:	MOVEI	S1,.JQCFD(R)		;GET FD FOR CTL
	MOVEM	S1,.JCFOB+FOB.FD(R)	;STORAGE AREA
	MOVX	S1,FB.LSN		;NO LINE SEQ NUMBERS
	ADDI	S1,7			;PLACE BYTE SIZE IN S1
	MOVEM	S1,.JCFOB+FOB.CW(R)	;SAVE CONTROL WORD
IFN	FTJSYS,<
	HRROI	S1,.JQNAM(R)		;USER NAME FROM CREATE
	HRROI	S2,.JQCON(R)		;CONNECTED DIRECTORY
>;END FTJSYS
IFN	FTUUOS,<
	MOVE	S1,.JQPPN(R)		;GET PPN FOR USER
	MOVEI	S2,0			;MAKE ZERO FOR CONSISTENCY
>;END FTUUOS
	MOVEM	S1,.JCFOB+FOB.US(R)	;SAVE USER IN BEHALF
	MOVEM	S2,.JCFOB+FOB.CD(R)		;SAVE IN FOB
	MOVEI	S1,FOB.SZ		;SIZE OF THE BLOCK
	MOVX	T1,EQ.PRV		;GET PRIVILEGE FLAG
	TDNE	T1,.JQJBB+JIB.SQ(R)	;WAS IT SET
	MOVEI	S1,FOB.MZ		;YES.. NO IN BEHALF NEEDED
	MOVEI	S2,.JCFOB(R)		;ADDRESS OF THE BLOCK
	$CALL	F%IOPN			;OPEN THE FILE
	JUMPF	FNDC.E			;ERROR EXIT
	MOVEM	S1,.JCJFN(R)		;SAVE CTL JFN
	TRO	F,FR.CTO		;TURN ON OPEN CTL BIT
	POPJ	P,			;AND RETURN FOR NORMAL READING

FNDC.E:	PUSHJ	P,L$BLNK##		;GET BLANK LINE
	IDENT	[ASCIZ / BATCFE	/]	;IDENTIFY LINE
	$TEXT	(L$OUT1,<^E/[-1]/...^F/.JQCFD(R)/>)	;LAST ERROR
	IDENT	[ASCIZ / BATBJC	Batch Job has been Canceled
/]
	SETZM	.JRTIM(R)		;NO TIME STAMP
	PUSHJ	P,L$CRLF##		;SEND CR AND LF
	PJRST	CLOSJB		;CLOSE THE JOB OUT
	SUBTTL	INPPTY--PTY INPUT ROUTINES
IFN FTUUOS,<
INPPTY:	MOVE	S1,[INPUT 0,0]	;SETUP FOR INPUT UUO
	IOR	S1,.JPCHN(R)	;PUT CHANNEL INTO INSTRUCTION
	XCT	S1		;EXECUTE INPUT
	POPJ	P,
>  ;END IFN FTUUOS

IFN FTJSYS,<

INPPTY:	MOVE	S1,.JPTTY(R)		;TTY FOR PTY
	SOBE				;CHECK OUTPUT BUFFER
		JRST	INPP.1		;YES..GET IT
	$RETF				;NO RETURN
INPP.1:	MOVEM	S2,EE			;SAVE COUNT FOR SIN
	MOVE	S1,.JPLSO(R)		;LINK LIST NUMBER
	$CALL	L%LAST			;POSITION TO THE END
	MOVE	S1,.JPLSO(R)		;LIST NUMBER
	MOVE	S2,EE			;GET CHARACTER COUNT
	IDIVI	S2,5			;CONVERT TO WORDS
	ADDI	S2,3			;3 WORDS 2 HEADER 1 FOR TEXT
	;MEMORY OPTIMIZATION BY USING MINIMUM SIZE BLOCK
	CAIGE	S2,ALCSIZ-3		;GREATER OR EQUAL TO MINIMUM SIZE
	MOVEI	S2,ALCSIZ-3		;ALLOW FOR LIB OVERHEAD
	$CALL	L%CENT			;CREATE ENTRY
	MOVE	S1,.JPCHN(R)		;PTY JFN 
	MOVE	T2,S2			;SAVE ADDRESS OF BLOCK
	HRLI	S2,440700		;LEFT HALF BYTE POINTER
	HRRI	S2,2(T2)		;ADDRESS IN RIGHT HALF
	MOVEM	S2,(T2)			;SAVE POINTER IN WORD 0
	MOVE	T1,EE			;COUNT TO READ
	MOVEM	T1,1(T2)		;SAVE COUNT IN FIRST WORD
	SIN				;READ THE DATA
;*** ERJMP
	MOVE	S1,.JPTTY(R)		;GET TTY NUMBER(PTY)
	SOBE				;ANY MORE DATA
		JRST INPP.1		;YES GO GET IT
	$RETT				;GIVE GOOD RETURN
	>  ;END OF IFN FTJSYS
	SUBTTL	SEND PTY OUTPUT TO JOB

SNDUPC:	MOVEI	CH,CHR.CC	;SET A ^C
	PUSHJ	P,PUTPTY	;SEND THE ^C AND FALL INTO FORCE THE BUFFER

IFN FTUUOS,<
PTYSND:	MOVE	S1,[OUTPUT 0,0]	;OUTPUT TO THE PTY
	IOR	S1,.JPCHN(R)	;PUT CHANNEL NUMBER IN PTY
	XCT	S1		;EXECUTE THE OUTPUT
	POPJ	P,
>  ;END IFN FTUUOS

IFN FTJSYS,<
PTYSND:	PUSH	P,S1		;SAVE S1
	PUSH	P,S2		;SAVE S2
	PUSHJ	P,HLFDUP	;INSURE LINE IS HALF-DUPLEX
	MOVE	S1,.JPCHN(R)	;PTY JFN
	HRROI	S2,.JPTYO(R)	;POINTER TO OUTPUT AREA
	SKIPGE	T1,.JPOUT+2(R)	;CHECK IF LESS THAN ZERO
	SETZ	T1,		;YES,,MAK ZERO
	SUBI	T1,PTYBLK*PTYBFR*5  ;GET NEGATIVE COUNT
PTYSN1:	SOUT			;OUTPUT TO THE PTY
	ERJMP	PTYSN2		;OUTPUT FAILED ?
	MOVEI	S1,PTYBLK*PTYBFR*5 ;BUFFER SIZE
	MOVEM	S1,.JPOUT+2(R)	;RESTORE BUFFER COUNT
	MOVE	S1,[POINT 7,.JPTYO(R)] ;BYTE POINTER FOR PTY OUT
	MOVEM	S1,.JPOUT+1(R)	;RESTORE POINTER
	POP	P,S2		;RESTORE S2
	POP	P,S1		;RESTORE S1
	POPJ	P,		;RETURN

PTYSN2:	MOVX	S1,.FHSLF	;GET OUR PROCESS HANDLE
	GETER			;GET LAST ERROR CODE
	HRRZS	S2		;KEEP ONLY THE ERROR CODE
	CAIE	S2,IOX33	;OUTPUT FAILED BECAUSE PTY BUFFER FULL ?
	  $STOP	(OPF,Output to PTY failed)
	PUSHJ	P,QTS		;YES - TRY AGAIN LATER
	MOVE	S1,.JPCHN(R)	;GET PTY JFN
	HRROI	S2,.JPTYO(R)	;POINT TO OUTPUT AREA
	JRST	PTYSN1		;GO OUTPUT A BUFFER
>  ;END OF IFN FTJSYS
	SUBTTL	GETPTY--GET A CHARACTER FROM PTY INPUT BUFFER

IFN FTUUOS,<

GETPTY:	SOSGE	.JPINP+2(R)	;IS THERE A CHARACTER
	  $RETF			;GIVE FALSE RETURN
	ILDB	CH,.JPINP+1(R)	;GET THE NEXT
	JUMPN	CH,.RETT	;NOT A NULL, GIVE GOOD RETURN
	JRST	GETPTY		;IGNORE NULLS
>  ;END IFN FTUUOS

IFN FTJSYS,<
GETPTY:	MOVE	S1,.JPLSO(R)		;LIST NUMBER
	$CALL	L%FIRS			;POSITION TO FIRST
	JUMPF	.POPJ			;ERROR..PASS SAME CODE
GETP.1:	SOSGE	1(S2)			;DECREMENT COUNT IN BUFFER
	JRST	GETP.2			;CHECK FOR MORE
	ILDB	CH,(S2)		;GET BYTE FROM BUFFER
	JUMPE	CH,GETP.1		;SKIP NULLS
	$RETT				;GIVE GOOD RETURN
GETP.2:	MOVE	S1,.JPLSO(R)		;LIST NUMBER
	$CALL	L%DENT			;DELETE THE ENTRY
	MOVE	S1,.JPLSO(R)		;GET NEXT ELEMENT
	$CALL	L%NEXT			;GET NEXT ENTRY
	JUMPF	.POPJ			;ERROR RETURN..PASS ERROR BACK
	JRST	GETP.1			;GO GET CHARACTER
>  ;END OF IFN FTJSYS
	SUBTTL	PUTPTY--PUT CHARACTERS INTO PTY OUTPUT BUFFER
PUTPTY:
IFN	FTJSYS,<
	CAIN	CH,CHR.LF	;IS IT A LINE FEED
	TRNN	F,FR.SLF	;ARE WE SKIPPING LINE FEED
	TRZA	F,FR.SLF	;CLEAR THE FLAG
	POPJ	P,		;RETURN..(HAD A LINE FEED)
	CAIN	CH,CHR.CR	;IS IT A CARRIAGE RETURN
	TRO	F,FR.SLF	;YES SET FLAG TO SKIP LF TO PTY
>;END FTJSYS

	SOSGE	.JPOUT+2(R)	;IS BUFFER FULL
	  JRST	PUTP.1		;YES, SEND THE BUFFER
	IDPB	CH,.JPOUT+1(R)	;STORE IT
	POPJ	P,
PUTP.1:	PUSHJ	P,PTYSND	;SEND THIS BUFFER TO THE JOB
	SETOM	.JREOL(R)	;FAKE AN EOL SENT SO ANY ERRORS CAN BE FOUND
	PUSH	P,CH		;SAVE THE CHARACTER I WANT TO SEND
	PUSH	P,S1		;SAVE OTHER REGS ALSO
	PUSH	P,S2		;...
	PUSHJ	P,IOWAIT	;AND WAIT UNTIL THE JOB WANT'S MORE INPUT
	SKIPE	.JRTIM(R)	;IS TIME STAMP NEEDED?
	TLNE	F,FL.SIL	;YES, BUT ARE WE SILENCED
	  SKIPA			;DON'T OUTPUT A TIME STAMP
	PUSHJ	P,L$LSTP##	;OUTPUT ONE BEFORE RESTORING S1 AND S2
	SETZM	.JREOL(R)	;CLEAR THE FLAG JUST IN CASE IT'S LEFT ON
	POP	P,S2		;RESTORE
	POP	P,S1		;...
	POP	P,CH		;RESTORE THE CHARACTER TO SEND
	JRST	PUTPTY		;NOW STORE IT INTO THE BUFFER
;SUBROUTINE TO SEND A STRING POINTED TO BY 'S1' TO THE JOB

UUOSND:	HRR	T1,.JBUUO##	;ENTER HERE IF FROM UUO CALL
SNDSTR:	HRLI	T1,(POINT 7,0)	;MAKE A BYTE POINTER OUT OF IT
	ILDB	CH,T1		;GET ONE
	JUMPE	CH,CPOPJ	;IS AN ASCIZ STRING
	PUSHJ	P,SNDCHR	;SEND IT AND ECHO
	JRST	SNDSTR+1	;LOOP ON THE STRING

;SUBROUTINE TO SEND <CR>-<LF> AND FORCE OUT THE BUFFER

SNDCLF:	MOVEI	CH,CHR.CR	;A CARRIAGE RETURN
	PUSHJ	P,SNDCHR	;SEND THE CHARACTER
	MOVEI	CH,CHR.LF	;A LINE FEED
	PUSHJ	P,SNDCHR	;SEND IT TOO
	JRST	PTYSND		;SEND THE BUFFER AND RETURN

;SUBROUTINE TO SEND CH TO PTY AND JOB

SNDCHR:	PUSHJ	P,PUTPTY	;PUT INTO THE OUTPUT BUFFER
	CAIN	CH,CHR.LF	;WAS THAT THE LINE FEED I SENT
	  SETOM	.JREOL(R)	;YES, SET A FLAG FOR ERROR CHECKING
	TLNE	F,FL.SIL	;IS THE LINE TO BE SILENCED
	  POPJ	P,		;YES, EXIT NOW
	JRST	L$PLOG##	;ECHO IN THE LOG FILE
	SUBTTL	UUOCON--BATCON LUUO HANDLER

;BATCON UUO PROCESSOR

UUOCON:	HLRZ	IO2,.JBUUO##	;GET THE OPCODE
	LSH	IO2,-^D9	;POSITION IT
	CAILE	IO2,UUOCNT	;NUMBER OF KNOWN UUOS
	  JRST	UUOERR		;ILLEGAL UUO ?
	JRST	@UUOTBL-1(IO2)	;DISPATCH THE UUO
UUOTBL:	JRST	L$TXTL##	;OPCODE 001 - ASCIZ  TEXT TO THE LOG FILE
	JRST	UUOSND		;OPCODE 002 - ASCIZ  TEXT TO THE JOB
	JRST	L$SIXU##	;OPCODE 003 - SIXBIT TEXT TO THE LOG FILE
	JRST	L$IDEN##	;OPCODE 004 - IDENTIFIER TO THE LOG FILE
UUOCNT==.-UUOTBL		;NUMBER OF KNOWN UUOS

UUOERR:	$STOP(IBU,ILLEGAL BATCON UUO)
;SUBROUTINE TO CREATE A MASK INTO AC B FOR THE COMMAND IN AC S1

MASKIT:	MOVE	S2,S1		;COPY THE COMMAND
	SETO	T2,		;EVENTUAL MASK (COMPLEMENT FORM)
	LSH	T2,-6		;SHIFT THE MASK
	LSH	S2,6		;SHIFT THE COMMAND THE OTHER WAY
	JUMPN	S2,.-2		;CONTINUE UNTIL HAVE SHIFTED ALL THE CHARACTERS
	POPJ	P,		;RETURN WITH MASK IN B

;SUBROUTINE TO CHECK IF CHARACTER IN CH IS A LINE TERMINATOR

COMTRM:	CAIG	CH,CHR.FF	;LOOK FOR PAPER MOTION CHARACTERS
	CAIGE	CH,CHR.LF
	  SKIPA			;NO, LOOK FOR OTHERS
	POPJ	P,		;GIVE TERMINATOR RETURN
	CAIE	CH,CHR.CG	;^G
	CAIN	CH,CHR.CZ	;^Z
	   POPJ	P,		;RETURN
	CAIE	CH,CHR.A1	;IS IT THE STANDARD ALTMODE
	CAIN	CH,CHR.CC	;^C
	  POPJ	P,		;RETURN
	JRST	CPOPJ1		;NOT ONE OF THE ABOVE, NOT A TERMINATOR

;SUBROUTINE TO GET A SIXBIT COMMAND INTO S1

GETSIX:	MOVE	P2,[POINT 6,P1]	;POINTER TO THE STRING
	SETZ	P1,		;EVENTUAL DESTINATION
GETS.1:	PUSHJ	P,GETONE	;GET A CHARACTER
	  JRST	GETS.5		;STOP ON LINE TERMINATOR
	  JRST	GETS.2		;SPECIAL, CHECK FOR BLANKS
	  JRST	GETS.4		;DON'T INCLUDE LEADING NUMBERS
GETS.3:	SUBI	CH," "		;CONVERT TO SIXBIT
	TLNE	P2,770000	;ALREADY HAVE ENOUGH
	  IDPB	CH,P2		;NO, INCLUDE THIS CHARACTER
	JRST	GETS.1		;GET MORE INPUT
GETS.2:	CAIN	CH," "		;IS IT A BLANK
	  JUMPE	P1,GETS.1	;YES, IGNORE LEADING BLANKS
	TRNE	F,FR.%SG	;ARE % SIGNS VALID CHARACTERS
	CAIE	CH,"%"		;YES, WAS IT ONE
	  JRST	GETS.5		;RETURN IF SPECIAL OR BLANK AS TERMINATOR
	JRST	GETS.3		;INCLUDE THE % SIGN
GETS.4:	JUMPE	P1,GETS.5	;STOP IF THE NUMBER IS FIRST
	JRST	GETS.3		;INCLUDE IF AFTER THE FIRST
GETS.5:	MOVE	S1,P1		;PLACE WORD IN S1
	POPJ	P,		;RETURN
;SUBROUTINE TO GET A CHARACTER FORM THE COMMAND LINE
;CALL IS:
;	PUSHJ	P,GETONE
;	  HERE IF A LINE TERMINATOR
;	  HERE IF A SPECIAL CHARACTER
;	  HERE IF A NUMBER
;	  HERE IF A LETTER

GETONE:	TRZE	F,FR.RSC	;CALLER ALREADY HAVE CH
	  JRST	CLASSF		;YES, CLASSIFY IT AND GIVE IT BACK
	PUSHJ	P,GETCTL	;GET A CHARACTER FROM CONTROL FILE
	JUMPE	CH,GETONE	;THROUGH AWAY NULLS
	CAIN	CH,CHR.CR	;AND IGNORE CARRIAGE RETURNS
	  JRST	GETONE
	CAIN	CH,CHR.HT	;A TAB
	  MOVEI	CH," "		;YES, CONVERT TABS TO BLANKS
CLASSF:	CAIE	CH,CHR.CR	;CARRIAGE RETURN IF FROM BATCON LABEL PROCESSOR
	PUSHJ	P,COMTRM	;IS IT A LINE TRMINATOR
	  POPJ	P,		;RETURN
	CAIG	CH,"9"
	CAIGE	CH,"0"		;IS IT A DIGIT
	  SKIPA
	JRST	CPOPJ2		;YES, GIVE APPROPRIATE RETURN
	CAIG	CH,172		;LOWER CASE "Z"
	CAIGE	CH,141		;LOWER CASE "A"
	  SKIPA
	SUBI	CH," "		;MAKE UPPER CASE
	CAIG	CH,"Z"
	CAIGE	CH,"A"		;IS IT A LETTER
	  JRST	CPOPJ1		;NO, MUST BE A SPECIAL
CPOPJ3:	AOS	(P)		;LETTER EXIT
CPOPJ2:	AOS	(P)		;DIGIT EXIT
CPOPJ1:	AOS	(P)		;SPECIAL CHARACTER EXIT
CPOPJ:	POPJ	P,		;LOTS OF SKIP RETURNS
	SUBTTL	TABSRC	--	TABLE LOOKUP ROUTINE

;SUBROUTINE TO DO A TABLE LOOKUP FOR THE COMMAND IN S1
;ON CALL  A = XWD -COUNT , TABLE ADDRESS
;RETURNS  CPOPJ  IF NOT FOUND
;	  CPOPJ1 IF AMBIGUOUS
;	  CPOPJ2 IF A GOOD COMMAND  C = RELATIVE INDEX INTO THE TABLE

;CLOBBERS AC'S S2,A,B,C,D

TABSRC:	PUSHJ	P,MASKIT	;CREATE A MASK IN B
	SETZ	T3,		;CLEAR FOUND ONE INDICATOR
	MOVEI	T4,(T1)		;SAVE TABLE START ADDRESS
TABS.1:	MOVE	S2,(T1)		;GET ONE FROM THE TABLE
	CAMN	S1,S2		;AN EXACT MATCH
	  JRST	[MOVEI T3,(T1)	;YES, COMPUTE OFFSET
		JRST TABS.3]	;AND EXIT NOW
	ANDCM	S2,T2		;MASK TO AS MANY CHARS AS IN S1
	CAME	S1,S2		;FOUND A MATCH
	  JRST	TABS.2		;NO, CONTINUE SEARCH
	JUMPN	T3,CPOPJ1	;IF ALREADY FOUND ONE, GIVE AMBIGUOUS RETURN
	MOVEI	T3,(T1)		;SAVE ADDRESS OF THIS ONE
TABS.2:	AOBJN	T1,TABS.1	;LOOK FOR A MATCH
	JUMPE	T3,CPOPJ		;RETURN IF NEVER FOUND ONE
TABS.3:	SUBI	T3,(T4)		;COMPUTE RELATIVE OFFSET
	JRST	CPOPJ2		;GIVE LOTS OF SKIP RETURNS
SUBTTL	System Dependent Subroutines

;TO AVOID EXCESSIVE FEATURE TESTING IN THE MAIN CODE FOR TOPS10 OR TOPS20,
;	SYSTEM DEPENDENT SUBROUTINES ARE INCLUDED HERE, AS A SEPARATE SECTION.


;	GJTIML	GET SUBJOB (J) REMAINING TIME LIMIT INTO S1
;	ONCECN	SET UP ONCE ONLY CONSTANTS
;	PREKJB	SET UP FOR AUTO LOGOUT OF A JOB
;	CHKCLS	DETERMINE IF CLOSE/DUMP/UNHANDLED ERROR
;	SYSPRG	DETERMINE IF CURRENT PROGRAM CAME FROM SYS:.  USED FOR
;		%CERR:: OR %ERR:: DECISION
SUBTTL	TOPS10 Subroutines

IFN FTUUOS,<		;A LARGE FEATURE TEST FOR TOPS10 VERSION

;ROUTINES NOT NEEDED ON TOPS10

	DELSPL==CPOPJ	;NO SPOOLED FILES TO DELETE

;SUBROUTINE TO GET SUBJOB (J) REMAINING TIME LIMIT INTO S1

GJTIML:	HRL	S1,J		;GET THE JOB NUMBER
	HRRI	S1,.GTLIM	;THE LIMIT TABLE
	GETTAB	S1,		;GET THE JOB LIMIT WORD
	  JFCL			;BATCH NEEDS THAT TABLE
	TLZ	S1,777700	;CLEAR ALL BUT TIME REMAINING
	POPJ	P,		;RETURN WITH REMAINING LIMIT

;SUBROUTINE TO SET UP FOR AUTO LOGOUT ABOUT TO HAPPEN

PREKJB:	MOVE	T1,[2,,T2]	;SET FOR JBSET. UUO
	HRRZ	T2,J		;ADD THE JOB NUMBER
	MOVE	T3,[.STTLM,,^D30] ;GIVE SOME EXTRA TIME FOR KJOB
	JBSET.	T1,		;TRY TO PREVENT TIME EST EXCEEDED DURING KJOB
	  JFCL
	POPJ	P,		;AND RETURN

;SUBROUTINE TO SET UP ONCE ONLY CONSTANTS

ONCECN:	SETZ	S1,		;CLEAR S1 TO BE SAFE IF NO WHERE
	MOVSI	T1,'OPR'	;TEST IF SYSTEM HAS REMOTE STATION FEATURE
	WHERE	T1,		;BY SEEING IF THIS WHERE UUO FAILS
	  SKIPA			;IT DID, NO LOCATE COMMAND FOR NEW JOBS
	MOVX	S1,<B.REMT>	;SET REMOTE LOGIC AVAILABLE
	IORM	S1,FLAGS	;TURN ON THE FLAG
	SKIPN	CORCHK		;WANT CORE CHECKING?
	POPJ	P,		;NO..RETURN
	MOVE	S1,[%CNMMX]	;FIND OUT THE VALUE OF MINMAX
	GETTAB	S1,		;SO JOBS WITH /CORE:1K DON'T CONFUSE BATCON
	  MOVEI	S1,^D12*^D1024	;THIS IS THE VALUE SUGGESTED FOR 507 MONITORS
	LSH	S1,-^D9		;CONVERT TO PAGES
	MOVEM	S1,MINMAX	;SAVE FOR LATER
	POPJ	P,		;AND RETURN




	;;;FTUUO CONDITIONAL CONTINUED ON NEXT PAGE
;SUBROUTINE TO CHECK IF A CLOSE/DUMP COMMAND IS NEEDED

CHKCLS:	TLNN	R,RL.JIE	;IS THE JOB IN ERROR STATE
	  POPJ	P,		;NO, DON'T NEED THE CLOSE
	TRO	F,FR.UHE	;AN UNEXPECTED CONDITION
	PUSHJ	P,INMONM	;MAKE SURE THE JOBS IN MONITOR MODE
	SKIPE	.JRTIM(R)	;TIME STAMP NEEDED
	  PUSHJ	P,L$LPER##	;YES, SEND A PERIOD, THAT WILL TIME STAMP IT
	TXTJOB	[ASCIZ/CLOSE/]	;SEND THE CLOSE COMMAND
	PUSHJ	P,SNDCLF	;END THE LINE AND SEND THE BUFFER
	PUSHJ	P,IOWAIT	;WAIT UNTIL COMPLETE
	PUSHJ	P,SYSPRG	;DID PROGRAM COME FROM SYS
	  POPJ	P,		;YES, NO DUMP
	HRL	S1,J		;GET THE JOB NUMBER
	HRRI	S1,.GTPRG	;GET THE PROGRAM NAME
	GETTAB	S1,
	  POPJ	P,		;DON'T KNOW, NO DUMP
	JUMPE	S1,CPOPJ	;RUN OR GET ERROR, NO DUMP
	TXTJOB	[ASCIZ/DCORE .DMP/]	;NOW SEND THE DUMP COMMAND
	PUSHJ	P,SNDCLF	;END THE LINE
	PUSHJ	P,IOWAIT	;WAIT FOR NEXT INPUT REQUEST
	JRST	INMONM		;MAKE SURE AGAIN THEN RETURN TO CALLER

;SUBROUTINE TO DETERMINE IF PROGRAM CAME FROM SYS

SYSPRG:	HRL	S1,J		;GET THE JOB NUMBER
	HRRI	S1,.GTLIM	;GET THE JBTLIM TABLE
	GETTAB	S1,
	  POPJ	P,		;CAN'T GET IT, SAY YES
	TLNE	S1,(JB.LSY)	;CHECK GOTTEN FROM SYS BIT
	  POPJ	P,		;IT DID
	JRST	CPOPJ1		;A USER PROGRAM

;SUBROUTINE TO GET NEXT CHARACTER FROM THE PTY EVEN IF CROSSES A BUFFER

NXTPTY:	PUSHJ	P,GETPTY	;GET A CHARACTER
	  SKIPF			;BUFFER EMPTY REFILL IT
	POPJ	P,		;GOT ONE, TURN
	PUSHJ	P,QTS		;WAIT FOR NEXT WAKE-UP
	PUSHJ	P,INPPTY	;GET A FRESH BUFFER
	JRST	NXTPTY		;TRY NOW


>  ;;;END OF IFN FTUUOS
SUBTTL	TOPS20 Subroutines

IFN FTJSYS,<		;A LARGE FEATURE TEST FOR TOPS20 VERSION

;ROUTINES NOT NEEDED ON TOPS20

	SYSPRG==CPOPJ1	;ALL ERRORS TRAP TO %ERR::

;SUBROUTINE TO GET SUBJOB (J) REMAINING TIME LIMIT INTO S1

GJTIML:	MOVEI	S1,(J)		;GET THE JOB NUMBER
	HRROI	S2,S1		;ONE WORD INTO S1 (E.G. -1,,S1)
	MOVX	T1,.JIRTL	;A = S2 + 1, WANT RUN TIME LIMIT
	GETJI			;GET IT
	  SETO	S1,		;OH WELL!
	POPJ	P,		;RETURN WITH TIME IN S1

;SUBROUTINE TO SET UP ONCE ONLY CONSTANTS

ONCECN:	SETZM	MINMAX		;THERE IS NO SYSTEM MINIMUM
	MOVX	S1,RC%EMO	;EXACT MATCH ONLY
	HRROI	S2,[ASCIZ /PS:<SPOOL>/]
	RCDIR			;GET SPOOL DIRECTORY NUMBER
	MOVEM	T1,SPLNUM	;SAVE AWAY THE ANSWER
	MOVE	S1,[SIXBIT/PTYPAR/]	;GET NUMBER OF PTYS AVAILABLE
	SYSGT			;GET THE VALUE
	HRRM	S1,FIRPTY	;SAVE FIRST PTY NUMBER
	HLRM	S1,NUMPTY	;SAVE NUMBER OF PTYS IN SYSTEM
	HRRZI	S1,.MSIIC	;BYPASS MOUNT COUNTS
	MSTR			;DO THE FUNCTION
	ERJMP	.+1		;IGNORE ERROR FOR NOW
	SETOM	S1		;MY JOB
	MOVX	S2,JI.LOC	;GET MY LOCATION
	PUSHJ	P,I%JINF	;GET THE VALUE
	MOVEM	S2,MYNODE	;SAVE MY NODE
	MOVEI	S1,.FHSLF	;GET MY HANDLE
	MOVEI	S2,103		;SET THE PROPER QUEUES
	SPRIW			;SET THE PRIORITY WORD
	ERJMP	.+1		;IGNORE THE VALUE
	POPJ	P,		;AND RETURN

;SUBROUTINE TO DETERMINE IF AN UNHANDLED ERROR OCCURRED

CHKCLS:	TLNE	R,RL.JIE	;DID AN ERROR OCCUR
	  TRO	F,FR.UHE	;YES, AN UNEXPECTED CONDITION
	POPJ	P,		;NEVER DO CLOSE/DUMP
;HERE TO DELETE SPOOLED INPUT FILES:
;
;FILES ARE NAMED:
;	DSK:<SPOOL>CDR-XXX.CDYYYY.*

;WHERE XXX IS THE USER'S DIRECTORY NUMBER
;      YYYYY IS A STRING MADE OF THE JOBNAME CONCATENATED WITH A
;		RANDOM 4 CHARS CURRENTLY PASSED BY SPRINT IN .JQSIS.

DELSPL:	SKIPN	.JQSIS(R)		;IS THERE A SPOOLED INPUT NAME?
	POPJ	P,			;NO, JUST RETURN
	$TEXT	(<-1,,.JQCFD(R)>,<^T/SPLTXT/^O/.JQJBB+JIB.US(R),RHMASK/.^W/.JQSIS(R)/.*^0>)
	MOVX	S1,GJ%OLD!GJ%IFG!GJ%SHT	;LOAD GTJFN BITS
	HRROI	S2,.JQCFD(R)		;POINT TO FILE-NAME
	GTJFN				;GET A JFN
	  POPJ	P,			;FAILED, RETURN
	MOVE	T1,S1			;SAVE THE JFN
	JRST	DELS.2			;JUMP INTO THE LOOP

DELS.1:	GNJFN				;GET THE NEXT FILE
	  JRST	DELS.3			;DONE EXPUNGE THE AREA
DELS.2:	TLZ	S1,-1			;CLEAR LEFT HALF OF JFN WORD
	TXO	S1,DF%NRJ		;DONT RELEASE THE JFN
	DELF				;DELETE THE FILE
	  JFCL				;IGNORE THE ERROR
	MOVE	S1,T1			;RELOAD INDEXABLE JFN
	JRST	DELS.1			;GET THE NEXT ONE

DELS.3:	MOVEI	S1,0			;NO SPECIAL FLAGS
	MOVE	S2,SPLNUM		;GET DIRECTORY NUMBER OF <SPOOL>
	DELDF				;EXPUNGE IT
	ERJMP	.POPJ			;IGNORE ERROR..
	POPJ	P,			;AND RETURN
SPLTXT:	ASCIZ/PS:<SPOOL>CDR-/
>	;;;END OF FTJSYS
	SUBTTL	JOBSTS--JOB STATUS ON STREAM
IFN	FTUUOS,<
JOBSTS:	AOS	.JOBST(R)	;BUMP JOBSTS CALLED COUNT
	MOVE	J,.JPCHN(R)	;GET THE PTY CHANNEL NUMBER
	LSH	J,-^D23		;PLACE AS INDEX IN AC
	JOBSTS	J,		;GET THE STATUS
	  HALT	.		;;;BUG HALT
	POPJ	P,		;RETURN WITH J CONTAINING DATA
>;END FTUUOS

IFN FTJSYS,<
JOBSTS:	AOS	.JOBST(R)	;BUMP JOBSTS CALLED COUNT
	MOVEI	J,0		;CLEAR STATUS FLAG
	SETZM	.JJOBS+.JIUNO(R);CLEAR THE USER NUMBER FIELD
	SETZM	.JJOBS+.JIT20(R);CLEAR THE MONITOR LEVEL FLAG
	MOVE	S1,.JPTTY(R)	;TERMINAL NUMBER OF PTY
	HRLI	S2,-<.JIT20+1>	;COUNT OF ELEMENTS
	HRRI	S2,.JJOBS(R)	;LOCATION OF GETJI DATA
	MOVEI	T1,0		;START WITH 0
	GETJI			;GET JOB INFO
	  PUSHJ	P,ERRPRT	;ERROR EXIT
	SKIPE	.JJOBS+.JIUNO(R) ;IS USER LOGGED IN
	TLO	J,JL.ULI	;USER LOGGED IN SET
	TLO	J,JL.UML	;SET TO MONITOR LEVEL
	SKIPN	.JJOBS+.JIT20(R);CHECK MONITOR LEVEL FLAG
	TLZ	J,JL.UML	;MUST BE AT USER LEVEL
	SETZ	S1,		;SET FLAGS TO ZERO
	EXCH	S1,.JFLAG(R)	;GET THE CURRENT FLAGS AND RESET

; Since we can't trust the status returned on an interrupt, we have to ask
; the monitor if the PTY is really hungry.
;
JOBS.C:	TLZ	J,JL.UOA	;ANY OUTPUT READY
	MOVE	S1,.JPTTY(R)	;GET PTY NUMBER
	SOBE			;PTY HAVE OUTPUT FOR US
	TLO	J,JL.UOA	;YES OUTPUT AVAILABLE
JOBS.1:	SKIPGE	.JJOBS+.JIJNO(R) ;IS IT LOGGED IN
	JRST	JOBS.2		;SKIP CHECKING PTY HUNGRY
	TLZ	J,JL.UDI	;PTY IS HUNGRY ALREADY
	MOVE	S1,.JPCHN(R)	;GET PTY JFN
	MOVEI	S2,.MOPIH	;CHECK IF PTY HUNGRY
	MTOPR
	SKIPE	S2		;0 NOTHING,,-1 HUNGRY
JOBS.2:	TLO	J,JL.UDI	;PTY HUNGRY
	SKIPL	S1,.JJOBS+.JIJNO(R) 	;SKIP NO JOB NUMBER AVAILABLE
	TLO	J,JL.UJA	;JOB NUMBER AVAILABLE
	HRR	J,S1		;PLACE JOB NUMBER IN J
	POPJ	P,		;RETURN FOR NOW
>;END FTJSYS
	SUBTTL	TSLEEP--SLEEP ROUTINE FOR DISPATCH LOOP
IFN	FTUUOS,<
TSLEEP:	MOVX	S1,HB.IPC!HB.RPT ;SET IPCF AND PTY CONDITIONS
	SKIPE	CORCHK		;ARE WE CHECKING CORE
	HRRI	S1,^D60000	;YES..CHECK ONCE A MINUTE
	SKIPE	STACTV		;ANY STREAMS ACTIVE
	  HRRI	S1,^D15*^D1000	;YES, SET A TIMER FOR THE SLEEP
	HIBER	S1,		;TAKE A NAP
	  JFCL			;NICE TRY
	POPJ	P,		;RETURN FROM SLEEP
>;END FTUUOS
IFN	FTJSYS,<
TSLEEP:	MOVEI	S1,0		;SET INFINITE SLEEP
	SKIPE	STACTV		;ANY STREAMS ACTIVE
	MOVEI	S1,15		;YES..SLEEP FOR 15 SECONDS
	PJRST	I%SLP			;SLEEP AND WAKE ROUTINE
>;END FTJSYS
	SUBTTL	BATPSI--BATCON PSI ENABLE CODE
IFN FTJSYS,<
BATPSI:	CIS			;CLEAR INTERRUPT SYSTEM
	$CALL	I%ION			;ENABLE INTERRUPT SYSTEM
	MOVX	S1,.FHSLF		;PROCESS HANDLE
	MOVX	S2,<77B5+17777>		;ACTIVATE 0-5 AND 23-35
	AIC				;ACTIVATE THOSE CHANNELS
	POPJ	P,			;RETURN
>;END FTJSYS


IFN FTUUOS,<
BATPSI:	MOVE	S1,[VECTOR,,VECTOR+1]	;SETUP A BLT POINTER
	SETZM	VECTOR			;CLEAR THE FIRST WORD
	BLT	S1,ENDVEC		;CLEAR THE WHOLE THING
	MOVEI	S1,BATIPC		;GET ADDRESS OF IPCF INT RTN
	MOVEM	S1,VECIPC+.PSVNP	;SAVE IN VECTOR
	HRREI	T1,.PCIPC		;IPCF CONDITION CODE
	MOVSI	T2,<VECIPC-VECTOR>	;VECTOR OFFSET
	SETZ	T3,			;RESERVED WORD
	MOVX	S1,PS.FAC+T1		;ADD THE CONDTION
	PISYS.	S1,			;DO IT!!
	  HALT
	$CALL	I%ION			;TURN ON INTERRUPT SYSTEM
	POPJ	P,			;AND RETURN
>  ;END IFN FTUUOS
	SUBTTL	BATIPC--BATCON IPCF INTERRUPT HANDLER
BATIPC:	$BGINT INT.AL			;LEVEL 1 INTERRUPTS
	$CALL	C%INTR			;INTERRUPT OCCURED
	$DEBRK				;EXIT INTERRUPTS


	SUBTTL ERROR PRINT ROUTINE
IFN	FTJSYS,<
ERRPRT:	$STOP(GER,GETJI ERROR RETURN)
>;END FTJSYS
	SUBTTL	INTERRUPT PROCESSING ROUTINES
IFN	FTJSYS,<
	DEFINE	BLDCHN(XX,YY,ZZ),<
PTYC'XX:	$BGINT INT.IN			;LEVEL 1 INTERRUPTS
	MOVEI	S,ZZ				;INTERRPT LEVEL #
	JRST	PTYINP				;PTY INTER. PROCESSING
PTYC'YY:	$BGINT INT.OU			;LEVEL 1 INTERRUPTS
	MOVEI	S,ZZ				;INTERRPT LEVEL #
	JRST	PTYOUT				;PTY INTER. PROCESSING
	>;END BLDCHN
	XX==0
	YY==1
	ZZ==0
	REPEAT DEFMJB,<BLDCHN(\XX,\YY,ZZ)
		XX==XX+2
		YY==XX+1
		ZZ==ZZ+1>
PTYINP:	SKIPL	R,BASTBL(S)		;LOAD UP BASE REGISTER
	JRST	PTYERR			;MARK AS AN ERROR
	MOVSI	T1,<JL.UDI>		;INPUT READY
	IORM	T1,.JFLAG(R)		;RESTORE VALUE IN MEMORY
	AOS	.JINPI(R)		;COUNT INPUT DESIRED INTERRUPTS
	$DEBRK				;INTERRUPT EXIT
PTYOUT:	SKIPL	R,BASTBL(S)		;LOAD UP BASE REGISTER
	JRST	PTYERR			;MARK AS AN ERROR
	MOVSI	T1,<JL.UOA>		;USER HAS OUTPUT
	IORM	T1,.JFLAG(R)		;RESTORE VALUE IN MEMORY
	AOS	.JOUTI(R)		;COUNT OUTPUT READY INTERRUPTS
	$DEBRK				;EXIT INTERRUPT
PTYERR:	AOS	INTERR			;KEEP TRACK OF PTY ERRORS
	$DEBRK				;EXIT
>  ;END OF IFN FTJSYS
	SUBTTL	PTY AND LOG OUTPUT ROUTINES

IFN	FTUUOS,<
	
	;THIS ROUTINE WILL CHECK FOR A " AND SEND AN EXTRA " IF ONE WAS
	;SENT. IT WILL THEN  LOG CHARACTER TO LOG FILE AND PTY

PTYSCN:	MOVE	CH,S1		;SAVE CHARACTER IN CH
	CAIN	CH,CHR.QT	;CHECK IF A " FOR SCAN
	PUSHJ	P,LOGPT1	;YES OUTPUT AN EXTRA " FOR SCAN
	PJRST	LOGPT1		;OUTPUT THE CURRENT CHARACTER AND RETURN
>;END FTUUOS

PTYLOG:	MOVE	CH,S1		;CHARACTER IN CH
	PUSHJ	P,PUTPTY	;OUTPUT TO PTY
	PUSHJ	P,L$PLOG##	;OUTPUT TO LOG
	$RETT			;RETURN TRUE


LOGPTY:	MOVE	CH,S1		;CHARACTER INTO CH
LOGPT1:	PUSHJ	P,PUTPTY	;PLACE IN PTY BUFFER
	JRST	L$OUTC##	;NOW ECHO IN LOG FILE


	;PTYDAT	--THIS ROUTINE JUST SEND DATA TO PTY
PTYDAT:	MOVE	CH,S1		;PUT CHARACTER IN CH
	PUSHJ	P,PUTPTY	;OUTPUT CHARACTER AND RETURN
	$RETT			;RETURN TRUE



IOERR:	$STOP	(FIO,FATAL I-O RETURN FROM LIBRARY)




OUTDAT:	SOSG	.JWCNT(R)		;DECREMENT COUNT
	JRST	OUTERR			;ERROR MESSAGE TO LARGE
	IDPB	S1,.JWPTR(R)		;PUT CHARACTER IN MESSAGE
	$RETT				;RETURN TO TEXT


	SUBTTL	STAWTO	--	START WTO/WTOR MESSAGE

STAWTO:	$CALL	M%GPAG			;GET A PAGE
	MOVE	G,S1			;SAVE THE PAGE ADDRESS
	MOVEI	S1,<PAGSIZ-^D30>*5	;GET MESSAGE SPACE LEAVING ROOM FOR $ACK
	MOVEM	S1,.JWCNT(R)		;SAVE THE COUNT
	HRRI	S1,(G)			;POINT TO THE PAGE
	HRLI	S1,(POINT 7,)		;MAKE BYTE POINTER
	MOVEM	S1,.JWPTR(R)		;SAVE THE POINTER
	MOVEM	G,.JWADR(R)		;SAVE THE ADDRESS
	SETOM	.JWTOF(R)		;STARTING WTO..SET FLAG WORD
	POPJ	P,


	SUBTTL	OUTEXT--ROUTINE TO FINISH MESSAGE AND EXIT

OUTEXT:	$WTO	(<Message from Batch User>,<^I/JIBTXT/^T/@.JWADR(R)/>,.JQOBJ(R),<$WTJBN(.JJOBN(R)),$WTNOD(.JQLOC(R))>)
	MOVE	S1,.JWADR(R)		;GET THE ADDRESS
	PUSHJ	P,M%RPAG		;RELEASE THE PAGE
	SETZM	.JWTOF(R)		;CLEAR FLAG,,END OF WTO(R)
	$RETT				;GIVE GOOD RETURN


OUTERR:	PUSHJ	P,OUTEXT		;FINISH OFF MESSAGE
	$RETF				;TRUNCATE THE MESSAGE

MSGOUT:	TLZN	F,FL.SPL		;WAS SPECIAL BIT LIT
	MOVEI	S1,NULTXT		;NO..USE NULL TXT
	MOVEI	S2,NULTXT		;GET NULL ERROR TEXT
	TLZE	F,FL.ERR		;WAS ERROR SET
	MOVEI	S2,ERTEXT		;YES..USE ERROR TEXT
	MOVE	T1,.JERRO(R)		;GET THE ERROR CODE
	$ACK	(<^T/@IPC.TX(T2)/>,<^R/.JQJBB(R)/^I/(S2)/^I/(S1)/>,<.JQOBJ(R)>,<IPC.DA+.MSCOD(T2)>)
	$RETT				;RETURN

	SUBTTL	SNWTOR	--	SEND WTOR ROUTINE

SNWTOR:	TLNE	F,FL.NOP		;OPERATOR INTERVENTION ALLOWED?
	JRST	SNWT.E			;NO..GENERATE ERROR AND CANCEL JOB
	$WTOR	(<Message from Batch User>,<^I/JIBTXT/^T/@.JWADR(R)/>,.JQOBJ(R),.JQITN(R),<$WTJBN(.JJOBN(R)),$WTNOD(.JQLOC(R))>)
	MOVE	S1,.JWADR(R)		;GET THE ADDRESS
	PUSHJ	P,M%RPAG		;RELEASE THE PAGE
	SETZM	.JWTOF(R)		;CLEAR FLAG,,END OF WTO(R)
	$RETT				;GIVE GOOD RETURN
SNWT.E:	MOVX	S1,E.NOPA		;NO OPERATOR INTERVENTION ALLOWED
	MOVEM	S1,.JERRO(R)		;SAVE THE ERROR CODE
	TLO	F,FL.ERR		;TURN ON ERROR FLAG
	$WTO(<Canceling>,<^I/JIBTXT/ Job ^I/@ERRTAB(S1)/>,.JQOBJ(R),<$WTNOD(.JQLOC(R))>)
	MOVEI	T1,[ASCIZ/BTNOIN Operator Responses not allowed in this Stream   JOB CANCELED/]
	PJRST	NORM.1			;CHECK ERROR AND RETURN



ERTEXT:	ITEXT	(<
-- ^I/@ERRTAB(T1)/ -->)		;OUTPUT REASON

NULTXT:	ITEXT(<>)
	SUBTTL	ERRTAB--EXPAND ERROR TABLE VALUES

	DEFINE	X(A,B),<	EXP	[ITEXT (<B>)]>

ERRTAB:	MSGBLD			;BUILD MESSAGE TABLE
	LSTOFF	;FORCE OUT LITERALS NOW
	LIT
	LSTON
	END	BATCON