(FILECREATED "21-Jun-85 19:31:33" {ERIS}<LISPCORE>LIBRARY>TCPHTE.;2 5829   

      previous date: "15-Apr-85 16:53:27" {ERIS}<LISPCORE>LIBRARY>TCPHTE.;1)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT TCPHTECOMS)

(RPAQQ TCPHTECOMS ((RECORDS HOSTS.TXT.ENTRY HTELINE)
		   (FNS ADDASSOC \HTE.PARSE.ENTRY \HTE.READ.FILE \HTE.READ; \HTE.READLINE)
		   (INITVARS (HOSTS.TEXT.DIRECTORIES))))
[DECLARE: EVAL@COMPILE 

(DATATYPE HOSTS.TXT.ENTRY (HTE.TYPE HTE.ADDRESSES HTE.NAMES HTE.MACHINE.TYPE HTE.OS.TYPE 
				    HTE.PROTOCOLS))

(RECORD HTELINE (TYPE ADDRESSES NAMES MACHINE.TYPE OS.TYPE PROTOCOLS))
]
(/DECLAREDATATYPE (QUOTE HOSTS.TXT.ENTRY)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER POINTER))
		  (QUOTE ((HOSTS.TXT.ENTRY 0 POINTER)
			  (HOSTS.TXT.ENTRY 2 POINTER)
			  (HOSTS.TXT.ENTRY 4 POINTER)
			  (HOSTS.TXT.ENTRY 6 POINTER)
			  (HOSTS.TXT.ENTRY 8 POINTER)
			  (HOSTS.TXT.ENTRY 10 POINTER)))
		  (QUOTE 12))
