;<134-TENEX>HOSTS.MAC;11  3-Jun-80 17:31:22, Edit by LARSON
;4 upped nhsts to 513 (prime), added warning.
;<134-TENEX>HOSTS.MAC;10  2-Jun-80 18:49:49, Edit by LARSON
;3 upped NHSTN to 1200
;[SRI-KA]<134-TENEX>HOSTS.MAC;9, 26-Jan-80 14:12:28, EDIT BY Cower
;2 upped NHOSTS to 500 
;<134-TENEX>HOSTS.MAC;3     22-Jan-79             EDIT BY GENE
;1 Increased NHOSTS and NHSTN.
;<135-TENEX>HOSTS.MAC.9, 17-Nov-78 19:47:03, EDIT BY JBORCHEK
;ADD TOPS20 AND UNIX HOST TYPES
;<134-TENEX>HOSTS.MAC.100, 11-Oct-78 17:35:38, EDIT BY JBORCHEK
; MERGE IN CHANGES FOR EXTENDED LEADERS
;<134-TENEX>HOSTS.MAC;52     3-SEP-75 09:40:02    EDIT BY CALVIN
; INCREASED SIZE OF NHSTN & NHOSTS
;<133-TENEX>HOSTS.MAC;51     1-JAN-75 08:56:31    EDIT BY TOMLINSON
; FIX EOF FIX
;<133-TENEX>HOSTS.MAC;50    31-DEC-74 10:29:37    EDIT BY TOMLINSON
; TURN OFF EOF PSI CHANNEL WHILE READING FILE
;<TENEX-132>HOSTS.MAC;49    22-JUN-74 12:37:42    EDIT BY TOMLINSON
;<TENEX-132>HOSTS.MAC;48    20-JUN-74 13:11:59    EDIT BY TOMLINSON
; ADDED "NEW" KEEYWORD TO INDICATE NEW PROTOCOL HOSTS
;<TENEX-132>HOSTS.MAC;47     4-JUN-74 15:33:34    EDIT BY CLEMENTS
;<TENEX-132>HOSTS.MAC;46    31-MAR-74 12:41:29	EDIT BY CLEMENTS
;<TENEX-132>HOSTS.MAC;45    30-MAR-74 18:12:22	EDIT BY CLEMENTS
;<TENEX-132>HOSTS.MAC;44    28-MAR-74 18:20:15	EDIT BY TOMLINSON
;<TENEX-132>HOSTS.MAC;43    28-MAR-74 14:13:04	EDIT BY TOMLINSON
; SETUP GETAB TABLES WITH COUNTS
	SEARCH	PROLOG,STENEX
	TITLE	HOSTS
	SUBTTL	BUILD HOST NAME TABLES FROM FILE
	USE SWAPPC

INTERN	HSTINI,NHOSTS,NHSTN,NEWNCP,NICKNA,PNAMEP,PNMIDX
EXTERN	GTBNHN,GTBHST,CVNHST,HSTHSH,CVOHST
EXTERN	MSPACS,MRPACS,FPTA,SKPRET

; BITS AND FIELD VALUES FOR B0-8 OF HOSTN TABLE

SERVER==400000
USER==200000
NICKNA==100000
NEWNCP==400
NAME==200

TENEX==1000
ITS==2000
DEC==3000
TIP==4000
MTIP==5000
ELF==6000
ANTS==7000
MULTICS==10000
TOPS20==11000
UNIX==12000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;							;;
;;	nhosts MUST be prime for hsthsh to work		;;
;;							;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
NHOSTS==513			;; temp from 431(was 251.) ;2 ;4 was 500
NHSTN==1200			;1 (was 700) ;3 (was 1000)
MNHSTS==-NHOSTS

GS(HOSTNN,NHOSTS)
GS(HSTSTS,NHOSTS)
NGS(HOSTN,NHOSTS)
NGS(HSTNAM,NHSTN)
NGS(MHOSTS,1)

; Pointers into hostn

PNAMEP:	POINT 16,HOSTN(2),17
PNMIDX:	POINT 18,HOSTN(2),35


HSTINI:	SAVEQ
	SAVEP
	MOVEI 1,400000
	RCM			; GET CHANNELS THAT ARE ON
	PUSH P,1		; REMEMBER THEM
	MOVEI 1,400000
	MOVSI 2,(1B10)
	DIC			; TURN OFF EOF CHANNEL
	MOVSI 1,(1B2+1B17)
	HRROI 2,[ASCIZ \HOST-NAME/DESCRIPTOR-FILE.TXT\]
	GTJFN
	  JRST HSTINF		; FAIL
	PUSH P,1
	MOVE 2,[7B5+1B19]
	OPENF
	 JRST [	POP P,1
		RLJFN
		 JFCL
		JRST HSTINF]	; FAIL
	SETZM HSTNAM		; CLEAR OLD STUFF IN TABLE
	MOVSI 4,HSTNAM		; (TELNET FAILS IF THIS ISN'T DONE
	HRRI 4,HSTNAM+1		; AND IT LOOKS NEATER TO HAVE WHOLE
	BLT 4,HSTNAM+NHSTN-1	; WORD OF NULL AFTER EACH NAME)
	MOVSI 4,-NHOSTS		; CLEAR ALL HOST TABLES
