Google
 

Trailing-Edge - PDP-10 Archives - bb-h240e-bm_decnet-20_v4_0_dist - decnet-sources/sethos.mac
There are 4 other files named sethos.mac in the archive. Click here to see a list.
; UPD ID= 479, SNARK:<6.UTILITIES>SETHOS.MAC.4,  10-Feb-84 14:39:12 by EVANS
;Rescind previous work for decimal display.
; UPD ID= 469, SNARK:<6.UTILITIES>SETHOS.MAC.3,   8-Feb-84 10:01:28 by EVANS
;Add flag to edit number so I VER will display it in decimal.
; UPD ID= 195, SNARK:<6.UTILITIES>SETHOS.MAC.2,  22-Jan-83 05:16:31 by GRANT
;Update disconnect codes to Phase III terminology
; UPD ID= 86, SNARK:<5.UTILITIES>SETHOS.MAC.16,  10-Jun-82 09:23:35 by GRANT
;Improve user message when panic character is typed
; UPD ID= 63, SNARK:<5.UTILITIES>SETHOS.MAC.15,   4-Jan-82 08:34:44 by GRANT
;TCO - 5.1648 - When user types panic character, check for actual connection
; UPD ID= 44, SNARK:<5.UTILITIES>SETHOS.MAC.14,   1-Oct-81 14:26:39 by GRANT
;TCO 5.1553 - output remote system type when we don't support the protocol
; UPD ID= 31, SNARK:<5.UTILITIES>SETHOS.MAC.13,  15-Sep-81 11:33:07 by GRANT
;TCO 5.1509 - Enhance error message when remote system rejects connection
; UPD ID= 9, SNARK:<5.UTILITIES>SETHOS.MAC.12,  24-Jul-81 07:10:07 by GRANT
;Save destination node name so it can be printed out when reconnecting occurs
; UPD ID= 6, SNARK:<5.UTILITIES>SETHOS.MAC.11,  17-Jul-81 16:54:37 by GRANT
;Fix bug in parsing the input string of nodes - bug caused wrong message to
;be sent to PSTHRU
; UPD ID= 2, SNARK:<5.UTILITIES>SETHOS.MAC.10,   9-Jul-81 18:00:57 by GRANT
;Add version number, fix copyright
;Print out disconnect reason when ESC character is seen
; UPD ID= 2300, SNARK:<5.UTILITIES>SETHOS.MAC.9,   6-Jul-81 15:32:15 by MURPHY
;SAVE ONE PAGE WORTH OF TTY OUTPUT IF NOT .MOSNH
;Don't create fork when not needed.
;Switch for PTY/.MOSNH
; UPD ID= 2200, SNARK:<5.UTILITIES>SETHOS.MAC.8,  15-Jun-81 14:19:40 by GRANT
;CLOSF instead of RLJFN when " ? Remote node not responding "
; UPD ID= 2079, SNARK:<5.UTILITIES>SETHOS.MAC.7,  25-May-81 22:59:33 by GRANT
;check to see if link is really still there before saying "type continue to
;resume connection"
; UPD ID= 2034, SNARK:<5.UTILITIES>SETHOS.MAC.6,  19-May-81 15:00:45 by GRANT
;Force the input string to be syntactically correct before trying to open a link
; UPD ID= 1912, SNARK:<5.UTILITIES>SETHOS.MAC.5,  30-Apr-81 16:48:38 by GRANT
;Don't automatically reprompt when GTJFN or OPENF fail in DOJFN
; UPD ID= 1911, SNARK:<5.UTILITIES>SETHOS.MAC.4,  30-Apr-81 16:29:45 by GRANT
;Use .TICCZ instead of .TICTI in ESCHAR
; UPD ID= 1710, SNARK:<5.UTILITIES>SETHOS.MAC.3,  16-Mar-81 11:51:32 by GRANT
;Don't say "[TYPE ^Y, etc.]" until connection has been established
;Don't say "Reason n" when reporting the disconnect reeason
;Time out the attempted connection
;Don't say "Connection broken" when there really wasn't a connection
;If received configuration message doesn't support TOPS-20, say so
; UPD ID= 1646, SNARK:<5.UTILITIES>SETHOS.MAC.2,   4-Mar-81 12:14:55 by GRANT
;MAKE "SETHOST NODE::" CONNECT TO OBJECT 23 INSTEAD OF 123
;<MURPHY.MON>SETHOS.MAC.8, 20-Jan-81 16:07:11, EDIT BY MURPHY
;SH%LPM to prevent sending XON, XOFF
;<MURPHY.MON>SETHOS.MAC.7, 21-Nov-80 17:36:15, EDIT BY MURPHY
;<MURPHY.MON>SETHOS.MAC.4, 10-Oct-80 13:47:05, EDIT BY MURPHY
;<MURPHY.MON>SETHOST.MAC.2, 20-Aug-80 14:54:44, EDIT BY MURPHY
;USE .MOSNH FUNCTION TO MAKE MONITOR DO THE WORK
	TITLE	SETHOS - Program to permit logins to remote network host




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


	SALL			; Keep listing uncluttered, no macro expansion
	SEARCH	MONSYM,MACSYM,CMD ; Universals to search
	.REQUIRE SYS:MACREL,SYS:CMD ; Make LINK load these automatically

