perm filename HOST.FAI[HST,NET]1 blob sn#715289 filedate 1983-06-06 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.FATAL This isn't ready yet!!!  -- JJW
C00008 00003	Subroutines  SWINIR SWINR1 SWINR2 SWINIP SWINP1 PRHNUM PRHNIP PRDECP PRDEC PROCT PRLOOP PDL MONCMP HSTADR HSTTOP HSTEXT
C00015 ENDMK
C⊗;
.FATAL This isn't ready yet!!!  -- JJW

TITLE HOST ;⊗ A B C X Y P PDLEN FTHST3 HOSTAB START FLSINP HSTCOM CMDSCN PROMPT DOCMD HSTLUP GOTHST GETNUM NOTIPH HSTLUZ ALPHST GOTHDB OFFNAM

A←12				;Our AC's don't interfere with NETWRK's
B←13
C←14
X←15
Y←16
P←17

PDLEN←←20

FTHST3←←1			;Use HOSTS3 host numbers
HOSTAB←←1			;Load host table routines

.INSERT NETWRK.FAI[S,NET]

START:	JFCL
	RESET
	SETZM MONCMP
	MOVE P,[IOWD PDLEN,PDL]
	PUSHJ P,MAPHST		;Map host table in core
	RESCAN A
	JUMPE A,PROMPT
	INCHRS X
	 JRST PROMPT
	CAIE X,"H"		;Check for HOST command
	 CAIN X,"h"
	  JRST HSTCOM
FLSINP:	INCHRS X
	 JRST PROMPT
	CAIE X,175
	 CAIN X,12
	  JRST PROMPT
	JRST FLSINP

HSTCOM:	OUTSTR [ASCIZ/
/]
CMDSCN:	INCHRS X
	 JRST GOTHST
	CAIE X,175
	 CAIN X,12
	  JRST GOTHST		;No command argument
	CAIE X," "
	 JRST CMDSCN
	SETOM MONCMP
	JRST DOCMD

PROMPT:	SKIPE MONCMP
	 EXIT 1,
	OUTSTR [ASCIZ/
Host name or number: /]
DOCMD:	SETZM HSTEXT
	MOVE Y,[POINT 7,HSTEXT]
HSTLUP:	INCHWL X
	ANDI X,177
	CAIN X,15
	 INCHWL X
	CAIE X,175
	 CAIN X,12
	  JRST GOTHST
	IDPB X,Y
	JRST HSTLUP

GOTHST:	SKIPN HSTEXT
	 JRST [	MOVEI A,[SIXBIT/SYS/
			 SIXBIT/HOSTAB/
			 SIXBIT/DMP/
			 0 ↔ 0 ↔ 0]
		SWAP A,]
	SETZ X,
	IDPB X,Y
;Here with input text string in HSTEXT.
	MOVE Y,[POINT 7,HSTEXT]	;Start at beginning of text
	ILDB X,Y		;Now see if we got a name or a number
	CAIL X,"0"
	 CAILE X,"9"
	  JRST ALPHST		;Alphabetic host specification
	PUSHJ P,SWINIP		;Get host number
	 JRST NOTIPH		;Not an IP host number
	JUMPN X,HSTLUZ
	MOVE 0,B		;Set up for HSTNUM
GETNUM:	PUSHJ P,HSTNUM		;Look up the number
	 JRST [ OUTSTR [ASCIZ/No such host
/]
		JRST PROMPT]
	JRST GOTHDB

;Here with a non-IP host number in A (octal) and B (decimal).
NOTIPH:	JUMPE X,[OUTSTR [ASCIZ/Incomplete host number specification
/]
		JRST PROMPT]
	CAIN X,"/"		;BBN style number?
	 JRST [	CAILE B,377
		 SETO B,
		PUSH P,B
		ILDB X,Y	;Check numericness
		CAIL X,"0"
		 CAILE X,"9"
		  JRST HSTLUZ
		PUSHJ P,SWINIR
		SKIPN B
		 SETZM (P)
		POP P,A		;A←host, B←IMP
		JUMPN X,HSTLUZ
		LSH A,=16
		ADDI A,(B)
		TLO A,(NW%ARP)	;Set network
		JRST GETNUM]
	CAIN X,"#"		;XEROX style number
	 JRST [	SKIPLE A
		CAILE A,377
		 JRST HSTLUZ
		PUSH P,A
		ILDB X,Y	;Check numericness
		CAIL X,"0"
		 CAILE X,"9"
		  JRST HSTLUZ
		PUSHJ P,SWINIR
		POP P,B		;B←subnet, A←host
		JUMPN X,HSTLUZ
		SKIPLE A
		CAILE A,377
		 JRST HSTLUZ
		LSH B,=8
		ADDI B,(A)
		MOVSI B,(NW%SU)	;Set network
		JRST GETNUM]
HSTLUZ:	OUTSTR [ASCIZ/Bad host number format
/]
	JRST PROMPT

