9/5/71    - RMS -

***** THIS FACILITY, AND THESE FUNCTIONS, EXIST ONLY IN THE VERSION 
	OF MACLISP CURRENTLY CALLED "NLISP" AND ARE NOT STANDARD YET 
	[AS OF DECEMBER 1972]

CHANGES TO NLISP I-O:

CONTENTS:
	FILES, AND HOW TO OPEN THEM
	SELECTION FOR INPUT
	ENABLING FOR OUTPUT
	NEW LPT OUTPUT FORMAT
	EOF HANDLING
	NEW STATUS CALLS
	OTHER NEW FUNCTIONS
	OLD I-O FUNCTIONS
	INCOMPATIBILITIES

FILES, AND HOW TO OPEN THEM:

	A FILE IN LISP IS REFERRENCED THROUGH A FILE-ARRAY.
A FILE-ARRAY IS AN ATOM WITH A FILE PROPERTY OF A SPECIAL TYPE;
IT CONTAINS TWO FILENAMES, A DEVICE NAME, AND A SYSTEM NAME;
AN EOF FUNCTION RELEVANT ONLY TO INPUT;
AND A CHRCT AND A LINEL RELEVANT ONLY TO OUTPUT.
IT ALSO CONTAINS OTHER INTERNAL DATA.

	TO OPEN A FILE, USE THE LSUBRS OPENI AND OPENO,
FOR INPUT AND OUTPUT, RESPECTIVELY.
THEY WILL BE REFERRED TO COLLECTIVELY AS 'OPEN.

	OPEN CAN TAKE AN ATOMIC ARG, A LIST ARG, NEITHER, OR BOTH.
IF THERE IS NO ATOMIC ARG, OPEN WILL GENSYM ONE.
IF THE ATOM IS NOT A FILE-ARRAY, OPEN WILL MAKE IT ONE,
	AND PUT IN THE DEFAULT NAMES, LINEL, AND EOFFN.
IF THERE WAS A LIST ARG, THE NAMES IN IT WILL BE
	MERGED IN TO THOSE IN THE FILE-ARRAY.
THE RESULTING SET OF NAMES SPECIFIES THE FILE, WHICH IS THEN OPENED.
THE VALUE OF OPEN IS THE FILE-ARRAY.

