(FILECREATED "28-NOV-83 13:15:08" {PHYLUM}<LISPCORE>SOURCES>AOFD.;43 23390  

      changes to:  (VARS AOFDCOMS)

      previous date: " 8-NOV-83 03:14:24" {PHYLUM}<LISPCORE>SOURCES>AOFD.;42)


(* Copyright (c) 1981, 1982, 1983 by Xerox Corporation)

(PRETTYCOMPRINT AOFDCOMS)

(RPAQQ AOFDCOMS ((* Open file descriptors. This file is shared with VAX.)
		 (FNS CLOSEALL CLOSEF INPUT OPENP OUTPUT POSITION RANDACCESSP \IOMODEP)
		 (COMS (* STREAM interface to Read and Write to random memory)
		       (DECLARE: DONTCOPY (EXPORT (RECORDS BASEBYTESTREAM)))
		       (FNS \BASEBYTES.IO.INIT \MAKEBASEBYTESTREAM \MBS.OUTCHARFN 
			    \BASEBYTES.NAME.FROM.STREAM \BASEBYTES.BOUT \BASEBYTES.SETFILEPTR 
			    \BASEBYTES.READP \BASEBYTES.BIN \BASEBYTES.PEEKBIN \BASEBYTES.TRUNCATEFN 
			    \BASEBYTES.OPENFN \BASEBYTES.BLOCKIO)
		       (GLOBALVARS \BASEBYTESDEVICE)
		       (DECLARE: DONTEVAL@LOAD (P (\BASEBYTES.IO.INIT)))
		       (FNS OPENSTRINGSTREAM))
		 (FNS GETSTREAM \ADDOFD \CLEAROFD \DELETEOFD \GETSTREAM \RESETOFDS \SEARCHOPENFILES)
		 (DECLARE: DONTCOPY (EXPORT (MACROS \INSTREAMARG \OUTSTREAMARG \STREAMARG)))
		 (MACROS GETOFD \GETOFD)
		 (DECLARE: DONTEVAL@LOAD (P (MOVD? (QUOTE GETSTREAM)
						   (QUOTE GETOFD))
					    (MOVD? (QUOTE \GETSTREAM)
						   (QUOTE \GETOFD))))
		 (INITVARS (\OPENFILES))
		 (GLOBALVARS \OPENFILES)
		 (LOCALVARS . T)
		 (DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA)
										       (NLAML)
										       (LAMA)))))



(* Open file descriptors. This file is shared with VAX.)