; This program will allow a user to login in to a remote system in a
; DECnet network from a TOPS-20 host system. It demonstrates use of the
; TOPS-20 DECnet functionality in a program which performs a real function.
; The remote system must provide a program which acts as a server to
; this program. The MCBNRT program is an example of a program written for
; TOPS-20 which will perform that function on that system. Programs for
; other systems must perform functionally similar to MCBNRT. 
;
	SUBTTL	DECLARED SYMBOLS

IPTYF==0			;Use PTY if 1, otherwise use .MOSNH

	T1=:1			; AC definitions
	T2=:2
	T3=:3
	T4=:4
	Q1==:5
	Q2==:6
	CX=:16
	P=:17

	NPDL==100		; Size of pushdown list
	INSIZ==50		; Terminal input buffer size, in words
	MAXINP==INSIZ*5		; Maximum number of terminal input characters
	DBUFFR==100000		; Data buffer on page 100
	 SDBUF==200		;ASSUMED SIZE OF DBUFFR
	MEMBUF==101000		;MEMORY BFR FOR TTY OUTPUT
	 NMEMBF==777		;SIZE THEREOF

	TOPS20==^D8
	TOPS10==^D9

	VMAJOR==5		;MAJOR VERSION NUMBER
	VMINOR==0		;MINOR VERSION NUMBER
	VEDIT==^D1		;EDIT NUMBER
	VWHO==0			;LAST EDITOR (0 = DEC DEVELOPMENT)

	VSETHOS==<VWHO>B2+<VMAJOR>B11+<VMINOR>B17+VEDIT
	SUBTTL	IMPURE STORAGE

STATUS:	BLOCK 3
STIMSK:	BLOCK 1			; Terminal interrupt word mask for STIW 
UESCCH:	BLOCK 1			; User escape char
LOCAL:	BLOCK 2			; Local node name
DCNJFN:	BLOCK 1			; JFN of logical link to MCBNRT server
INSTR:	BLOCK INSIZ		; Terminal input stream buffer
CTRLY:	BLOCK 1			;CTRL/Y FLAG
NODE0:	BLOCK 20
ROUTE:	BLOCK 40
DESTND:	BLOCK 2			;SPACE FOR DESTINATION NODE NAME
SAVACE:	BLOCK 4			; Register save area for AC's 1 - 4
SAVSTS:	BLOCK 1			;SAVE LOC FOR LINK STATUS
NAME:	BLOCK 50		; File spec name of logical link to MCBNRT
FORK:	BLOCK 1			; Handle of inferior process to read from TTY
PTYF:	IPTYF			;PTY/.MOSNH FLAG
MEMPTR:	BLOCK 1			;PTR TO MEM BFR FOR TTY OUTPUT
NMSPC:	BLOCK 1			;SPACE REMAINING IN MEM BFR
VIRGIN:	EXP -1			; Flag to indicate fresh start, initially -1
PC:	BLOCK 3			; Storage for PC on interrupts
LEVTAB:	PC			; Software interrupt level table
	PC+1
	PC+2
CHNTAB:	0			; Software interrupt channel table
	1,,ESC			; Panic character (default ^Y)
	0
	REPEAT ^D33,<0>		;FILL REST OF CHN TABLE
PDL:	BLOCK NPDL		; Pushdown list (STACK)

CMDSTG				; Command parser storage (from CMDS)
	SUBTTL	START  -  Start of SETHOST program

EVEC:	JRST START		;INITIAL START
	JRST REENT		;CONTINUE EXISTING CONNECTION
	EXP VSETHOS		;VERSION

START:	RESET			; Intialize ourself
	MOVE P,[IOWD NPDL,PDL]	; and set up pushdown list
	AOS VIRGIN		; Bump count of times we come through here
	CALL CMDINI		; Initialize command parser
	SKIPN PTYF		;USING PTY?
	IFSKP.
	  SETZM NMSPC		;NOTE MEM BFR HAS NO SPACE
	  MOVX T1,CR%MAP	;YES, Create process to read from TTY
	  SETZM T2
	  CFORK			; Make the process, same address map
	   JRST [JSHLT		; on error... halt and allow continue
		JRST START]
	  MOVEM T1,FORK		; Save the process handle obtained
	ENDIF.
	MOVEI T1,.FHSLF		; Our process handle
	RPCAP			; Get our capabilities
	TXO T3,SC%CTC		; allow ^C trapping for job
	EPCAP			; Enable new set of capabilities
	MOVE T2,[LEVTAB,,CHNTAB] ; Address of software interrupt system tables
	SIR			; Give them to monitor
	MOVX T2,1B1		; Channel number
	AIC			; Activate software interrupt channels
	EIR			; Enable software interrupt system
	CALL ALLON		; Turn on all TTY interrupts
	CALL PRESCN		; Prescan EXEC line for host name...
	 JRST PREHST		; Got it - skip the prompting
	JRST ESCHAR		; Otherwise get it now
	SUBTTL	ESCHAR - Obtain the escape character user wants to use