(DEFINEQ

(ADDASSOC
  (LAMBDA (KEY VAL ALIST)                                    (* ejs: "27-Jan-85 21:15")
    (LET ((OLDLST (FASSOC KEY ALIST)))
      (COND
	(OLDLST (push (CDR OLDLST)
		      VAL))
	(T (NCONC1 ALIST (LIST KEY VAL)))))))

(\HTE.PARSE.ENTRY
  (LAMBDA (ENTRY)                                            (* ejs: "27-Jan-85 21:43")
    (LET ((HTE.ENTRY (create HOSTS.TXT.ENTRY
			     HTE.TYPE ←(CAR (fetch (HTELINE TYPE) of ENTRY))
			     HTE.ADDRESSES ←(for X in (fetch (HTELINE ADDRESSES) of ENTRY)
					       collect (\IP.READ.STRING.ADDRESS (MKSTRING X)))
			     HTE.NAMES ←(fetch (HTELINE NAMES) of ENTRY)
			     HTE.MACHINE.TYPE ←(CAR (fetch (HTELINE MACHINE.TYPE) of ENTRY))
			     HTE.OS.TYPE ←(CAR (fetch (HTELINE OS.TYPE) of ENTRY))))
       (PROTOLST (fetch (HTELINE PROTOCOLS) of ENTRY))
       (PROTOCOLS (CONS)))
      (for PROTOENTRY in PROTOLST do (COND
				       ((STRPOS (QUOTE /)
						PROTOENTRY)
					 (ADDASSOC (SUBATOM PROTOENTRY 1 (SUB1 (STRPOS (QUOTE /)
										       PROTOENTRY)))
						   (SUBATOM PROTOENTRY (STRPOS (QUOTE /)
									       PROTOENTRY NIL NIL NIL 
									       T))
						   PROTOCOLS))))
      (replace (HOSTS.TXT.ENTRY HTE.PROTOCOLS) of HTE.ENTRY with (CDR PROTOCOLS))
      (for NAME in (fetch (HTELINE NAMES) of ENTRY) do (PUTHASH NAME HTE.ENTRY \IP.HOSTNAMES)))))

(\HTE.READ.FILE
  (LAMBDA (FILE WANTEDTYPES)                                 (* ejs: "27-Jan-85 21:52")
    (DECLARE (GLOBALVARS \IP.HOSTNAMES))
    (CLRHASH \IP.HOSTNAMES)
    (SETQ FILE (OPENSTREAM FILE (QUOTE INPUT)
			   (QUOTE OLD)))
    (OR WANTEDTYPES (SETQ WANTEDTYPES (QUOTE (HOST))))
    (bind (SCRATCHLST ←(LIST NIL NIL NIL NIL NIL NIL))
	  ENTRY until (EOFP FILE)
       do (SETQ ENTRY (\HTE.READLINE FILE SCRATCHLST))
	  (COND
	    ((FMEMB (CAR (fetch (HTELINE TYPE) of ENTRY))
		    WANTEDTYPES)
	      (\HTE.PARSE.ENTRY ENTRY))))
    (CLOSEF FILE)))

(\HTE.READ;
  (LAMBDA (FL RDTBL)                                         (* ejs: "27-Jan-85 20:19")
    (until (SELCHARQ (BIN FL)
		     ((CR LF EOL)
		       T)
		     NIL))
    NIL))

(\HTE.READLINE
  (LAMBDA (STREAM SCRATCHLST WANTEDTYPES)                    (* ejs: "27-Jan-85 21:55")
    (COND
      (SCRATCHLST (for X on SCRATCHLST do (RPLACA X NIL)))
      (T (SETQ SCRATCHLST (LIST NIL NIL NIL NIL NIL NIL))))
    (bind CHARS FIELDCONTENTS CH (FIELD# ← 1)
       do (COND
	    ((NOT (EOFP STREAM))
	      (SETQ CH (BIN STREAM))
	      (SELCHARQ CH
			(: (COND
			     (CHARS (push FIELDCONTENTS (PACKC (DREVERSE CHARS)))
				    (SETQ CHARS)))
			   (COND
			     (FIELDCONTENTS (RPLACA (FNTH SCRATCHLST FIELD#)
						    (DREVERSE FIELDCONTENTS))
					    (SETQ FIELDCONTENTS)
					    (add FIELD# 1)
					    (COND
					      ((AND (EQ FIELD# 2)
						    (NOT (FMEMB (CAAR SCRATCHLST)
								WANTEDTYPES)))
						(until (OR (EOFP STREAM)
							   (NOT (SELCHARQ (\PEEKBIN STREAM)
									  ((CR EOL LF)
									    T)
									  NIL)))
						   do (\HTE.READ; STREAM)))))))
			(; (\HTE.READ; STREAM)
			   (RETURN))
			((SPACE TAB ,)
			  (COND
			    (CHARS (push FIELDCONTENTS (PACKC (DREVERSE CHARS)))
				   (SETQ CHARS))))
			((EOL CR LF)
			  (until (OR (EOFP STREAM)
				     (NOT (SELCHARQ (\PEEKBIN STREAM)
						    ((CR EOL LF)
						      T)
						    NIL)))
			     do (BIN STREAM))
			  (COND
			    ((OR (EOFP STREAM)
				 (SELCHARQ (\PEEKBIN STREAM)
					   ((SPACE TAB)
					     NIL)
					   T))
			      (RETURN SCRATCHLST))))
			(push CHARS CH)))
	    (T (COND
		 (CHARS (push FIELDCONTENTS (PACKC (DREVERSE CHARS)))
			(SETQ CHARS)))
	       (COND
		 (FIELDCONTENTS (RPLACA (FNTH SCRATCHLST FIELD#)
					(DREVERSE FIELDCONTENTS))
				(SETQ FIELDCONTENTS)
				(add FIELD# 1)
				(COND
				  ((AND (EQ FIELD# 2)
					(NOT (FMEMB (CAAR SCRATCHLST)
						    WANTEDTYPES)))
				    (until (OR (EOFP STREAM)
					       (NOT (SELCHARQ (\PEEKBIN STREAM)
							      ((CR EOL LF)
								T)
							      NIL)))
				       do (\HTE.READ; STREAM))))))
	       (RETURN SCRATCHLST))))))
)

(RPAQ? HOSTS.TEXT.DIRECTORIES )
(PUTPROPS TCPHTE COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (984 5715 (ADDASSOC 994 . 1255) (\HTE.PARSE.ENTRY 1257 . 2549) (\HTE.READ.FILE 2551 . 
3219) (\HTE.READ; 3221 . 3425) (\HTE.READLINE 3427 . 5713)))))
STOP