XEROX Lisp Users Packages 2 4 1 1 PIPES 1 4 4 4 By: Mike Bird INTRODUCTION This package incorporates several components: * A mechanism consisting of a ring-buffer connecting a pair of streams - similar to UNIX pipes. * Some pipe-related functions, such as a TEE filter and a special form to create a pipeline - a number of processes whose primary input/output streams are connected together. * A function called OPENRESETSTREAM which encapsulates RESETSAVE activity commonly associated with an OPENFILE or OPENSTREAM. [Primary input and output streams are those accessed by specifying NIL to BIN and BOUT]. USER FUNCTIONS (OPENPIPE SIZE) Returns a dotted-pair of streams - the CAR of which can read a ring-buffer written via the CDR. SIZE must be in the range 1 to 32767 inclusive and defaults to 512. Both streams ignore DELETEFILE, GETFILEINFO, GETFILENAME and SETFILEINFO - returning NIL. The read-stream can BACKFILEPTR, BIN, CLOSEFILE, EOFP and PEEKBIN. This is sufficient to support READ et.c. EOFP always waits until there is a byte in the buffer or the write-stream is closed. If the write-stream is closed BIN takes end of file action when the buffer becomes empty. The write-stream can BOUT, CLOSEFILE and EOFP. This is sufficient to support PRINT et.c. EOFP always returns T. The write-stream is closed if the read-stream is closed, but not vice versa. (PIPELINE FORMS) Creates a new process for all forms except the last - which is evaluated in the current process. The first and last forms are evaluated with their primary input and output streams (respectively) taken from the current environment. The primary streams of the others are linked together by pipes. Provision is made to close pipes on process termination, thus propagating EOF in the conventional manner. In other respects PIPELINE behaves like PROGN. *** WARNING *** Interlisp-D has a tendency to drop into Raid sometimes when one process attempts to use another's primary streams. Therefore it is presently advisable to avoid having the first process in the pipeline read its primary input. (TEE.FILTER TEEFILE APPEND?) This function copies bytes from its primary input to its primary output and TEEFILE. If APPEND? is NIL, TEEFILE is opened in OUTPUT mode and deleted on error or abort. Otherwise TEEFILE is opened in APPEND mode and is not deleted. (STREAM.SOURCE INPUT) This function copies bytes from the specified input file to its primary output. (STREAM.SINK OUTPUT APPEND?) This function copies bytes from its primary input to the specified output. APPEND? is as for TEE.FILTER. (FILTER.KEYBOARD INPUT OUTPUT STRING) This function copies bytes from INPUT - which is typically T - to OUTPUT until STRING is encountered. STRING is not copied. STRING defaults to a single ^Z character. [Because of line buffering it is necessary to type a newline sometime after the ^Z in order for it to be seen]. [This function is needed because (EOFP T) is often true - so COPYBYTES won't work]. (ADD.FILTER FORM INPUT CLOSEINPUT OUTPUT CLOSEOUTPUT) This function creates a process executing FORM with primary input INPUT and primary output OUTPUT. If CLOSEINPUT (resp. CLOSEOUTPUT) is non-NIL then a RESETSAVE is issued within the new process before evaluating FORM to ensure that INPUT (resp. OUTPUT) is closed when the process terminates. (OPENRESETSTREAM FILE ACCESS RECOG BYTESIZE PARAMETERS DELETE-Y/N/NIL DELETE-ON-ANY-STATE) FILE, ACCESS, RECOG, BYTESIZE and PARAMETERS are as for OPENSTREAM (which is similar to OPENFILE). If FILE denotes an already open file/stream then, unless RECOG is NEW (or RECOG=NIL and ACCESS=OUTPUT), the stream associated with that file is checked for ACCESS compatibility and returned. Otherwise a new stream is opened. A RESETSAVE is issued to ensure that the stream will eventually be closed and, if RESETSTATE is non-NIL, optionally deleted. The file will be deleted iff: (AND "It was not previously open" (OR "RESETSTATE is non-NIL" "DELETE-ON-ANY-STATE is non-NIL") (OR "DELETE-Y/N/NIL is Y" (AND "DELETE-Y/N/NIL is NIL" (OR "RECOG is NEW" (AND "RECOG is NIL" "ACCESS is OUTPUT"))))) EXAMPLES (PIPELINE (STREAM.SOURCE 'A) (TEE.FILTER 'B) (STREAM.SINK 'C)) Copies file A to files B and C, although not very efficiently. (FILTER.KEYBOARD NIL 'MYFILE) Copies key input to MYFILE. (APPLY 'PIPELINE (APPEND '((PROGN (TTY.PROCESS (THIS.PROCESS)) (FILTER.KEYBOARD T) (TTY.PROCESS T))) (for I from 1 to 20 collect '(COPYBYTES)))) Tests pipes and processes. (LIST ((PAGE NIL NIL (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 SIZE 10 FAMILY HELVETICA OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF SLOPE REGULAR WEIGHT MEDIUM)) (270 42 72 36) NIL) (HEADING NIL (HEADINGTYPE BOO) (84 744 444 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL NIL (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 SIZE 10 FAMILY HELVETICA OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF SLOPE REGULAR WEIGHT MEDIUM)) (270 42 72 36) NIL) (HEADING NIL (HEADINGTYPE BOO) (84 744 444 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL NIL (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 SIZE 10 FAMILY HELVETICA OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF SLOPE REGULAR WEIGHT MEDIUM)) (270 42 72 36) NIL) (HEADING NIL (HEADINGTYPE BOO) (84 744 444 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))))) È TÈ ÈÈ ŠŠ8ŠŠ8 4ŠŠ8ŠŠ8ÈÈÈ PAGEHEADINGBOO HELVETICA  HELVETICA  TIMESROMAN HELVETICA HELVETICA LOGO HELVETICA HELVETICA   HRULE.GETFN HELVETICA HRULE.GETFN HELVETICA HRULE.GETFN HRULE.GETFN HELVETICA HRULE.GETFN HELVETICA HRULE.GETFN HRULE.GETFN HRULE.GETFN HELVETICA  .`¯~YÀ)j/âéPj&T6%[f¿ " !+ % $-  ? *!5{ z¹