ESCHAR:	PROMPT <Escape character(^Y):> ; Put out prompt to users terminal
	MOVEI T1,[FLDDB. (.CMTXT,CM%SDH,,<Character for interrupting connection>,<>)]
	CALL CFIELD		; Read the escape character
	LDB T1,[POINT 7,ATMBUF,6] ; Get character itself
	MOVEM T1,UESCCH		;SAVE IT
	CAILE T1,.TICCZ		; Is it a valid character? (^A to ^Z)
	 JRST [	HRROI T1,[ASCIZ /Invalid character/] ; No, tell user
		ESOUT
		JRST ESCHAR]	; and try again
	MOVNI T2,0(T1)		; Save the character
	HRLS T1			; Character value is terminal code
	HRRI T1,1		; Channel number
	ATI			; Assign terminal code to software interrupt channel
	MOVX T1,1B0		; Get a bit
	LSH T1,0(T2)		; Make terminal interrupt word mask for character
	TXO T1,1B<.TICTI>	; Allow typein
	MOVEM T1,STIMSK		; Save for use later
	JRST HSTNAM		; Get the host name
	SUBTTL	HSTNAM - Get the host name user wants to login on

HSTNAM:	PROMPT <Host name: >	; Put out prompt to users terminal
PREHST:	MOVEI T1,[FLDDB. (.CMTXT,CM%SDH,,<Name of system to connect to>)]
	CALL CFIELD		; Read host name
	HRROI T1,INSTR		; Pointer to destination buffer
	HRROI T2,ATMBUF		; Pointer to source buffer
	MOVEI T3,0		; An ASCIZ string
	SOUT			; Copy the host name
	MOVX T1,177B6		; See if real host name given
	TDNN T1,INSTR		; Was one?
	JRST [	HRROI T1,[ASCIZ /
[CONNECTING TO LOCAL HOST- /]		; No, tell user what's happening
		PSOUT
		MOVEI T1,.NDGLN		; Function code to get local node name
		MOVEI T2,T3
		HRROI T3,INSTR
		NODE			; Obtain local node name
		HRROI T1,INSTR
		PSOUT			; Output to user's TTY
		HRROI T1,[ASCIZ /]
/]
		PSOUT			; Finish the message nicely
		JRST .+1]
	JRST SETTMD		; Have name. Now set TTY modes
	SUBTTL	SETTMD - Set TTY modes

SETTMD:	MOVEI T1,.PRIIN		; Primary input
	RFMOD			; Get current JFN mode word
	TXO T2,TT%WAK		; Wake on all
	TXZ T2,TT%ECO!TT%DAM	; Echoes off and binary data mode
	SFMOD			; Set new JFN mode word
	MOVX T1,.FHJOB		; Set terminal interrupt word for entire job
	MOVE T2,STIMSK		; Get terminal interrupt word saved earlier
	STIW			; Set it to allow only panic interrupts
	CALL COLDSH		; Convert digraph :: to -
	HRROI T1,NAME		; Build network file spec to MCBNRT
	HRROI T2,[ASCIZ /DCN:/]	; The DECnet device for making connection
	SETZM T3
	SOUT
	MOVE T2,[POINT 7,NODE0]
	SOUT			; Copy node name as well
	HRROI T2,[ASCIZ /-23/]	; MCBNRT's object type
	SKIPE ROUTE		; Doing routing?
	HRROI T2,[ASCIZ /-123/]	;PSTHRU'S OBJECT TYPE
	SOUT
DOJFN:	MOVX T1,GJ%SHT		; Do a short form GTJFN
	HRROI T2,NAME		; Using the spec just built
	GTJFN			; Get DCN connection
	 JRST [	JSERR			; If error, tell user
		CALL ALLON		; Reset TTY to normal mode
		HALTF			;STOP
		JRST HSTNAM]		; And go back to get host name
	MOVEM T1,DCNJFN		; Save JFN for the connection
	;MOVEI T1,.PRIOU		; Check if parity OK on this TTY
	;GDSTS			; Get device status
	;ERJMP [SETZM T2			; If error, set all status off
	;	JRST .+1]		; And continue along
	;MOVE T1,DCNJFN		; Restore the JFN for network connection
	;TXNE T2,GD%PAR		; Does terminal allow parity?
	MOVE T2,[FLD(^D8,OF%BSZ)!FLD(.GSSMB,OF%MOD)!OF%RD!OF%WR]
				 ; Yes, 8 bit bytes and read/write access
	OPENF			; Open the network connection
	 ERJMP [JSERR			; If failed, tell user
		MOVE T1,DCNJFN		; And release the JFN
		RLJFN
		 JFCL
		CALL ALLON		; Reset TTY to normal mode
		TMSG <
>
		JRST HSTNAM]		; And go back to get host name
	MOVEI T4,6		;6 TRIES FOR THE CONNECTION