;Here with an alphabetic host name.
ALPHST:	MOVE 0,[POINT 7,HSTEXT]
	PUSHJ P,HSTNAM		;Search for name
	 JRST [ OUTSTR [ASCIZ/No such host
/]
		JRST PROMPT]
	 JRST [ OUTSTR [ASCIZ/Ambiguous host name
/]
		JRST PROMPT]
;Here after successful return from HSTNUM or HSTNAM.
GOTHDB:	HRRZ A,1		;A ← NUMNAM
	ADD A,HSTADR
	OUTSTR (A)		;Print name
	HLRZ B,(A)		;Site table entry
	ADD B,HSTADR
	HRRZ C,(A)		;Official name
	ADD C,HSTADR
	CAIN A,(C)
	 JRST OFFNAM
	OUTSTR [ASCIZ/ is a nickname for /]
	OUTSTR (C)
	OUTSTR [ASCIZ/ which/]
OFFNAM:	OUTSTR [ASCIZ/ is number /]
;print netname if possible
;deal with multiple host numbers


;Subroutines ;⊗ SWINIR SWINR1 SWINR2 SWINIP SWINP1 PRHNUM PRHNIP PRDECP PRDEC PROCT PRLOOP PDL MONCMP HSTADR HSTTOP HSTEXT

;  Super winning numeric input routine.  Numbers are parsed as both octal and
; decimal, unless either (a) an 8 or 9 appears in the number, or (b) the number
; is followed by a decimal point.

SWINIR:	SETZB A,B			; A ← octal number, B ← decimal
SWINR1:	CAIL X,"8			; if can't be octal, A ← -1
	 SETO A,
	JUMPL A,SWINR2
	LSH A,3
	ADDI A,-"0(X)			; bring in next octal digit
SWINR2:	IMULI B,10.
	ADDI B,-"0(X)			; bring in next decimal digit
	ILDB X,Y
	CAIN X,".			; decimal point ends spec and forces decimal
	 JRST [	SETO A,
		ILDB X,Y
		POPJ P,]
	CAIL X,"0
	 CAILE X,"9
	  POPJ P,			; non-numeric, return
	JRST SWINR1

;Super winning IP host number parser.  If an IP host number is seen, then it
;will be returned in B and for IFE FTHST3, IPHOST will be set; for IFN FTHST3,
;SWINIP will skip return.  Otherwise, just like SWINIR.

SWINIP:	PUSHJ P,SWINIR		;Parse a number
	CAIL X,"0		;Check the next character
	CAILE X,"9
	POPJ P,			;Not a digit, so not an IP host number
	PUSH P,B		;Save 1st byte
	PUSHJ P,SWINP1		;Get rest of IP host number left-adj in B
	POP P,A			;Restore 1st byte
	LSHC A,-12.		;Right-adjust entire number in B
	AOS (P)			;Skip to show IP host number
	POPJ P,

;Subroutine to return an IP host number left-adjusted in B.

SWINP1:	PUSHJ P,SWINIR		;Get a number
	PUSH P,B		;Save it
	CAIL X,"0		;See if a digit follows
	CAILE X,"9
	TDZA B,B		;No.  Zero B and skip
	PUSHJ P,SWINP1		;Yes, get rest of IP host in B
	POP P,A			;Get back current byte
	LSHC A,-8.		;Shift into rest of number
	POPJ P,

;Routine to print a host number, either in SU Ethernet or IP format.  Takes
;host number in 0.
PRHNUM:	OUTCHR [" ]
	TLNE 0,740000		;Non-Internet?
	 JRST PRHNIP		;Yes, print non-IP
	LDB 1,[301000,,0]
	PUSHJ P,PRDEC		;Print first byte
	LDB 1,[201000,,0]
	PUSHJ P,PRDECP		;Print period and second byte
	LDB 1,[101000,,0]
	PUSHJ P,PRDECP		;Print period and third byte
	LDB 1,[001000,,0]
	PUSHJ P,PRDECP		;Print period and fourth byte
	OUTCHR [" ]
	POPJ P,

PRHNIP:	HLRZ 1,0		;Get left half of addr
	CAIE 1,(NW%SU)		;SU-Net?
	 POPJ P,		;No, return quietly
	LDB 1,[101000,,0]
	PUSHJ P,PROCT		;Print first byte
	OUTCHR ["#]
	LDB 1,[001000,,0]
	PUSHJ P,PROCT		;Print second byte
	OUTCHR [" ]
	POPJ P,

PRDECP:	OUTCHR [".]
PRDEC:	SKIPA 3,[10.]
PROCT:	MOVEI 3,10
PRLOOP:	IDIV 1,3
	PUSH P,2
	SKIPE 1
	 PUSHJ P,PRLOOP
	POP P,1
	ADDI 1,"0
	OUTCHR 1
	POPJ P,

PDL:	BLOCK PDLEN

MONCMP:	BLOCK 1				; -1 → got a monitor command

HSTADR:	BLOCK 1
HSTTOP:	BLOCK 1
HSTEXT:	BLOCK 25

END START