; UPD ID= 152, SNARK:<6.1.UTILITIES>SERVER.MAC.25, 10-Sep-85 15:44:44 by PALMIERI
;Fix bug at INPREC, commented out instruction causes undesireable skip
; UPD ID= 150, SNARK:<6.1.UTILITIES>SERVER.MAC.24, 12-Aug-85 15:29:06 by MELOHN
;Remove unnecessary CFBFI%s and add an appropriate one when breaking back
;to the host.
;Rip out edit 24, as it causes problem with ^Cing out of password: TEXTI%.
; UPD ID= 146, SNARK:<6.1.UTILITIES>SERVER.MAC.23, 19-Jun-85 22:31:00 by MELOHN
; UPD ID= 129, SNARK:<6.1.UTILITIES>SERVER.MAC.22, 23-May-85 16:53:19 by MELOHN
;Change message supported fields to not support 0,
;Set speed on indeterminate lines to 9600 for VMS,
;correctly initialize terminal width, wrap, length, and page mode.
; UPD ID= 123, SNARK:<6.1.UTILITIES>SERVER.MAC.21, 3-May-85 22:20:53 by GLINDELL
; More work on PMR
; UPD ID= 122, SNARK:<6.1.UTILITIES>SERVER.MAC.20, 3-May-85 20:22:34 by GLINDELL
; Change FTPMR default to be OFF
; UPD ID= 121, SNARK:<6.1.UTILITIES>SERVER.MAC.19, 3-May-85 20:15:47 by GLINDELL
; Support poor mans routing - use CTDNCN (DNCONN for CTERM-SERVER)
; UPD ID= 112, SNARK:<6.1.UTILITIES>SERVER.MAC.18, 9-Apr-85 19:45:57 by MELOHN
; Fix from last edit - make normal echo BIN% terminator work properly.
; UPD ID= 110, SNARK:<6.1.UTILITIES>SERVER.MAC.17, 4-Apr-85 14:36:45 by MELOHN
; Fix input count routine to not echo the BIN% to get the first waiting char.
; Add cell TRMFLG, set when TEXTI% has echoed a terminator when echo terminator
; was disabled. In this case, we attempt to throw away the next write message
; in the hope that it was echoing the terminator that we have already echoed.
; UPD ID= 109, SNARK:<6.1.UTILITIES>SERVER.MAC.16, 29-Mar-85 15:45:01 by MELOHN
; Clean up stuff from the last edit. If QUIET, try NRT on illegal nodenames.
; UPD ID= 107, SNARK:<6.1.UTILITIES>SERVER.MAC.10, 28-Mar-85 22:57:33 by MELOHN
; Add routine to set the program name to the name of the connected node.
; Add QUIET cell to keep server connection/error msgs to a mimimum(default OFF)
; Make error msgs returned to users identify CTERM-SERVER as the source of err.
; Remove timout on initial connect since 6.1 systems will do it for us.
; UPD ID= 98, SNARK:<6.1.UTILITIES>SERVER.MAC.9, 18-Mar-85 17:02:03 by MELOHN
; Fix parsing of nodename to accept :: at the end of the string.
; UPD ID= 72, SNARK:<6.1.UTILITIES>SERVER.MAC.8, 27-Jan-85 22:57:40 by MELOHN
; Make default no input escape recognition to fix DECalc problem on VMS.
; UPD ID= 71, SNARK:<6.1.UTILITIES>SERVER.MAC.7, 25-Jan-85 21:08:19 by MELOHN
; Fix terminal settings restoration to correctly restore terminal len and wid
; UPD ID= 68, SNARK:<6.1.UTILITIES>SERVER.MAC.5, 16-Jan-85 20:23:41 by MELOHN
; Add a new entry in the entry vector for the EXEC to use when running the
; server via the SET HOST command. Using this vector will suppress the error
; messages usually supplied by the server to the user, since the EXEC will
; handle that for us.
;
; Add code to set error code NSPX20 when no CTERM destination process so that
; the EXEC can go and try running NRT with the SET HOST command.
;
; Remove special handling code for freelfs in OUPENT, since it was eating
; messages with only CRLF in them.
;
;WORK:<MELOHN.CTS>SERVER.MAC.11 27-Nov-84 15:56:50, Edit by MELOHN
;
; If a read is terminated because of underflow, check to see if it is a
; continuation read. If so, re-read the editing character and send it
; to the host.
;
; Change the edit number, not the version number.
;
; UPD ID= 24, SNARK:<6.1.UTILITIES>SERVER.MAC.2, 8-Aug-84 12:08:39 by WEISBACH
; Add routines TRMSTX and TRMRTX to save and restore the terminal
; characteristics for the case that the TEXTI is interrupted (by
; out-of-band character PSI) and later restarted.

TITLE SERVER
SEARCH MACSYM,MONSYM,CMD
.REQUIRE SYS:MACREL,SYS:CMD
SALL
;Feature switches
IFNDEF FTPMR,<FTPMR==:0>
DEFINE $PMR,<IFN FTPMR,>
DEFINE $NOPMR,<IFE FTPMR,>
IF1,<IFN FTPMR,<PRINTX -- Building with PMR support -->>
;If FTPMR is non-zero, then CTERM-SERVER will be built with CTDNCN. That
;is a modified version of DNCONN, which is the PMR support module.