TSTCON:	MOVEI T1,^D2000		;2 SECONDS BETWEEN TRIES
	DISMS			;WAIT
	MOVE T1,DCNJFN		;GET BACK THE JFN
	MOVX T2,.MORLS		;READ LINK STATUS
	MTOPR
	 ERJMP .+1
	TXNE T3,MO%CON		;CONNECTED?
	JRST GOTCON		;YES, GO TO IT
	TXNE T3,MO%WFC		;NO, WAITING FOR A CONNECT?
	JRST TSTCO1		;YES, WAIT FOR A BIT
	TXNE T3,MO%ABT		;NO, CONNECT BEEN REJECTED?
	JRST [	HRROI T1,[ASCIZ/
? Remote system rejected connection - /]
		PSOUT
		JRST NOTCON]
TSTCO1:	SOJE T4,[HRROI T1,[ASCIZ/
? Remote node not responding

/]
TSTCO2:		PSOUT
		MOVE T1,DCNJFN		; And release the JFN
		CLOSF
		 JFCL
		CALL ALLON		; Reset TTY to normal mode
		JRST HSTNAM]		; And go back to get host name
	JRST TSTCON		;TRY AGAIN
;CONNECTION TO REMOTE NODE HAS BEEN ESTABLISHED


GOTCON:	SKIPN ROUTE		; want to route-through?
	JRST NOR		; No. Go on

;Here to do pass-through

	MOVE T1,DCNJFN		;GET BACK JFN
	HRROI T2,ROUTE		;Get message
	SETZM T3
	SOUTR			; Send it
	 ERJMP RTERR
RT0:	HRROI T2,DBUFFR
	MOVNI T3,^D200
	SINR			; Get message
	 ERJMP RTERR
	SETZM T4
	IDPB T4,T2		; tie it off
	LDB T4,[POINT 7,DBUFFR,6]
	SOJG T4,RTERR0		; bad
	JUMPE T4,NOR
	MOVE T1,[POINT 7,DBUFFR,6]
	PSOUT
	MOVE T1,DCNJFN
	JRST RT0

NOR:	SKIPN PTYF		;IF USING PTY...
	IFSKP.
	  MOVE T1,FORK		; Restore the process handle obtained
	  MOVEI T2,DOINP0	; The start address
	  SFORK			; Start the process to read input from TTY
	   ERJMP [RESET			; If failed, reset ourself
		JSHLT			; Tell user and halt
		JRST START]		; Go back to beginning if continued
	ENDIF.
	MOVE T1,DCNJFN
	MOVE T2,[POINT ^D8,DBUFFR]
	MOVNI 3,SDBUF
	SINR				; Read status message
	 ERJMP BADCON
	LDB T1,[POINT ^D8,DBUFFR,7]
	SOJN T1,[MOVEI T4,SDBUF(T3) ;GeT count received-1
		 JRST GOTDAX]
	LDB T1,[POINT ^D8,DBUFFR+1,7]
	CAIL T1,0		;IS OPERATING SYSTEM
	CAILE T1,HSTTYN		; TYPE LEGAL?
	IFNSK.			;NO
	  TMSG <
? Remote system sent an illegal configuration message
>
	   JRST QUIT		;BYE
	ENDIF.
	CAIE T1,TOPS20		;TOPS-20?
	CAIN T1,TOPS10		;OR TOPS10?
	SKIPA			;OK
	IFNSK.			;NO
	   PUSH P,T1		;STASH SYSTEM TYPE
	   TMSG <
? Communication with >
	   POP P,T1		;RETRIEVE SYSTEM TYPE
	   HRROI T1,@HSTTYP(T1)	;MAKE BP TO REMOTE'S NAME
	   PSOUT		;PRINT IT OUT
	   TMSG < not supported by SETHOST

>
	   CALL ALLON		;RESET TTY TO NORMAL MODE
	   RESET		;CLEAR EVERYTHING
	   JRST HSTNAM		;START OVER
	ENDIF.
	SKIPN CTRLY		;TELL USER ABOUT CTRL/Y?
	JRST GOTDA2		;NO, USER SELECTED A CHAR
	TMSG	<
[Type ^Y to return to node > ; Tell user how to get back
	MOVX T1,.NDGLN
	MOVX T2,T3
	MOVE T3,[POINT 7,LOCAL]
	NODE			; And name of local node
	 JFCL
	HRROI T1,LOCAL
	PSOUT
	TMSG	<]
>				; Finish off nicely
	JRST GOTDA2

RTERR:
RTERR0:	HRROI T1,[ASCIZ /
?DECNET connection aborted by remote server
/]
	PSOUT
	MOVE T1,[POINT 7,DBUFFR,6]
	PSOUT
	HRROI T1,[ASCIZ /
/]
	PSOUT
QUIT:	RESET
	HALTF
	JRST START
;OPERATING SYSTEM TYPES

HSTTYP:	[ASCIZ\RSTS\]
	[ASCIZ\RT-11\]
	[ASCIZ\RSTS/E\]
	[ASCIZ\RSX-11S\]
	[ASCIZ\RSX-11M\]
	[ASCIZ\RSX-11D\]
	[ASCIZ\IAS\]
	[ASCIZ\VMS\]
	[ASCIZ\TOPS-20\]
	[ASCIZ\TOPS-10\]
	[ASCIZ\RTS-8\]
	[ASCIZ\OS-8\]
	[ASCIZ\RSX-11M+\]
	[ASCIZ\MCB\]