EXAMPLES:
	(OPENI UREAD) RE-OPENS THE UREAD FILE, TO START AT THE
		 BEGINNING AGAIN. (SEE "OLD I-O FUNCTIONS")
	(SETQ Z (OPENI '(NEW CLAP COM))) OPENS COM:NEW CLAP
		IN A FILE-ARRAY WHICH OPEN CREATES, AND PUTS IT IN Z.
	(OPENI 'Z '(NEW CLAP COM)) MAKES Z A FILE-ARRAY,
		AND OPENS COM:NEW CLAP IN IT.

	IT IS ADVISABLE TO HAVE OPEN GENSYM ALL FILE-ARRAYS, SO
THAT THEY WILL BE UNINTERNED, AND THEREFORE SUBJECT TO GC; AND WILL
AUTOMATICALLY BE CLOSED ANG GO AWAY WHEN NO LONGER NEEDED.
THIS REQUIRES THAT EACH ONE BE PUT WHERE IT CAN BE FOUND WHEN
IT IS RETURNED BY OPEN (E.G. BY SETING A VARIABLE TO IT,
SELECTING OR ENABLING IT).
SELECTION FOR INPUT:

	SINCE THERE CAN BE SEVERAL FILES OPEN FOR INPUT AT ONCE,
AS WELL AS THE TTY, THERE EXISTS A SPECIAL MECHANISM FOR TELLING
LISP WHICH INPUT SOURCE TO READ FROM. LISP REMEMBERS:
	A CURRENTLY SELECTED INPUT SOURCE; AND
	A STACK, ACTUALLY IN THE FORM OF A LIST, OF PREVIOUSLY
	   SELECTED INPUT SOURCES WHICH HAVE BEEN PUSHED DOWN.
AN INPUT SOURCE IS EITHER A FILE-ARRAY OPEN FOR INPUT,
	OR NIL FOR THE TTY.

	INPUT SOURCES ARE SELECTED BY THE SUBRS INSEL AND INPUSH.
(INSEL X) SELECTS THE INPUT SOURCE X.
(INPUSH X), WHERE X IS AN INPUT SOURCE,PUSHES THE CURRENTLY
	SELECTED INPUT SOURCE ONTO THE SELECTION STACK-LIST,
	AND THEN SELECTS X.
(INPUSH 0) DOES NOTHING BUT RETURN THE CURRENTLY SELECTED SOURCE.
(INPUSH -1) POPS THE FIRST INPUT SOURCE OFF THE SPECIAL STACK,
	AND SELECTS IT.(INPUSH -2) DOES THAT TWICE, ETC.
(INPUSH 1) IS LIKE (INPUSH (INPUSH 0))
	(INPUSH 2) DOES THAT TWICE, ETC.
INSEL AND INPUSH ALWAYS RETURN THE INPUT SOURCE SELECTED
WHEN THEY EXIT.
ANY INPUSH OR INSEL THAT SELECTS THE TTY, EXCEPT (INPUSH 0),
TURNS OFF THE ^Q SWITCH.

	IF THE ^Q SWITCH IS SET, ALL ORDINARY LISP INPUT FUNCTIONS
TAKE THEIR INPUT FROM THE CURRENTLY SELECTED INPUT SOURCE.
	OTHERWISE, THEY READ FROM THE TTY, WHATEVER IS SELECTED.

ENABLING FOR OUTPUT:

	IF A FILE IS TO BE WRITTEN ON, IT MUST FIRST BE ENABLED.
LISP KEEPS RECORDS OF WHICH OUTPUT CHANNELS ARE ENABLED.
ANY SET OF OUTPUT CHANNELS MAY BE ENABLED AT ONCE.
(AN OUTPUT CHANNEL IS EITHER A FILE-ARRAY OPEN FOR OUTPUT,
	OR NIL FOR THE TTY)

	OUTPUT CHANNELS ARE ENABLED AND DISABLED WITH THE SUBR ENABLE.
(ENABLE X T) ENABLES OUTPUT CHANNEL X
(ENABLE X NIL) DISABLES IT
ENABLE RETURNS NON-NIL IFF THE OUTPUT CHANNEL IS ENABLED.
(ENABLEP X) RETURNS THE SAME THING.

	ALL ORDINARY LISP OUTPUT WILL GO TO ALL ENABLED FILE-ARRAYS
IFF THE ^R SWITCH IS NON-NIL.
	OUTPUT WILL GO TO THE TTY IFF IT IS ENABLED.
	(NOTE: THE ENABLE SWITCH FOR THE TTY IS JUST (NULL ^W))

	WHEN A FILE HAS BEEN COMPLETELY WRITTEN, IT MUST BE CLOSED
TO WRITE OUT THE LAST BUFFERFULL. IT IS ADVISABLE TO CLOSE
INPUT FILES ALSO, WHEN THEY ARE NO LONGER NEEDED.

(CLOSE X) CLOSES THE FILE-ARRAY X, AND RETURNS IT.
	IN CASE IT WAS OPEN FOR INPUT:
	X IS DELETED FROM THE SELECTION STACK, AND IF IT IS SELECTED,
	  (INPUSH -1) IS DONE TO DESELECT IT.
	IF X IS EQ TO UREAD, (SETQ UREAD NIL) IS DONE.
	SIMILAR FOR 'UWRITE, IN CASE WAS OPEN FOR OUTPUT.

CLOSING A FILE-ARRAY NOT OPEN HAS NO EFFECT.
CLOSING NIL IS AN ERROR.
NEW LINE PRINTER OUTPUT FORMAT:

TYPING CNTRL-B CAUSES OUTPUT TO THE LINE PRINTER AS FOLLOWS:
(IF THE LPT IS NOT AVAILABLE, OUTPUT WILL BE TO TPL INSTEAD,
AND "
SPOOLING LPT
" WILL BE PRINTED ON THE TTY IF IT (THE TTY) IS ENABLED)

	ALL S-EXPRESSIONS READ FROM THE TTY WILL BE PRINTED
ON THE LPT, PRECEDED BY "
    *	".
ORDINARY OUTPUT LINES WILL BE PRECEDED BY A TAB.
THUS, THE FOLLOWING ON THE TTY:
(PLUS 5 (REEADDAEAD))4
9

COULD CAUSE THE FOLLOWING ON THE LPT:

    *	(PLUS 5 (READ))
    *	4
	9

	THE LPT HAS NO FILE-ARRAY WHEN OPEN IN THIS MODE.
THE USUAL I-O FUNCTIONS WON'T WORK ON IT.
IT CAN BE DISABLED AND CLOSED ONLY BY TYPING ^E (OR EVALLING
(IOC E), OF COURSE).
THE SAME CHRCT AND LINEL ARE USED FOR THE TTY AND LPT.

ORDINARY OUTPUT CAN BE DONE TO THE LPT BY OPENING IT NORMALLY.

EOF HANDLING:

	NORMALLY, EOF CAUSES THE SELECTED FILE TO BE CLOSED,
(AND THUS POPPED BY (INPUSH -1) WHICH CLOSE DOES).
IF WITHIN (READ), (READCH), ETC., READING WILL CONTINUE WITH THE
INPUT SOURCE WHICH IS THEN SELECTED.
IF WITHIN (READ X), (READCH X), ETC., READING WILL STOP 
AND X WILL BE RETURNED.

	OTHER ACTIONS CAN BE OBTAINED BY GIVING A FILE-ARRAY A
NON-NIL EOF FUNCTION. IF THAT IS DONE, THEN IF EOF OCCURS ON THAT
FILE, THE EOF FUNCTION WILL BE CALLED WITH ONE ARG, WHICH WILL
BE NIL IF THE READ, READCH ETC. IN PROGRESS HAD NO ARG,
(LIST ARG) IF IT HAD ONE (WITHIN (READ X) IT WOULD BE (LIST X)).
IF THE EOF FUNCTION RETURNS NIL, THE SELECTED INPUT SOURCE IS
  CLOSED, AND READING CONTINUES FROM THE SOURCE POPPED TO.
IF IT RETURNS T, READING WILL CONTINUE IMMEDIATELY.
  (FROM THE SOURCE THE EOF FUNCTION LEFT SELECTED)
OTHERWISE, THE SELECTED SOURCE WILL BE CLOSED,
  AND READ, READCH, ETC. WILL RETURN THE CAR OF WHAT THE
  EOF FUNCTION RETURNED.
NEW STATUS AND SSTATUS CALLS:

(STATUS ENABL)	RETURNS A LIST OF ALL ENABLED OUTPUT CHANNELS.
(SSTATUS ENABL X)	CAUSES ONLY THOSE OUTPUT CHANNELS IN THE LIST
		X TO BE ENABLED. RETURNS X.

THE FOLLOWING CALLS REFER TO THE DEFAULTS IF X IS NIL:

(STATUS FILE X)	WHERE X IS A FILE-ARRAY,
		RETURNS A LIST OF THE NAMES STORED IN X AS:
		(FN1 FN2 DEV SNAME).
(SSTATUS FILE X Y)	PUTS THE NAMES IN Y INTO THE FILE-ARRAY X.
		IF A NAME IN Y IS $$ (ALTMODE-ALTMODE),
		THE NAME IN X WON'T BE CHANGED.
(STATUS RFILE X) WHERE X IS A FILE ARRAY WHICH IS NOT OPEN,
		IS EQUIVALENT TO (STATUS FILE X).
		BUT, IF X IS OPEN, THE NAMES OF THE FILE ACTUALLY OPEN ARE RETURNED.
(SSTATUS RFILE X Y)	LIKE (SSTATUS FILE X Y),
		BUT RETURNS (STATUS RFILE X).
(STATUS EOFFN X)	RETURNS X'S EOF FUNCTION
(SSTATUS EOFFN X Y)	SETS X'S EOF FUNCTION TO Y, RETURNS Y.
(STATUS LINEL X)	RETURNS X'S LINEL.
		THE TTY ALWAYS USES THE DEFAULT LINEL.
(SSTATUS LINEL X Y)	SETS X'S LINEL TO Y, RETURNS Y.
		IF A LINEL IS 0, NO EXTRA CRLF'S WILL BE OUTPUT.
(STATUS CHRCT X)	RETURNS X'S CHRCT. THERE IS NO DEFAULT CHRCT;
		(STATUS CHRCT NIL) RETURNS THE TTY'S CHRCT.
(SSTATUS CHRCT X Y)	SETS X'S CHRCT.
		(SSTATUS CHRCT NIL Y)	SETS THE TTY'S CHRCT.
(STATUS CHNUM X)	RETURNS NON-NIL IFF X IS OPEN.
		(STATUS CHNUM NIL) IS NIL .

OTHER NEW FUNCTIONS:

RENAME  --  SUBR.
	(RENAME X Y), WHERE X IS A FILE-ARRAY, RENAMES THE FILE OPEN
	IN X, OR THE FILE WHOSE NAMES ARE IN X, AS THE NAMES IN Y.
	THE NEW NAMES ARE PUT IN X, WHICH IS RETURNED.
	NAMES IN Y WHICH ARE $$ ARE LEFT UNCHANGED.
	IF X ISN'T OPEN, DEVICE AND SNAME CAN COME FROM Y.
	IF X IS OPEN, ANY DEVICE OR SNAME IN Y IS IGNORED.

	IF X IS A LIST OF NAMES, THEY ARE PUT OVER THE DEFAULT NAMES
	TO GET THE NAMES OF THE FILE TO BE RENAMED AS THE NAMES IN Y.
	IN THIS CASE, Y IS RETURNED.

READFILE  --  LSUBR.
	(READFILE X) RETURNS (READ), DONE WITH X TEMPORARILY SELECTED.
	(READFILE Y X) IS SIMILAR, BUT RETURNS (READ Y).

MAKFIL  --  SUBR.
	(MAKFIL X) MAKES THE ATOM X INTO A FILE-ARRAY,
	AND RETURNS IT. THE DEFAULTS ARE PUT INTO IT.

TYI  --  IS NOW AN LSUBR. CAN TAKE 0 OR 1 ARG, LIKE READCH.
OLD I-O FUNCTIONS KEPT FOR COMPATIBILITY:
(WITH EQUIVALENT DEFINITIONS)

UREAD  --  FSUBR.  OPENS AND SELECTS FILE SPECIFIED IN GENSYMMED
	FILE-ARRAY, WHICH BECOMES VALUE OF ATOM 'UREAD.
	UPDATES DEFAULT NAMES.
  (LAMBDA (X)  (SSTATUS FILE NIL X)
	(SETQ UREAD (INSEL (OPENI X)))
	(STATUS CRUNIT))

UWRITE  --  FSUBR.  OPENS AND ENABLES FILE .LISP. OUTPUT ON SPECIFIED UNIT.
	USES GENSYMMED FILE-ARRAY, WHICH BECOMES VALUE OF 'UWRITE.
	UPDATES DEFAULT UNIT (DEVICE AN SNAME).
  (LAMBDA (X)  (SSTATUS CRUNIT X)
	(SETQ UWRITE (OPENO '(/.LISP/. OUTPUT)))
	(ENABLE UWRITE T)
	(STATUS CRUNIT))

UFILE  --  FSUBR. CLOSES UWRITE FILE WITH SPECIFIED NAMES.
	UPDATES DEFAULT FILENAMES.
	RETURNS UNIT WRITTEN ON.
  (LAMBDA (X)  (RENAME UWRITE X)
	(SSTATUS FILE NIL (STATUS FILE UWRITE))
	(CDDR (STATUS FILE (CLOSE UWRITE))))

UKILL  --  FSUBR.  DELETES SPECIFIED FILE. UPDATES DEFAULT NAMES.
  (LAMBDA (X) (SSTATUS FILE NIL X)
	(RENAME (STATUS FILE NIL) '/ )
	(STATUS CRUNIT))

CRUNIT  --  FSUBR. SETS DEFAULT UNIT. RETURNS NEW DEFAULT.
  (LAMBDA (X)  (SSTATUS FILE NIL (COONS $$ (CONS $$ X)))
	(STATUS CRUNIT))

OLD STATUS CALLS:

STATUS CRUNIT  --  RETURNS DEFAULT UNIT.
  (LAMBDA NIL (CDDR (STATUS FILE NIL)))

SSTATUS CRUNIT  --  EQUIVALENT TO CRUNIT.

STATUS UREAD  --  INDICATES WHETHER UREADING,
	GIVES NAME OF FILE BEING UREAD.
  (LAMBDA NIL (COND (UREAD (STATUS FILE UREAD))))

STATUS UWRITE  --  INDICATES WHETHER UWRITING,
	GIVES UNIT BEING UWRITTEN ON.
  (LAMBDA NIL (COND (UWRITE (CDDR (STATUS FILE UWRITE)))))

SSTATUS UREAD  --  EQUIVALENT TO UREAD.

SSTATUS UWRITE  --  EQUIVALENT TO UWRITE.
INCOMPATIBILITIES:

THE ATOMS CHRCT AND LINEL NO LONGER HAVE SPECIAL MEANINGS IN LISP.
  THERE IS NOTHING WHICH HAS EXACTLY THEIR MEANING.

THE DIS DEVICE	-- NO LONGER HAS SPECIAL FACILITIES IN LISP.
  IT CAN BE WRITTEN ON WITH OPENO, OF COURSE.
  CNTRL-N AND CNTRL-O NO LONGER DO ANYTHING. (NOR (IOC N))
  THE ATOM ^N HAS NO SPECIAL MEANING.

UKILL	-- NO LONGER FLAPS TAPES.

*	-- IS NO LONGER PRINTED OUT AFTER ERRORS.

VIDI, VIDLIN, VIDLOG	-- HAVE BEEN FLUSHED.