HSTCLR:	SETZM HOSTN(4)
	SETZM HOSTNN(4)
	SETZM HSTSTS(4)
	AOBJN 4,HSTCLR
	MOVEI 4,HOSTN
	MOVEI 5,HSTNAM
LUP0:	PUSHJ P,GCH
	 JRST DONE
	MOVEM 3,7		; SAVE IN CASE THIS IS ALINE
	CAIN 2,12
	 JRST LUP0
	CAIGE 4,HOSTN+NHOSTS
	CAIL 5,HSTNAM+NHSTN
	 JRST FULL
	BKJFN
	 JFCL
	RFPTR
	 JFCL
	PUSH P,2
	MOVEI 3,10
	NIN
	 JRST [	HRLI 6,[ASCIZ /BAD NUMBER/]
		POP P,3
		JRST SYNERR]
	MOVE 1,2
	PUSH P,4
	PUSHJ P,CVNHST
	PUSHJ P,HSTHSH
	 JFCL
	POP P,4
	POP P,3
	JUMPL 2,FULL
	MOVEM 1,HOSTNN(2)
	HRRM 2,(4)
	MOVE 1,(P)
	BKJFN
	 JFCL
	PUSHJ P,GCH
	 JRST PEOF
	CAIE 2,","
	 JRST [	HRLI 6,[ASCIZ /MISSING COMMA AFTER HOST NUMBER/]
		JRST SYNERR]
	MOVE 6,5		; TEMP FOR BYTE POINTER
	SUBI 6,HSTNAM		; MAKE RELATIVE POINTER
	HRLM 6,0(4)		; STORE IN LH OF HOSTN
	MOVE 6,5		; TEMP POINTER AGAIN
	HRLI 6,440700		; 7 BIT LEFT JUSTIFIED

	MOVEI 10,^D39		; UP TO 39 CHARS IN HOST NAME
LUP1:	PUSHJ P,GCH		; READ NEXT CHARACTER
	 JRST PEOF
	CAIE 2,12		; TERMINATE ON END OF LINE
	CAIN 2,","
	 SETZ 2,		; OR COMMA
	IBP 6
	HRRZ 1,6		; WHERE ARE WE GOING TO PUT THIS?
	CAIL 1,HSTNAM+NHSTN	; OFF END OF TABLE?
	 JRST FULL		; YES, SAY FULL
	DPB 2,6			; STORE THE BYTE
	SOSLE 10
	JUMPN 2,LUP1		; LOOP IF NOT THE END
	MOVE 1,0(P)
	BKJFN			; GET THE TERMINATOR AGAIN
	 JFCL
	MOVEI 10,NAME		; FLAG AS HAVING A NAME
LUP2:	PUSHJ P,GCH
	 JRST PEOF
LUP2A:	CAIN 2,12
	 JRST LUP2X		; DONE IF END OF LINE
	CAIE 2,","		; SCAN UNTIL COMMA FOUND
	 JRST LUP2
	PUSHJ P,GCH		; GET FIRST LETTER OF WORD
	 JRST PEOF
	CAIN 2,","
	 JRST LUP2A		; JUMP IF NULL WORD
	CAIN 2,12
	 JRST LUP2X		; DONE IF END OF LINE

	SETZ 1,			; PUT VALUE OF WORD HERE
	CAIN 2,"A"
	 MOVEI 1,ANTS
	CAIN 2,"D"
	 MOVEI 1,DEC
	CAIN 2,"E"
	 MOVEI 1,ELF
	CAIN 2,"I"
	 MOVEI 1,ITS
	CAIN 2,"M"
	 JRST [	PUSHJ P,GCH
		 JRST PEOF
		CAIN 2,"U"
		 MOVEI 1,MULTICS
		CAIN 2,"T"
		 MOVEI 1,MTIP
		JRST ELUP3]
	CAIN 2,"N"
	 JRST [	PUSHJ P,GCH
		 JRST PEOF
		CAIN 2,"E"
		 MOVEI 1,NEWNCP
		CAIN 2,"I"
		 MOVEI 1,NICKNA
		JRST ELUP3]
	CAIN 2,"S"
	 MOVEI 1,SERVER
	CAIN 2,"T"
	 JRST [	PUSHJ P,GCH
		 JRST PEOF
		CAIN 2,"E"
		 MOVEI 1,TENEX
		CAIN 2,"I"
		 MOVEI 1,TIP
		CAIN 2,"O"
		 MOVEI 1,TOPS20
		JRST ELUP3]
	CAIN 2,"U"
	 JRST [	PUSHJ P,GCH
		 JRST PEOF
		CAIN 2,"N"
		 MOVEI 1,UNIX
		CAIN 2,"S"
		 MOVEI 1,USER
		JRST ELUP3]