HSTTYN=.-HSTTYP-1		;NUMBER OF DEFINED OPERATING SYSTEM TYPES
	SUBTTL	GOTDA1 - Read data from network connection

GOTDA1:	SKIPE PTYF		;USING PTY?
      IFSKP.
	MOVE T1,DCNJFN		;NO, HAND CONNECTION TO MONITOR
	MOVEI T2,.MOSNH
	MOVEI T3,1(P)
	PUSH P,[3]		;PUSH SIZE OF ARG BLOCK
	PUSH P,[.PRIIN]
	HRRZ T4,UESCCH
	TXO T4,SH%LPM		;LOCAL PAGE MODE
	PUSH P,T4
	MTOPR			;CONNECT DCNJFN TO TTY
	 ERJMP [JSHLT]
	ADJSP P,-3		;FLUSH ARG BLOCK
	WAIT
	JRST GOTDA1
      ENDIF.
	MOVE T1,DCNJFN		; Get the network connection JFN
	MOVE T2,[POINT ^D8,DBUFFR] ; Pointer to buffer
	MOVNI T3,1		; One byte only
	SIN			; Read from logical link
	 ERJMP BADCON			; If error, connection broken
	MOVE T3,T2		; Save byte pointer
	SIBE			; Any more data to read now ?
	IFSKP.
	  MOVEI T4,1		;NO, GO TYPE THE ONE CHARACTER
	  JRST GOTDAX
	ENDIF.
	EXCH T2,T3		; Restore byte pointer
	MOVE T4,T3		; Save count
	MOVNS T3		; Read the exact number available
	SIN			; Read remaining bytes
	 ERJMP BADCON			; If error, connection broken
	ADDI T4,1		;TOTAL COUNT OF BOTH SIN'S

GOTDAX:	MOVEI T1,.PRIOU		; Output to users terminal
	MOVE T2,[POINT ^D8,DBUFFR] ; Pointer to data from remote host
	MOVN T3,T4		; Output count
	CALL SAVTTO		;SAVE TTY OUTPUT
	SOUT			; Type data on users terminal
	SKIPE PTYF		;USING PTY?
	JRST GOTDA1		;YES
GOTDA2:	MOVE T1,DCNJFN
	SIBE			;HAVE PROCESSED ALL OF INITIAL MESSAGE?
	 CAIA			;NO
	JRST GOTDA1		;YES, GO SPLICE CONNECTION
	MOVE T4,T2		;GET COUNT OF BYTES REMAINING
	MOVN T3,T2		;READ EXACTLY THAT NUMBER
	MOVE T2,[POINT 8,DBUFFR]
	SIN			; Read remaining bytes
	 ERJMP BADCON
	JRST GOTDAX		;PRINT IT

;SAVE COPY OF OUTPUT GOING TO TERMINAL
;T1-T4 ARE SET FOR SOUT TO TTY

SAVTTO:	SAVEAC <T1,T2,T3,T4>	;BE TRANSPARENT
	MOVM T1,T3		;GET POS COUNT OF CHARS HERE
	CAMGE T1,NMSPC		;MORE THAN SPACE IN MEM BFR?
	IFSKP.
  ; *** CODE COULD BE PUT HERE TO WRITE THE BFR TO A FILE ALSO ***
	  MOVE T1,[POINT 8,MEMBUF] ;YES, RESET BUFFER
	  MOVEM T1,MEMPTR
	  MOVEI T1,NMEMBF*5
	  MOVEM T1,NMSPC
	ENDIF.
	ADDM T3,NMSPC		;REDUCE SPACE BY AMOUNT OF THIS SOUT
	MOVE T1,MEMPTR		;PTR TO MEMORY BUFFER
	SOUT
	MOVEM T1,MEMPTR		;SAVE UPDATED PTR
	RET
	SUBTTL	ALLON - Restore echoing and interrupts on terminal

ALLON:	MOVX T1,.FHJOB		; Set terminal interrupt word for entire job
	SETOM T2		; Terminal interrupt word mask for all codes
	STIW			; Set terminal interrupt word
	MOVEI T1,.PRIIN		; Primary input
	RFMOD			; Read JFN mode word
	TXO T2,TT%ECO!TT%DAM	; Echo on, ASCII data mode, output translation disabled
	SFMOD			; Set new JFN mode word
	RET			; Done, return to caller
;ROUTINE TO SCAN THE STRING IN INSTR AND CONVERT ANY
;INSTANCE OF THE DIGRAPH "::" TO "-". THIS IS DONE
;BECAUSE COLONS ARE DIFFICULT TO PASS VIA FILE
;SPECS BUT DASHES AREN'T.

COLDSH:	MOVE T2,[POINT 7,INSTR]	; Source string
	MOVE T3,[POINT 7,NODE0]
	SETZM ROUTE
	MOVE Q1,T2		;STASH THE BP
	ILDB T4,T2
	CALL GUDCHR
	 JRST ENDO3
	SKIPA
COLDS0:	ILDB T4,T2		; Get a byte
	CAIN T4,":"		; Start of a digraph?
	JRST ENDOF		;YES, GO FIGURE IT OUT
	IDPB T4,T3		;NO, stash it
	JUMPN T4,COLDS0		; If more to do, proceed
	JRST DUN		;GO FINISH UP