;Send bytes to the terminal - use this macro for any data sent to the
;terminal as a result of a START-READ or WRITE message. This is used
;to keep track of the last character sent to the terminal so that
;the format flag of the START-READ message can be implemented
;Nonskippable
;Uses only ACs T1,T2,T3
DEFINE $PSOUT (PTR,COUNT)<
IFN PTR-3,<
MOVN T3,COUNT ;;Get negative of source count
IFN PTR-2,<MOVE T2,PTR> ;;Get source pointer, if needed
>
IFE PTR-3,<
IFN COUNT-2,<MOVE T2,PTR> ;;Source pointer
IFE COUNT-2,<EXCH T2,T3> ;;Source pointer and count
MOVN T3,COUNT ;;Get negative of source count
>
MOVEI T1,.PRIOU ;;Destination
IFN. T3
SOUT% ;;Do it.
LDB T3,T2 ;;Get last character
MOVEM T3,OUPCR ;;Save it
ENDIF.
>;END $PSOUT
;As above, but for a single byte
;Nonskippable
DEFINE $PBOUT (THEBYT)<
IFN THEBYT-1,<MOVE T1,THEBYT>
PBOUT%
MOVEM T1,OUPCR
>;END $PBOUT

;Command parsing macro
;Parse a keyword - value is in T1
; KEYTAB is address of the keyword table,
; FAIL is the address to go to on failure.
;Nonskippable.
;Returns value of key in T1
DEFINE KEYWRD (KEYTAB)<
MOVEI T1,[FLDDB.(.CMKEY,,KEYTAB)] ;;Address of function descriptor block
CALL RFIELD ;;Do work.
HRRZ T1,(T2) ;;Get value of key
>;END OF KEYWRD
COMMENT #
This macro generates the action codes and the corresponding
dispatch tables. CODPRE is the first three characters of the action
code names, RTNPRE is the first three characters of the dispatch
routines. CODLST is a list of three character suffixes for the names of
the action codes which will also serve as the suffixes for the names of
the dispatch routines.
#
DEFINE DSPGEN (CODTYP,RTNTYP,CODLST)<
IRP CODLST,<IFIW ! RTNTYP'CODLST>
.ZZ==0
IRP CODLST,<
CODTYP'CODLST==.ZZ
.ZZ==.ZZ+1
>
>;END OF DSPGEN

SUBTTL INPUT PROCESS -- TERMINAL INPUT AVAILABLE -- QUOTE IN PROGRESS
;Here when the input state is quote in progress.
;CALL INPQUT with no arguments
;Returns +2 if read is still active
;Returns +1 if read was terminated
INPQUT: MOVEI INPSTA,.INORD ;Put state back to ordinary.
MOVEI T1,.CHCNV ;Get the quote character
IDPB T1,INPBLK+.RDDBP ;Put it into the buffer
SOS INPBLK+.RDDBC ;Account for it.
PBIN% ;Get the next character
IDPB T1,INPBLK+.RDDBP ;Put it into the buffer
SOS INPBLK+.RDDBC ;Account for it.
CALL PSIRSC ;Restore single character interrupts.
SKIPLE INPBLK+.RDDBC ;Is buffer full ?
RETSKP ;No. Read is still active
MOVEI T1,.TMFUL ;Yes. Terminate read with buffer full
SETZ T2, ;No terminator
CALLRET INPEND ;(T1,T2)

SUBTTL INPUT PROCESS -- TERMINAL INPUT AVAILABLE -- ESCAPE SEQUENCE
;Here when the input state is escape sequence parsing in progress.
;CALL INPESC with no arguments
;Returns +2 if read is still active
;Returns +1 if read was terminated
INPESC: PBIN% ;Get byte
IDPB T1,ESCPTR ;Save it
SOSLE ESCCNT ;Account for it. Out of space ?
JRST @TSTATE(ESCSTA) ;No. Invoke the state machine.
CALLRET INVALD ;Yes. Terminate read - invalid escape sequence
;The intermediate state machine routines - just change the state
;Transition to state 1
STATE1: MOVEI ESCSTA,1 ;Set the state and
RETSKP ; continue
;Transition to state 2
STATE2: MOVEI ESCSTA,2 ;Set the state and
RETSKP ; continue
;Transition to state 3
STATE3: MOVEI ESCSTA,3 ;Set the state and
RETSKP ; continue
;Transition to state 4
STATE4: MOVEI ESCSTA,4 ;Set the state and
RETSKP ; continue
;Transition to state 5
STATE5: MOVEI ESCSTA,5 ;Set the state and
RETSKP ; continue

SUBTTL TIMER PROCESS -- CLEARING AND SETTING THE TIMER
;This routine clears the timer
;CALL TIMCLR with no arguments
;Returns +1 always
TIMCLR: MOVEI T1,.TMNUL ;Set the state of the timer
MOVEM T1,TIMSTA ;to "off"
RET ;Done.
;This routine sets up the timer for the timeout option on the START-READ
;CALL TIMSET with T1/ number of seconds timer is to be set for
;Returns +1 always
;Uses T1 only
TIMSET: MOVEM T1,TIMOUT ;Set the timeout period
MOVEI T1,.TMSTT ;Set the state of the timer "set request"
MOVEM T1,TIMSTA ;Set the state
MOVE T1,JOBNO ;Get my job number
TWAKE% ;Wake the timer up to process the request
TRN
RET ;Done