* New version of IRM New version of the IRM, updated to Medley. * moved to docs/medley-irm as discussed
141 lines
151 KiB
Plaintext
141 lines
151 KiB
Plaintext
|
||
INTERLISP-D REFERENCE MANUAL
|
||
I/O FUNCTIONS
|
||
|
||
"25"24. INPUT/OUTPUT FUNCTIONS
|
||
2
|
||
|
||
This chapter describes the standard I/O functions used for reading and printing characters and Interlisp expressions on files and other streams. First, the primitive input functions are presented, then the output functions, then functions for random-access operations (such as searching a file for a given stream, or changing the "next-character" pointer to a position in a file). Next, the PRINTOUT statement is documented (see below), which provides an easy way to write complex output operations. Finally, read tables, used to parse characters as Interlisp expressions, are documented.
|
||
Specifying Streams for Input/Output Functions(INPUT/OUTPUT% FUNCTIONS NIL Input/Output% Functions NIL ("25") 1 SUBNAME SPECIFYING% STREAMS% FOR SUBTEXT specifying% streams% for)
|
||
1
|
||
|
||
Most of the input/output functions in Interlisp-D have an argument named STREAM or FILE, specifying on which open stream the function's action should occur (the name FILE is used in older functions that predate the concept of stream; the two should, however, be treated synonymously). The value of this argument should be one of the following:
|
||
a stream An object of type STREAM, as returned by OPENSTREAM (Chapter 23) or other stream-producing functions, is always the most precise and efficient way to designate a stream argument.
|
||
T The litatom T designates the terminal input or output stream of the currently running process, controlling input from the keyboard and output to the display screen. For functions where the direction (input or output) is ambiguous, T is taken to designate the terminal output stream. The T streams are always open; they cannot be closed.
|
||
The terminal output stream can be set to a given window or display stream by using TTYDISPLAYSTREAM (Chapter 28). The terminal input stream cannot be changed. For more information on terminal I/O, see Chapter 30.
|
||
NIL The litatom NIL designates the "primary" input or output stream. These streams are initially the same as the terminal input/output streams, but they can be changed by using the functions INPUT and OUTPUT.
|
||
For functions where the direction (input or output) is ambiguous, e.g., GETFILEPTR, the argument NIL is taken to mean the primary input stream, if that stream is not identical to the terminal input stream, else the primary output stream.
|
||
a window Uses the display stream of the window . Valid for output only.
|
||
a file name As of this writing, the name of an open file (as a litatom) can be used as a stream argument. However, there are inefficiencies and possible future incompatibilities associated with doing so. See Chapter 24 for details.
|
||
(GETSTREAM(GETSTREAM (Function) NIL NIL ("25") 2) FILE ACCESS) [Function]
|
||
Coerces the argument FILE to a stream by the above rules. If ACCESS is INPUT, OUTPUT, or BOTH, produces the stream designated by FILE that is open for ACCESS. If ACCESS=NIL, returns a stream for FILE open for any kind of input/output (see the list above for the ambiguous cases). If FILE does not designate a stream open in the specified mode, causes an error, FILE NOT OPEN.
|
||
(STREAMP(STREAMP (Function) NIL NIL ("25") 2) X) [Function]
|
||
Returns X if X is a STREAM, otherwise NIL.
|
||
Input Functions
|
||
1
|
||
|
||
While the functions described below can take input from any stream, some special actions occur when the input is from the terminal (the T input stream, see above). When reading from the terminal, the input is buffered a line at a time, unless buffering has been inhibited by CONTROL (Chapter 30) or the input is being read by READC or PEEKC. Using specified editing characters, you can erase a character at a time, a word at a time, or the whole line. The keys that perform these editing functions are assignable via SETSYNTAX, with the initial settings chosen to be those most natural for the given operating system. In Interlisp-D, the initial settings are as follows: characters are deleted one at a time by Backspace; words are erased by control-W; the whole line is erased by Control-Q.
|
||
On the Interlisp-D display, deleting a character or a line causes the characters to be physically erased from the screen. In Interlisp-10, the deleting action can be modified for various types of display terminals by using DELETECONTROL (Chapter 30).
|
||
Unless otherwise indicated, when the end of file is encountered while reading from a file, all input functions generate an error, END OF FILE. Note that this does not close the input file. The ENDOFSTREAMOP stream attribute (Chapter 24) is useful for changing the behavior at end of file.
|
||
Most input functions have a RDTBL argument, which specifies the read table to be used for input. Unless otherwise specified, if RDTBL is NIL, the primary read table is used.
|
||
If the FILE or STREAM argument to an input function is NIL, the primary input stream is used.
|
||
(INPUT(INPUT (Function) NIL NIL ("25") 2) FILE) [Function]
|
||
Sets FILE as the primary input stream; returns the old primary input stream. FILE must be open for input.
|
||
(INPUT) returns the current primary input stream, which is not changed.
|
||
Note: If the primary input stream is set to a file, the file's full name, rather than the stream itself, is returned. See discussion in Chapter 24.
|
||
(READ(READ (Function) NIL NIL ("25") 3) FILE RDTBL FLG) [Function]
|
||
Reads one expression from FILE. Atoms are delimited by the break and separator characters as defined in RDTBL. To include a break or separator character in an atom, the character must be preceded by the character %, e.g., AB%(C is the atom AB(C, %% is the atom %, %control-K is the atom Control-K. For input from the terminal, an atom containing an interrupt character can be input by typing instead the corresponding alphabetic character preceded by Control-V, e.g., ^VD for Control-D.
|
||
Strings are delimited by double quotes. To input a string containing a double quote or a %, precede it by %, e.g., "AB%"C" is the string AB"C. Note that % can always be typed even if next character is not "special", e.g., %A%B%C is read as ABC.
|
||
If an atom is interpretable as a number, READ creates a number, e.g., 1E3 reads as a floating point number, 1D3 as a literal atom, 1.0 as a number, 1,0 as a literal atom, etc. An integer can be input in a non-decimal radix by using syntax such as 123Q, |b10101, |5r1234 (see Chapter 7). The function RADIX, sets the radix used to print integers.
|
||
When reading from the terminal, all input is line-buffered to enable the action of the backspacing control characters, unless inhibited by CONTROL (Chapter 30). Thus no characters are actually seen by the program until a carriage-return (actually the character with terminal syntax class EOL, see Chapter 30), is typed. However, for reading by READ, when a matching right parenthesis is encountered, the effect is the same as though a carriage-return were typed, i.e., the characters are transmitted. To indicate this, Interlisp also prints a carriage-return line-feed on the terminal. The line buffer is also transmitted to READ whenever an IMMEDIATE read macro character is typed (see below).
|
||
FLG=T suppresses the carriage-return normally typed by READ following a matching right parenthesis. (However, the characters are still given to READ; i.e., you do not have to type the carriage-return.)
|
||
(RATOM FILE RDTBL) [Function]
|
||
Reads in one atom from FILE. Separation of atoms is defined by RDTBL. % is also defined for RATOM, and the remarks concerning line-buffering and editing control characters also apply.
|
||
If the characters comprising the atom would normally be interpreted as a number by READ, that number is returned by RATOM. Note however that RATOM takes no special action for " whether or not it is a break character, i.e., RATOM never makes a string.
|
||
(RSTRING(RSTRING (Function) NIL NIL ("25") 3) FILE RDTBL) [Function]
|
||
Reads characters from FILE up to, but not including, the next break or separator character, and returns them as a string. Backspace, Control-W, Control-Q, Control-V, and % have the same effect as with READ.
|
||
Note that the break or separator character that terminates a call to RATOM or RSTRING is not read by that call, but remains in the buffer to become the first character seen by the next reading function that is called. If that function is RSTRING, it will return the null string. This is a common source of program bugs.
|
||
(RATOMS(RATOMS (Function) NIL NIL ("25") 4) A FILE RDTBL) [Function]
|
||
Calls RATOM repeatedly until the atom A is read. Returns a list of the atoms read, not including A.
|
||
(RATEST(RATEST (Function) NIL NIL ("25") 4) FLG) [Function]
|
||
If FLG = T, RATEST returns T if a separator was encountered immediately prior to the atom returned by the last RATOM or READ, NIL otherwise.
|
||
If FLG = NIL, RATEST returns T if last atom read by RATOM or READ was a break character, NIL otherwise.
|
||
If FLG = 1, RATEST returns T if last atom read (by READ or RATOM) contained a % used to quote the next character (as in %[ or %A%B%C), NIL otherwise.
|
||
(READC (READC% (Function) NIL NIL ("25") 4)FILE RDTBL) [Function]
|
||
Reads and returns the next character, including %, ", etc, i.e., is not affected by break or separator characters. The action of READC is subject to line-buffering, i.e., READC does not return a value until the line has been terminated even if a character has been typed. Thus, the editing control characters have their usual effect. RDTBL does not directly affect the value returned, but is used as usual in line-buffering, e.g., determining when input has been terminated. If (CONTROL T) has been executed (Chapter 30), defeating line-buffering, the RDTBL argument is irrelevant, and READC returns a value as soon as a character is typed (even if the character typed is one of the editing characters, which ordinarily would never be seen in the input buffer).<2E><> |