;here is found : in file spec

ENDOF:	SETZM T4
	IDPB T4,T3		; Tie it off
	ILDB T4,T2		; get next
	CAIE T4,":"		; Another one?
ENDO3:	JRST [	TMSG <
? Invalid node name format

>
		CALL ALLON
		JRST HSTNAM]
	ILDB T4,T2		;PEEK AHEAD 1 BYTE
	SKIPN T4		;IF NONE, NO ROUTING NEEDED
	JRST DUN		;GO FINISH UP
	CALL GUDCHR		;IS IT LEGIT?
ENDO4:	 JRST [	TMSG <
? Illegal character after ::

>
		CALL ALLON
		JRST HSTNAM]
	SETO T4,		;BACKUP THE
	ADJBP T4,T2		; BYTE
	MOVEM T4,T2		;  POINTER
	MOVE Q1,T2		;STASH THE BP
	MOVE T3,[POINT 7,ROUTE]
	MOVEI T4,1
	IDPB T4,T3
ENDO0:	ILDB T4,T2		; Get next
	CAIE T4,":"		;A DELIMITER?
	JRST ENDO1		;NO
	ILDB T4,T2		;YES, GET NEXT BYTE
	CAIE T4,":"		;A SECOND DELIMITER?
	JRST ENDO3		;NO, CAN'T HAVE THAT
	IDPB T4,T3		;PUT IN :
	IDPB T4,T3		; AGAIN
	ILDB T4,T2		;PEEK AHEAD 1 BYTE
	SKIPN T4		;IF NONE, OK
	JRST [	SETO T4,
		ADJBP T4,T2
		MOVEM T4,T2
		JRST ATEND]
	SETO Q1,		;FAKE A BACK UP
	ADJBP Q1,T2		; AND STASH THE BP
	CALL GUDCHR		;IS IT LEGIT?
	 JRST ENDO4		;NO, TOO BAD
ENDO1:	JUMPE T4,ATEND		;IF NULL, DONE
	IDPB T4,T3		;STASH IT
	JRST ENDO0		; Copy string
ATEND:	PUSH P,T1
	LDB T1,T3		; Look at last byte
	CAIE T1,":"		; Finish correctly?
	JRST [	MOVEI T1,":"
		IDPB T1,T3
		IDPB T1,T3
		JRST .+1]
	HRROI T1,[ASCIZ /"23="/]
	MOVE T2,T3
	SETZM T3
	SIN			; Finish string
	POP P,T1
	IDPB T3,T2		; Tie it off

DUN:	MOVE T3,[POINT 7,DESTND]	;MAKE BP TO DESTINATION NODE NAME
DUN1:	ILDB T4,Q1		;GET A BYTE
	CAIN T4,":"		;IS IT A DELIMITER?
	IFNSK.			;YES
	   SETZ T4,		;END OF NODE NAME
	   JRST DUN2		;AND FINISH
	ENDIF.
	CAILE T4,"Z"		;IS IT LOWER CASE?
	SUBI T4,40		;YES, MAKE IT UPPER CASE
DUN2:	IDPB T4,T3		;PUT IN THE BYTE
	SKIPE T4		;ARE WE DONE?
	JRST DUN1		;NO
	RET			;YES
;ROUTINE TO CHECK FOR LEGITIMATE CHARACTERS IN A NODE NAME
;ACCEPTS:	T4/ ASCIZ OF CHARACTER
;RETURNS:	+1  ILLEGAL
;		+2  OK

GUDCHR:	CAIGE T4,"0"
	RET
	CAIG T4,"9"
	RETSKP
	CAIGE T4,"A"
	RET
	CAIG T4,"Z"
	RETSKP
	CAIGE T4,"a"
	RET
	CAIG T4,"z"
	RETSKP
	RET
	SUBTTL	PRESCN - Prescan EXEC command for host name