ELUP3:	HRLI 6,[ASCIZ /UNRECOGNIZED FLAG NAME/]
	JUMPE 1,SYNERR		; JUMP IF NO MATCH FOUND
	MOVSI 2,(17B8)
	HRLI 6,[ASCIZ /MULTIPLE SYSTEM TYPE SPECIFICATION/]
	TDNE 2,10		; ALREADY HAVE A SYSTEM TYPE?
	TDNN 2,1		; YES AND IS THIS TRYING TO SET IT?
	 SKIPA
	  JRST SYNERR		; YES. ERROR
	IOR 10,1		; ACCUMULATE BITS
	JRST LUP2		; AND SKIP TO COMMA/EOL

LUP2X:	MOVSI 5,(1B0)		; FLAG A NICKNAME IF NEEDED
	TRZE 10,NICKNA
	 IORM 5,(4)
	HRRZ 5,(4)
	MOVEM 10,HSTSTS(5)
	MOVEI 5,1(6)		; START NEXT STRING IN NEXT WORD
	AOJA 4,LUP0		; STEP TO NEXT HOSTN SLOT AND LOOP

PEOF:	MOVE 1,0(P)
	RFPTR
	 JFCL
	MOVE 3,2
	HRLI 6,[ASCIZ /PREMATURE END OF FILE/]
SYNERR:	HLRO 1,6
	PSOUT
	HRROI 1,[ASCIZ / IN HOST DESCRIPTOR FILE
/]
	PSOUT
	MOVE 2,7
	MOVE 1,0(P)
	SFPTR			; SET BACK TO BEGINNING OF LINE
	 JFCL
	SETO 7,
PERLP:	MOVE 1,0(P)
	RFPTR
	 JFCL
	CAME 2,3
	 JRST PERLP1
	MOVEI 1,101
	RFPOS
	HRRZ 7,2
PERLP1:	MOVE 1,0(P)
	PUSHJ P,GCH1
	 MOVEI 2,12
	CAIN 2,12
	 JRST PERLPX
	MOVE 1,2
	PBOUT
	JRST PERLP

PERLPX:	HRROI 1,[ASCIZ /
/]
	PSOUT
	JUMPLE 7,PMRK
	MOVEI 1,40
	PBOUT
	SOJG 7,.-1
PMRK:	MOVEI 1,"^"
	PBOUT
	HRROI 1,[ASCIZ /

/]
	PSOUT
	JRST LUP0

FULL:	HRROI 1,[ASCIZ /HOST TABLES FULL BEFORE END OF FILE
/]
	PSOUT
	JRST DONE

DONE:	PUSH P,5
	MOVE 2,4
	SUBI 2,HOSTN
	MOVNM 2,MHOSTS		; SAVE FOR CVHST, ...
	MOVE 1,[POINT 12,GTBHST,17]
	CALL SETGTB
	POP P,2
	SUBI 2,HSTNAM
	MOVE 1,[POINT 12,GTBNHN,17]
	CALL SETGTB
	POP P,1
	CLOSF
	 JFCL
	AOS -1(P)		; SUCCESS RETURN
HSTINF:	POP P,2			; GET CHANNELS THAT WERE ON BEFORE
	MOVEI 1,400000
	AIC			; TURN THEM BACK ON
	POPJ P,

SETGTB:	PUSH P,2
	PUSH P,1
	CALL FPTA
	PUSH P,1
	CALL MRPACS
	HRLZ 2,1
	PUSH P,2
	TLO 2,40000
	MOVE 1,-1(P)
	CALL MSPACS
	MOVE 2,-3(P)
	DPB 2,-2(P)
	POP P,2
	POP P,1
	CALL MSPACS
	POP P,1
	POP P,2
	POPJ P,

GCH:	MOVE 1,-1(P)
	RFPTR
	 JFCL
	MOVEM 2,3
GCH2:	PUSHJ P,GCH1
	 POPJ P,
	CAIN 2,";"
	 JRST GCHSMC
	CAIE 2,11
	CAIN 2,40
	 JRST GCH2
GCHX:	CAIN 2,37
	 MOVEI 2,12
	AOS 0(P)
	POPJ P,

GCH1:	BIN
	CAIE 2,15
	CAIN 2,14
	 JRST GCH1
	JUMPN 2,SKPRET
GCHNUL:	GTSTS
	TLNE 2,1000
	 POPJ P,
	JRST GCH1

GCHSMC:	BIN
	CAIE 2,37
	CAIN 2,12
	 JRST GCHX
	JUMPN 2,GCHSMC
	GTSTS
	TLNN 2,1000
	 JRST GCHSMC
	POPJ P,

	END