(DEFINEQ

(CLOSEALL
  [LAMBDA (ALLFLG)                                           (* wt: "24-JUL-78 23:03")
    (DECLARE (LOCALVARS . T))

          (* The OPENP in the when catches the case where a WHENCLOSE on an earlier file closes a later file in the original
	  value of OPENP)


    (MAPCONC (OPENP)
	     (FUNCTION (LAMBDA (FL)
		 (AND (OPENP FL)
		      [OR ALLFLG (NOT (GETPROP FL (QUOTE CLOSEALL]
		      (LIST (CLOSEF FL])

(CLOSEF
  [LAMBDA (FILE)                                             (* rmk: "14-OCT-83 15:30")
    (PROG ((STREAM (\GETSTREAM FILE)))
          (COND
	    ((OR (\OUTTERMP STREAM)
		 (NOT (fetch USERCLOSEABLE of STREAM)))
	      (RETURN NIL)))
          (\CLEAROFD)
          (COND
	    ((EQ STREAM \PRIMIN.OFD)
	      (SETQ \PRIMIN.OFD \LINEBUF.OFD)))
          (COND
	    ((EQ STREAM \PRIMOUT.OFD)
	      (SETQ \PRIMOUT.OFD \TERM.OFD)))
          (\DELETEOFD STREAM)

          (* Logical close before physical close; otherwise, we might have a logically open file with no physically open 
	  file behind it. (Device LPT depends on this))


          (\CLOSEFILE STREAM)
          (RETURN (fetch FULLNAME of STREAM])

(INPUT
  [LAMBDA (FILE)                                             (* rmk: "14-OCT-83 15:30")
    (PROG1 (fetch FULLNAME of \PRIMIN.OFD)
	   (COND
	     (FILE (SETQ \PRIMIN.OFD (COND
		       ((EQ FILE T)                          (* Check explicitly for T to avoid needless creations)
			 \LINEBUF.OFD)
		       (T (\GETSTREAM FILE (QUOTE INPUT])

(OPENP
  [LAMBDA (FILE ACCESS)                                      (* rmk: "14-OCT-83 15:31")
    (DECLARE (GLOBALVARS \OPENFILES))
    (for STREAM in \OPENFILES first [COND
				      (FILE (RETURN (AND (SETQ STREAM (\GETSTREAM FILE ACCESS T))
							 (fetch FULLNAME of STREAM]
       when (AND (fetch USERVISIBLE of STREAM)
		 (\IOMODEP STREAM ACCESS T))
       collect (fetch FULLNAME of STREAM])

(OUTPUT
  [LAMBDA (FILE)                                             (* rmk: "14-OCT-83 15:31")
    (PROG1 (fetch FULLNAME of \PRIMOUT.OFD)
	   (COND
	     (FILE (SETQ \PRIMOUT.OFD (COND
		       ((EQ FILE T)                          (* Check for this special so we don't create a tty 
							     window needlessly)
			 \TERM.OFD)
		       (T (\GETSTREAM FILE (QUOTE OUTPUT])

(POSITION
  [LAMBDA (FILE N)                                           (* rmk: "14-OCT-83 15:32")
    (PROG [(STRM (COND
		   (FILE (\GETSTREAM FILE))
		   (T \PRIMOUT.OFD]
          (RETURN (PROG1 (fetch CHARPOSITION of STRM)
			 (COND
			   (N (replace CHARPOSITION of STRM with (COND
								   ((IGREATERP N 0)
								     N)
								   (T 
                                                             (* compatible with PDP-10 version)
								      0])

(RANDACCESSP
  [LAMBDA (FILE)                                             (* rmk: "14-OCT-83 15:32")
    (PROG ((STREAM (\GETSTREAM FILE)))
          (RETURN (AND (fetch RANDOMACCESSP of (fetch DEVICE of STREAM))
		       (NEQ STREAM \LINEBUF.OFD)
		       (fetch FULLNAME of STREAM])

(\IOMODEP
  [LAMBDA (STREAM ACCESS NOERROR)                            (* rmk: "21-OCT-83 11:10")
                                                             (* Returns STREAM if it represents a File open with 
							     access mode ACCESS)
    (COND
      ([COND
	  ((NOT ACCESS)
	    (fetch ACCESS of STREAM))
	  ((EQ ACCESS (fetch ACCESS of STREAM)))
	  [(EQ (fetch ACCESS of STREAM)
	       (QUOTE BOTH))
	    (FMEMB ACCESS (QUOTE (INPUT OUTPUT]
	  ((EQ (fetch ACCESS of STREAM)
	       (QUOTE APPEND))
	    (EQ ACCESS (QUOTE OUTPUT]
	STREAM)
      (T (\FILE.NOT.OPEN STREAM NOERROR])
)



(* STREAM interface to Read and Write to random memory)

(DECLARE: DONTCOPY 
(* FOLLOWING DEFINITIONS EXPORTED)


[DECLARE: EVAL@COMPILE 

(RECORD BASEBYTESTREAM STREAM (SUBRECORD STREAM)
			      (ACCESSFNS ((BIASOFFST (fetch (STREAM FW6) of DATUM)
						     (replace (STREAM FW6) of DATUM with NEWVALUE))
					  (BBSNCHARS (fetch (STREAM FW7) of DATUM)
						     (replace (STREAM FW7) of DATUM with NEWVALUE))
					  (WRITEXTENSIONFN (fetch (STREAM F1) of DATUM)
							   (replace (STREAM F1) of DATUM
							      with NEWVALUE)))))
]


(* END EXPORTED DEFINITIONS)

)
(DEFINEQ

(\BASEBYTES.IO.INIT
  (LAMBDA NIL
    (DECLARE (GLOBALVARS \BASECHARDEVICE))                   (* JonL " 8-NOV-83 03:11")
    (SETQ \BASEBYTESDEVICE (create FDEV
				   DEVICENAME ←(QUOTE BASEBYTES)
				   RESETABLE ← T
				   RANDOMACCESSP ← T
				   PAGEMAPPED ← NIL
				   FDBINABLE ← T
				   FDBOUTABLE ← T
				   FDEXTENDABLE ← NIL
				   CLOSEFILE ←(FUNCTION NILL)
				   DELETEFILE ←(FUNCTION NILL)
				   DIRECTORYNAMEP ←(FUNCTION NILL)
				   EVENTFN ←(FUNCTION NILL)
				   GENERATEFILES ←(FUNCTION \GENERATENOFILES)
				   GETFILEINFO ←(FUNCTION NILL)
				   GETFILENAME ←(FUNCTION \BASEBYTES.NAME.FROM.STREAM)
				   HOSTNAMEP ←(FUNCTION NILL)
				   OPENFILE ←(FUNCTION \BASEBYTES.OPENFN)
				   READPAGES ←(FUNCTION NILL)
				   REOPENFILE ←(FUNCTION (LAMBDA (FILE ACCESS RECOG OTHERINFO FDEV 
								       STREAM)
				       STREAM))
				   SETFILEINFO ←(FUNCTION NILL)
				   TRUNCATEFILE ←(FUNCTION (LAMBDA (STREAM I)))
				   WRITEPAGES ←(FUNCTION \ILLEGAL.DEVICEOP)
				   BIN ←(FUNCTION \BASEBYTES.BIN)
				   BOUT ←(FUNCTION \BASEBYTES.BOUT)
				   PEEKBIN ←(FUNCTION \BASEBYTES.PEEKBIN)
				   READP ←(FUNCTION \BASEBYTES.READP)
				   BACKFILEPTR ←(FUNCTION (LAMBDA (STREAM)
				       (AND (NEQ (fetch COFFSET of STREAM)
						 (fetch BIASOFFST of STREAM))
					    (\PAGEDBACKFILEPTR STREAM))))
				   SETFILEPTR ←(FUNCTION \BASEBYTES.SETFILEPTR)
				   GETFILEPTR ←(FUNCTION (LAMBDA (STREAM)
				       (IDIFFERENCE (fetch COFFSET of STREAM)
						    (fetch BIASOFFST of STREAM))))
				   GETEOFPTR ←(FUNCTION (LAMBDA (STREAM)
				       (IDIFFERENCE (fetch EOFFSET of STREAM)
						    (fetch BIASOFFST of STREAM))))
				   EOFP ←(FUNCTION (LAMBDA (STREAM)
				       (IGEQ (fetch COFFSET of STREAM)
					     (fetch EOFFSET of STREAM))))
				   BLOCKIN ←(FUNCTION (LAMBDA (STREAM BASE OFFST N)
				       (\BASEBYTES.BLOCKIO STREAM BASE OFFST N (QUOTE INPUT))))
				   BLOCKOUT ←(FUNCTION (LAMBDA (STREAM BASE OFFST N)
				       (\BASEBYTES.BLOCKIO STREAM BASE OFFST N (QUOTE OUTPUT))))
				   RENAMEFILE ←(FUNCTION \ILLEGAL.DEVICEOP)))
    (\DEFINEDEVICE NIL \BASEBYTESDEVICE)))

(\MAKEBASEBYTESTREAM
  (LAMBDA (BASE OFFST LEN ACCESS WRITEXTENSIONFN OSTREAM)    (* JonL " 7-NOV-83 23:50")
                                                             (* If an error is to occur due to non-numeric arg or 
							     range restrictions, then let it happen outside the 
							     UNINTERRUPTABLY)
    (OR BASE (ERROR "Can't use NIL as a BASE"))
    (OR (AND (SMALLP OFFST)
	     (SMALLP LEN)
	     (SMALLP (add LEN OFFST)))
	(SHOULDNT "Currently can't support fixp-sized offsets"))
    (SELECTQ ACCESS
	     (NIL (SETQ ACCESS (QUOTE INPUT)))
	     ((INPUT OUTPUT BOTH))
	     (\ILLEGAL.ARG ACCESS))
    (if (type? STREAM OSTREAM)
	then (if (EQ (ffetch (STREAM DEVICE) of OSTREAM)
		     \BASEBYTESDEVICE)
		 then (replace ACCESS of OSTREAM with NIL)
	       else (CLOSEF OSTREAM)
		    (SETQ OSTREAM (create BASEBYTESTREAM
					  DEVICE ← \BASEBYTESDEVICE smashing OSTREAM)))
      else (SETQ OSTREAM (create BASEBYTESTREAM
				 DEVICE ← \BASEBYTESDEVICE)))
    (UNINTERRUPTABLY
        (freplace USERCLOSEABLE of OSTREAM with NIL)
	(freplace USERVISIBLE of OSTREAM with NIL)
	(freplace BYTESIZE of OSTREAM with BITSPERBYTE)
	(freplace CPAGE of OSTREAM with (freplace EPAGE of OSTREAM with 0))
	(freplace CPPTR of OSTREAM with BASE)
	(freplace COFFSET of OSTREAM with (freplace BIASOFFST of OSTREAM with OFFST))
	(freplace CBUFSIZE of OSTREAM with (freplace EOFFSET of OSTREAM with LEN))
	(replace ACCESS of OSTREAM with ACCESS)

          (* Insures that the BINABLE BOUTABLE and EXTENDABLE bits are setup setup, and that the correct BIN and BOUT fns 
	  are "inherited" from the FDEV as well)


	(freplace FULLFILENAME of OSTREAM with NIL)
	(freplace OUTCHARFN of OSTREAM with (FUNCTION \MBS.OUTCHARFN))
	(freplace LINELENGTH of OSTREAM with 0)
	(freplace CHARPOSITION of OSTREAM with 0)
	(freplace WRITEXTENSIONFN of OSTREAM with (SELECTQ ACCESS
							   ((OUTPUT BOTH)
							     WRITEXTENSIONFN)
							   NIL))
	(freplace BBSNCHARS of OSTREAM with 0))
    OSTREAM))

(\MBS.OUTCHARFN
  (LAMBDA (STREAM CHAR)                                      (* JonL " 7-NOV-83 21:54")
    (BOUT (SETQ STREAM (\DTEST STREAM (QUOTE STREAM)))
	  CHAR)                                              (* The BBSNCHARS field *may* just be paralleling the 
							     CHARPOSITION field of the stream.)
    (add (ffetch BBSNCHARS of STREAM)
	 1)))

(\BASEBYTES.NAME.FROM.STREAM
  (LAMBDA (STREAM)                                           (* JonL " 7-NOV-83 21:38")
                                                             (* STRING streams have a FULLFILENAME which is just the 
							     string itself; other random basebytes streams have this 
							     field null)
    (OR (fetch FULLFILENAME of STREAM)
	(LIST (fetch CPPTR of STREAM)
	      (fetch BIASOFFST of STREAM)
	      (GETEOFPTR STREAM)))))

(\BASEBYTES.BOUT
  (LAMBDA (STREAM BYTE)                                      (* JonL " 7-NOV-83 21:14")
    (PROG (CO)
      A   (if (IGEQ (SETQ CO (fetch COFFSET of STREAM))
		    (fetch EOFFSET of STREAM))
	      then (if (SETQ CO (fetch (BASEBYTESTREAM WRITEXTENSIONFN) of STREAM))
		       then (APPLY* CO STREAM)
			    (GO A)
		     else (ERROR "Attempt to write past end of bytes block")))
          (RETURN (\PUTBASEBYTE (fetch CPPTR of STREAM)
				(PROG1 CO (freplace COFFSET of STREAM with (ADD1 CO)))
				BYTE)))))

(\BASEBYTES.SETFILEPTR
  (LAMBDA (STREAM I)                                         (* JonL " 7-NOV-83 22:56")
    (PROG ((I' I))
          (SELECTQ (SYSTEMTYPE)
		   (VAX (if (fetch FULLFILENAME of STREAM)
			    then (RETURN (replace F2 of STREAM with INDX))))
		   NIL)
          (add I'(fetch BIASOFFST of STREAM))
          (if (IGREATERP I'(fetch EOFFSET of STREAM))
	      then (ERROR "Beyond end of byte range" I)
	    else (replace COFFSET of STREAM with I')))))

(\BASEBYTES.READP
  (LAMBDA (STREAM FLG)                                       (* JonL " 7-NOV-83 21:02")
    (PROG ((CO (fetch COFFSET of STREAM))
	   (#LEFT (fetch EOFFSET of STREAM)))
          (add #LEFT (IMINUS CO))
          (RETURN (OR (IGEQ #LEFT 2)
		      (if (ZEROP #LEFT)
			  then NIL
			elseif FLG
			else (NEQ (\GETBASEBYTE (fetch CPPTR of STREAM)
						(fetch COFFSET of STREAM))
				  (CHARCODE CR))))))))

(\BASEBYTES.BIN
  (LAMBDA (STREAM)                                           (* JonL " 7-NOV-83 22:49")

          (* Normally, the microcoded version of BIN will handle this, since the BINABLE flag is set and since the COFFSET 
	  etc fields are setup appropriately)

                                                             (* Remember also that the VAX version installs a 
							     different STRMBINFN for the stringstream case)
    (PROG1 (\BASEBYTES.PEEKBIN STREAM)
	   (add (fetch COFFSET of STREAM)
		1))))

(\BASEBYTES.PEEKBIN
  (LAMBDA (STREAM NOERRORFLG)                                (* JonL " 7-NOV-83 23:41")
    (PROG ((CO (fetch COFFSET of STREAM)))
          (SELECTQ (SYSTEMTYPE)
		   (VAX (if (fetch FULLNAME of STREAM)
			    then                             (* Aha, it's a string stream)
				 (RETURN (\STRINGPEEKBIN STREAM NOERRORFLG))))
		   NIL)
          (RETURN (if (IGEQ CO (fetch EOFFSET of STREAM))
		      then (if (NOT NOERRORFLG)
			       then (STREAMOP (QUOTE ENDOFSTREAMOP)
					      STREAM STREAM))
		    else (\GETBASEBYTE (fetch CPPTR of STREAM)
				       CO))))))

(\BASEBYTES.TRUNCATEFN
  (LAMBDA (STREAM I)                                         (* JonL " 7-NOV-83 22:20")
    ((LAMBDA (I' BO EO)
	(add I' BO)
	(if (ILESSP I 0)
	    then (add I' EO))
	(if (OR (ILESSP I BO)
		(IGREATERP I' EO))
	    then (ERROR "Beyond end of byte range" I)
	  else (replace EOFFSET of STREAM with I')))
      I
      (fetch BIASOFFST of STREAM)
      (fetch EOFFSET of STREAM))))

(\BASEBYTES.OPENFN
  (LAMBDA (NAME ACCESS RECOG OTHERINFO FDEV)                 (* JonL " 7-NOV-83 23:40")
    (OR (STREAMP NAME)
	(HELP NAME "Why isn't this a STREAMP"))
    (if (fetch FULLFILENAME of NAME)
	then (OPENSTRINGSTREAM NAME ACCESS)
      else (\MAKEBASEBYTESTREAM (fetch CPPTR of NAME)
				(fetch BIASOFFST of NAME)
				(GETEOFPTR NAME)
				ACCESS
				(fetch WRITEXTENSIONFN of NAME)
				NAME))))

(\BASEBYTES.BLOCKIO
  [LAMBDA (STREAM BASE OFFST N DIRECTION)                    (* JonL " 8-JUL-83 01:54")
    (PROG (SBASE CO EO)
      A   (if (ILEQ N 0)
	      then (RETURN))
          (SETQ SBASE (fetch CPPTR of STREAM))
          (SETQ CO (fetch COFFSET of STREAM))
          (SETQ EO (fetch EOFFSET of STREAM))
          (if (IGREATERP N (IDIFFERENCE EO (SUB1 CO)))
	      then (if (EQ DIRECTION (QUOTE INPUT))
		       then (STREAMOP (QUOTE ENDOFSTREAMOP)
				      STREAM STREAM)
		     else                                    (* Do a single BOUT to see if the WRITEXTENSIONFN will 
							     fix it up)
			  (BOUT STREAM (\GETBASEBYTE BASE OFFST))
			  (add OFFST 1)
			  (add N -1)
			  (GO A)))
          (replace COFFSET of STREAM with (IPLUS CO N))
          (if (EQ DIRECTION (QUOTE OUTPUT))
	      then (swap SBASE BASE)
		   (swap CO OFFST))
          (\MOVEBYTES SBASE CO BASE OFFST N])
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS \BASEBYTESDEVICE)
)
(DECLARE: DONTEVAL@LOAD 
(\BASEBYTES.IO.INIT)
)
(DEFINEQ

(OPENSTRINGSTREAM
  (LAMBDA (STR)                                              (* JonL " 8-NOV-83 02:41")

          (* Does not register the stream on \OPENFILES, nor does it search \OPENFILES for a previously opened stream.
	  Thus, this implementation does not side-effect the string as the 10 does. However, the temporary coercion of 
	  strings to open streams in \GETSTREAM does simulate the side-effecting. STR can be a stream, if OPENSTREAM is 
	  called on a previously created stream stream, e.g. from OPENFILE)


    (DECLARE (GLOBALVARS \STRINGFDEV))
    (PROG (BASE OFFST LEN STREAM)
          (OR (STRINGP STR)
	      (if (AND (type? STREAM STR)
		       (STRINGP (fetch FULLNAME of STR)))
		  then (if (\IOMODEP STR (QUOTE INPUT)
				     T)
			   then                              (* Open properly)
				(RETURN STR)
			 elseif (\IOMODEP STR NIL T)
			   then                              (* Closed, re-open below.)
				(SETQ STR (fetch FULLNAME of (SETQ STREAM STR)))
			 else (\FILE.WONT.OPEN STR))
		else (\ILLEGAL.ARG STR)))
          (SETQ STREAM (\MAKEBASEBYTESTREAM (OR (fetch (STRINGP BASE) of STR)
						T)
					    (fetch (STRINGP OFFST) of STR)
					    (fetch (STRINGP LENGTH) of STR)
					    (QUOTE INPUT)
					    NIL STREAM))
          (PROGN                                             (* Minor differences between a basebytestream and a 
							     stringstream)
		 (freplace FULLFILENAME of STREAM with STR)
                                                             (* Actually, a non-null FULLFILENAME field is what 
							     distinguishes the two kind of stream)
		 (freplace USERCLOSEABLE of STREAM with T)
		 (freplace USERVISIBLE of STREAM with T)
		 (SELECTQ (SYSTEMTYPE)
			  (VAX (freplace F2 of STREAM with 0)
			       (freplace STRMBINFN of STREAM with (FUNCTION \STRINGBIN)))
			  NIL))
          (RETURN STREAM))))
)
(DEFINEQ

(GETSTREAM
  [LAMBDA (FILE ACCESS)                                      (* rmk: "14-OCT-83 15:27")
                                                             (* USER ENTRY)
    (\GETSTREAM FILE ACCESS])

(\ADDOFD
  [LAMBDA (STREAM)                                           (* rmk: "21-OCT-83 16:32")
                                                             (* Returns the STREAM it adds to \OPENFILES)
    (\CLEAROFD)
    (AND (fetch NAMEDP of STREAM)
	 (push \OPENFILES STREAM))
    STREAM])

(\CLEAROFD
  [LAMBDA NIL                                                (* lmm "30-SEP-80 20:08")
                                                             (* IF GETOFD CACHES ITS ARGS, THIS CAN CLEAR THE CACHE)
    ])

(\DELETEOFD
  [LAMBDA (OFD)                                              (* rmk: "25-OCT-79 08:20")
    (SETQ \OPENFILES (DREMOVE OFD \OPENFILES])

(\GETSTREAM
  [LAMBDA (X ACCESS NOERROR)                                 (* rmk: "25-OCT-83 18:47")

          (* \GETSTREAM accepts either a: file name, a file handle, stream, a string, NIL, T, or a partial file name.
	  -
	  ACCESS is INPUT, OUTPUT, APPEND, BOTH or NIL -
	  NOERROR, if non-NIL, means to return NIL if the file is not open in the specified access mode;
	  otherwise, an error is caused)


    (DECLARE (GLOBALVARS \DEFAULTLINEBUF \DEFAULTTTYDISPLAYSTREAM))
    (COND
      ((NULL X)
	(SELECTQ ACCESS
		 (INPUT (COND
			  ((EQ \PRIMIN.OFD \DEFAULTLINEBUF)
			    (\CREATE.TTYDISPLAYSTREAM)))
			\PRIMIN.OFD)
		 (OUTPUT (COND
			   ((AND \DEFAULTTTYDISPLAYSTREAM (EQ \PRIMOUT.OFD \DEFAULTTTYDISPLAYSTREAM))
			     (\CREATE.TTYDISPLAYSTREAM)))
			 \PRIMOUT.OFD)
		 (\IOMODEP (COND
			     ((NOT (EQ \PRIMIN.OFD \LINEBUF.OFD))
			       \PRIMIN.OFD)
			     (T \PRIMOUT.OFD))
			   ACCESS NOERROR)))
      ((EQ X T)
	(SELECTQ ACCESS
		 (INPUT (COND
			  ((EQ \LINEBUF.OFD \DEFAULTLINEBUF)
			    (\CREATE.TTYDISPLAYSTREAM)))
			\LINEBUF.OFD)
		 ((OUTPUT NIL)
		   (COND
		     ((AND \DEFAULTTTYDISPLAYSTREAM (EQ \TERM.OFD \DEFAULTTTYDISPLAYSTREAM))
		       (\CREATE.TTYDISPLAYSTREAM)))
		   \TERM.OFD)
		 (\FILE.NOT.OPEN X NOERROR)))
      ((type? STREAM X)
	(\IOMODEP X ACCESS NOERROR))
      ((LITATOM X)
	(OR (\SEARCHOPENFILES X ACCESS)
	    (\SEARCHOPENFILES (\GETFILENAME X (QUOTE OLD))
			      ACCESS)
	    (\FILE.NOT.OPEN X NOERROR)))
      [(STRINGP X)
	(OR (\SEARCHOPENFILES X ACCESS)
	    (\ADDOFD (OPENSTRINGSTREAM X ACCESS]
      ((type? WINDOW X)
	(fetch (WINDOW DSP) of X))
      (T (\FILE.NOT.OPEN X NOERROR])

(\RESETOFDS
  [LAMBDA NIL                                                (* rrb "22-JUL-83 15:51")
    (DECLARE (GLOBALVARS \OPENFILES))
    [MAP.PROCESSES (FUNCTION (LAMBDA NIL
		       (\OPENLINEBUF)
		       (SETQ \PRIMOUT.OFD \TERM.OFD)
		       (SETQ \PRIMIN.OFD \LINEBUF.OFD)
		       (SETQ \DRIBBLE.OFD]
    (for OFD in \OPENFILES
       do (replace CPPTR of OFD with NIL)
	  (FORGETPAGES OFD)
	  (replace ACCESS of OFD with NIL))                  (* Perhaps do the AFTER function ?)
    (SETQ \OPENFILES])

(\SEARCHOPENFILES
  [LAMBDA (NAME ACCESS)                                      (* rmk: "14-OCT-83 15:04")
                                                             (* Returns a stream whose fullname is NAME if it has 
							     accessmode ACCESS)
    (for STREAM in \OPENFILES when (EQ NAME (fetch FULLNAME of STREAM))
       do (RETURN (COND
		    (ACCESS (\IOMODEP STREAM ACCESS T))
		    (T STREAM])
)
(DECLARE: DONTCOPY 
(* FOLLOWING DEFINITIONS EXPORTED)


(DECLARE: EVAL@COMPILE 

(PUTPROPS \INSTREAMARG MACRO ((STRM NOERRORFLG)
  (\GETSTREAM STRM (QUOTE INPUT)
	      NOERRORFLG)))

(PUTPROPS \OUTSTREAMARG MACRO ((STRM NOERRORFLG)
  (\GETSTREAM STRM (QUOTE OUTPUT)
	      NOERRORFLG)))

(PUTPROPS \STREAMARG MACRO (OPENLAMBDA (STRM NOERRORFLG)
  (COND
    (NOERRORFLG (\GETSTREAM STRM NIL T))
    (T (\DTEST STRM (QUOTE STREAM))))))
)


(* END EXPORTED DEFINITIONS)

)
(DECLARE: EVAL@COMPILE 

(PUTPROPS GETOFD MACRO (= . GETSTREAM))

(PUTPROPS \GETOFD MACRO (= . \GETSTREAM))
)
(DECLARE: DONTEVAL@LOAD 
(MOVD? (QUOTE GETSTREAM)
       (QUOTE GETOFD))
(MOVD? (QUOTE \GETSTREAM)
       (QUOTE \GETOFD))
)

(RPAQ? \OPENFILES )
(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS \OPENFILES)
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(LOCALVARS . T)
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA )
)
(PUTPROPS AOFD COPYRIGHT ("Xerox Corporation" 1981 1982 1983))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1570 5509 (CLOSEALL 1580 . 2034) (CLOSEF 2036 . 2798) (INPUT 2800 . 3171) (OPENP 3173
 . 3637) (OUTPUT 3639 . 4043) (POSITION 4045 . 4540) (RANDACCESSP 4542 . 4862) (\IOMODEP 4864 . 5507))
 (6156 16380 (\BASEBYTES.IO.INIT 6166 . 8366) (\MAKEBASEBYTESTREAM 8368 . 10669) (\MBS.OUTCHARFN 10671
 . 11057) (\BASEBYTES.NAME.FROM.STREAM 11059 . 11565) (\BASEBYTES.BOUT 11567 . 12165) (
\BASEBYTES.SETFILEPTR 12167 . 12718) (\BASEBYTES.READP 12720 . 13202) (\BASEBYTES.BIN 13204 . 13764) (
\BASEBYTES.PEEKBIN 13766 . 14427) (\BASEBYTES.TRUNCATEFN 14429 . 14895) (\BASEBYTES.OPENFN 14897 . 
15366) (\BASEBYTES.BLOCKIO 15368 . 16378)) (16505 18585 (OPENSTRINGSTREAM 16515 . 18583)) (18586 22288
 (GETSTREAM 18596 . 18816) (\ADDOFD 18818 . 19139) (\CLEAROFD 19141 . 19374) (\DELETEOFD 19376 . 19530
) (\GETSTREAM 19532 . 21266) (\RESETOFDS 21268 . 21833) (\SEARCHOPENFILES 21835 . 22286)))))
STOP