PRESCN:	SKIPE	VIRGIN		; Starting out fresh?
	RETSKP			; No..., so return +2 to force prompt
	MOVEI	T1,.RSINI	; Make rescan buffer available 
	RSCAN			; as command line to process reading from CTTY
	 ERJMP PRESC1
	MOVX	T1,.RSCNT	; Get count of characters 
	RSCAN			; in rescan buffer
	 ERJMP PRESC1
	JUMPE	T1,[RETSKP]	; None there, so must prompt
	MOVEI	T1,.PRIIN	; Primary input
	BIN			; Read a character
	CAIE	T2,"R"		; RUN or R (program name can't start with "R")
	CAIN	T2,"r"		; Check lowercase also
	JRST PRESC0		; Yes, no prescanning, go eat rest of line
PRES1:	CAIE	T2," "		; Have we hit a space yet?
	CAIN	T2,"	"	; Also accept a tab
	JRST	PRES2		; Yes, read the node name
	CAIN	T2,.CHLFD	; Have we hit EOL yet?
	RETSKP			; Yes, no node name, skip return to prompt
	BIN			; Read the next character
	JRST	PRES1		; And loop to test

PRES2:	MOVSI	T1,.TICCY	; Default to ^Y for interrupt character
	MOVSM T1,UESCCH		;SAVE IT FOR MTOPR
	HRRI	T1,1		; And use channel one
	ATI			; Assign terminal code to interrupt channel
	MOVX	T1,1B0		; Get a hi order bit
	LSH	T1,-.TICCY	; Shift bit by value of ^Y code
	TXO	T1,1B<.TICTI>	; Allow typein
	MOVEM	T1,STIMSK	; Save for use later
	SETOM CTRLY		;SAY USE CTRL/Y
	PROMPT	<>		; Null prompt
	RET			; Done, return no skip to not prompt

;HERE TO FLUSH REST OF EXEC COMMAND LINE

PRESC0:	BIN			; Get next byte
	CAIE T2,.CHLFD		; The end of line?
	JRST PRESC0		; No, Try again
	RETSKP			; Yes, return +2 to prompt for node

;Here if rescan attempt does not succeed

PRESC1:	HRROI T1,[ASCIZ/Unexpected error in scanning command line/] ; If error,
	ESOUT			; tell user
	HALTF			; and halt
	JRST START		; Start over if continued...
	SUBTTL BADCON - Handle a broken network connection

BADCON:	CIS			; Prevent further interruption
	CALL ALLON		; Restore TTY modes
	SKIPN PTYF		;IF NON-MONITOR CHAR HANDLING,
	IFSKP.
	  MOVE T1,FORK		; Restore the process handle
	  KFORK			; Kill the terminal input process
	ENDIF.
	MOVE T1,DCNJFN		; Get JFN
	MOVEI T2,.MORDA
	HRROI T3,INSTR
	SETZM T4
	MTOPR			; Get any optional data
	 ERJMP .+1
	SETZM T1
	IDPB T1,T3
	HRROI T1,[ASCIZ /
?Connection broken/]		; Tell user bad news
	PSOUT
	JUMPN T4,[HRROI T1,[ASCIZ / at host /]
		  PSOUT
		  HRROI T1,INSTR
		  PSOUT
		  JRST .+1]
;	HRROI T1,[ASCIZ /. Reason: /]
	HRROI T1,[ASCIZ/ - /]
	PSOUT
NOTCON:	MOVE T1,DCNJFN		; Restore network connection JFN
	MOVEI T2,.MORLS		; Get current link status
	MTOPR
	 ERJMP [JSERR		; JFN must be bad
		JRST START]
NOTCO1:	HRRZ T2,T3		; Get DECnet error reason code
;	MOVEI T1,.PRIOU		; Output to users terminal
;	MOVEI T3,12		; In decimal
;	NOUT			; Type it
;	 JFCL
	CAIG T2,MAXMSG		; Know about this error?
	SKIPN T1,MSGTBL(T2)	; Yes, have one to type?
	SKIPA			; No
	PSOUT			; Yes, type it then
	HRROI T1,[ASCIZ /

/]
	PSOUT			; Pretty it
	MOVE T1,DCNJFN		; Get the JFN for the link
	TXO T1,CZ%ABT		; Abort any operations
	CLOSF			; Close it
	 ERJMP [JSERR			;If fails tell why
		JRST .+1]
	HALTF			; Halt here
	JRST START		; And start at beginning if continued
	SUBTTL	ESC - Handle input of panic escape character from terminal

;
; Note: This routine runs at software interrupt level when the user
;	types the specifed escape character. It resets the terminal
;	to its normal mode and halts, thus causing the EXEC to regain
;	control. If the EXEC CONTINUE command is issued data will be
;	again directed to the remote host.
;

ESC:	DMOVEM T1,SAVACE	; Save AC's we're going to use
	DMOVEM T3,SAVACE+2
	SKIPN PTYF		;PROGRAM PASSING CHARACTERS?
	IFSKP.
	  MOVE T1,FORK		; Restore process handle
	  FFORK			; Freeze the terminal input process
	ENDIF.
	MOVEI T1,.PRIOU		; Users terminal
	RFMOD			; Get current TTY modes
	PUSH P,T2		; Save them
	TXO T2,TT%DAM		; ASCII data mode, output translation disabled
	SFMOD			; Set new JFN mode word
	CFOBF			; Flush any pending terminal output
	MOVEI T1,.PRIIN		; Users terminal
	CFIBF			; Flush terminal type ahead
	MOVE T1,DCNJFN		;GET THE LINK
	MOVEI T2,.MORLS		;READ THE
	MTOPR			; LINK'S STATUS
	 ERJMP ESC1		;TOO BAD
	TXNE T3,MO%WCC		;WAITING FOR CONNECTION TO COME TRUE?
	IFNSK.			;YES, STILL WAITING
	   TMSG <
Attempt to make connection has been aborted

>
	   CALL ALLON		;RESET TTY TO NORMAL MODE
	   RESET		;CLEAR EVERYTHING
	   JRST HSTNAM		;START OVER
	ENDIF.
	MOVEM T3,SAVSTS		;NO, WE'VE BEEN CONNECTED - SAVE THE LINK STATUS
	TXNE T3,MO%CON		;STILL CONNECTED?
	JRST ESC2		;YES
ESC1:	TMSG <

Back at node >
	CALL GETUS		;OUTPUT OUR NODE NAME
	TMSG <, connection broken - >
	MOVE T3,SAVSTS		;RETRIEVE LINK STATUS
	JRST NOTCO1

ESC2:	TMSG <

Back at node >
	CALL GETUS
	HRROI T1,[ASCIZ/ - type CONTINUE to resume connection

/]				; Let him know how to restart
	PSOUT
	CIS
	HALTF			; Halt here until continued

REENT:	HRROI T1,[ASCIZ/
%Continuing at node /]
	PSOUT			; Let user know we are restarting
	HRROI T1,DESTND		;POINT TO NODE NAME
	PSOUT			;PUT IT OUT
	TMSG < ....
>
	MOVEI T1,.PRIOU		; Users terminal
	POP P,T2		; Desired TTY modes
	SFMOD			; Set new JFN mode word
	SKIPN PTYF		;LOCAL CHARACTER HANDLING?
	IFSKP.
	  MOVE T1,FORK		; Restore process handle
	  RFORK			; Resume the terminal input process
	ENDIF.
	DMOVE T1,SAVACE		; Restore the AC's
	DMOVE T3,SAVACE+2
	JRST GOTDA1


;OUTPUT THE LOCAL NODE NAME
;RETURNS:	+1

GETUS:	MOVX T1,.NDGLN
	MOVX T2,T3
	MOVE T3,[POINT 7,LOCAL]
	NODE			; Get our node name
	 JFCL
	HRROI T1,LOCAL
	PSOUT			; Type node name to user
	RET
	SUBTTL	DOINP0 - Read terminal input and send to remote host

;
; Note: This routine runs as a separate process to read characters
;	from the users terminal and send them to the NRTSRV server
;	which is running on the remote host system.
;	It is only started if PTYF is on.

DOINP0:	MOVEI T4,MAXINP		; Maximum input characters
	MOVE T3,[POINT 7,INSTR]	; Where they are going
	MOVEI T1,.PRIIN		; Primary input
	BIN			; Wait for a byte
	JRST DOIN0		; Got one, go handle it...

DOINP:	SIBE			; Any bytes?
	 SKIPA			; Yes
	JRST EMPTY		; No
	BIN			; Get another byte
DOIN0:	IDPB T2,T3		; Stash it in input stream buffer
	SOJG T4,DOINP		; Do it all
EMPTY:	MOVNI T3,MAXINP		; Maximum characters
	ADD T3,T4		; Compute number to send
	JUMPE T3,DOINP0		; If none, go wait
	MOVE T1,DCNJFN		; The network JFN
	HRROI T2,INSTR		; Pointer to input stream buffer
	SOUTR			; Send this buffer to remote MCBNRT
	JRST DOINP0		; And continue
	SUBTTL MSGTBL - Table of DECnet disconnect/abort reason text

;
; This table is used by the BADCON routine to provide an english
; text translation for the DECnet error codes which indicate why
; the network logical link connection was broken
;

;MACRO TO MAKE ENTRIES IN NSP ERROR TABLE

	MAXMSG==^D50		; Maximum number of NSP error messages

DEFINE NSPERR (CODE,TEXT,BASE<MSGTBL>),<
	.ORG BASE+CODE
	POINT 7,[ASCIZ\ TEXT\]
	.ORG
>
MSGTBL:				;DECNET ERROR TEXT TABLE

REPEAT MAXMSG,<POINT 7,[ASCIZ\: Undefined NSP error\]> ;MAKE TABLE SPACE
				; & UNDEFINED ENTRIES

	NSPERR (.DCX0,<Reject or disconnect by object>)
	NSPERR (.DCX1,<Resource allocation failure>)
	NSPERR (.DCX2,<Destination node does not exist>)
	NSPERR (.DCX3,<Remote node shutting down>)
	NSPERR (.DCX4,<Destination NVT process does not exist>)
	NSPERR (.DCX5,<Invalid process name field>)
	NSPERR (.DCX6,<NVT server is busy>)
	NSPERR (.DCX7,<Unspecified error>)
	NSPERR (.DCX8,<Abort by management>)
	NSPERR (.DCX9,<Abort by NVT server>)
	NSPERR (.DCX10,<Invalid node name>)
	NSPERR (.DCX11,<Local node shut>)
	NSPERR (.DCX21,<CI with illegal destination address>)
	NSPERR (.DCX24,<Flow control violation>)
	NSPERR (.DCX32,<Too many connections to node>)
	NSPERR (.DCX33,<Too many connections to destination NVT process>)
	NSPERR (.DCX34,<Access not permitted>)
	NSPERR (.DCX35,<Logical link services mismatch>)
	NSPERR (.DCX36,<Invalid account>)
	NSPERR (.DCX37,<Segment size too small>)
	NSPERR (.DCX38,<No response from remote system>)
	NSPERR (.DCX39,<Node unreachable>)
	NSPERR (.DCX40,<Link aborted due to data loss>)
	NSPERR (.DCX41,<Destination process does not exist>)
	NSPERR (.DCX42,<Confirmation of disconnect initiate>)
	NSPERR (.DCX43,<Image data field too long>)


	END 3,,EVEC