The IO
interface provides textual input and output for simple
programs. For more detailed control, use the interfaces Rd
,
Wr
, Stdio
, FileRd
, FileWr
, Fmt
, and Lex
.
The input procedures take arguments of type Rd.T
that specify
which input stream to use. If this argument is defaulted, standard
input (Stdio.stdin
) is used. Similarly, if an argument of type
Wr.T
to an output procedure is defaulted, Stdio.stdout
is used.
INTERFACEIO ; IMPORT Rd, Wr; PROCEDURE Put(txt: TEXT; wr: Wr.T := NIL);
Outputtxt
towr
and flushwr
.
PROCEDURE PutChar(ch: CHAR; wr: Wr.T := NIL);
Outputch
towr
and flushwr
.
PROCEDURE PutWideChar(ch: WIDECHAR; wr: Wr.T := NIL);
Outputch
towr
and flushwr
.
PROCEDURE PutInt(n: INTEGER; wr: Wr.T := NIL);
OutputFmt.Int(n)
towr
and flushwr
.
PROCEDURE PutLongInt(n: LONGINT; wr: Wr.T := NIL);
OutputFmt.LongInt(n)
towr
and flushwr
.
PROCEDURE PutReal(r: REAL; wr: Wr.T := NIL);
OutputFmt.Real(r)
towr
and flushwr
.
PROCEDURE EOF(rd: Rd.T := NIL): BOOLEAN;
ReturnTRUE
iffrd
is at end-of-file.
EXCEPTION Error;The exception
Error
is raised whenever a Get
procedure
encounters syntactically invalid input, including unexpected
end-of-file.
PROCEDURE GetLine(rd: Rd.T := NIL): TEXT RAISES {Error};
Read a line of text from rd
and return it.
A line of text is either zero or more characters terminated by a line break, or one or more characters terminated by an end-of-file. In the former case,
GetLine
consumes the line break but does not
include it in the returned value. A line break is either {\tt
"\n"} or {\tt
"\r\n"}.
PROCEDURE GetChar(rd: Rd.T := NIL): CHAR RAISES {Error};
Read the next character from rd
and return it.
PROCEDURE GetWideChar(rd: Rd.T := NIL): WIDECHAR RAISES {Error};
Read the next two bytes from rd
and return it as a wide character.
PROCEDURE GetInt(rd: Rd.T := NIL): INTEGER RAISES {Error};
Read a decimal numeral fromrd
usingLex.Int
and return its value.
PROCEDURE GetLongInt(rd: Rd.T := NIL): LONGINT RAISES {Error};
Read a decimal numeral fromrd
usingLex.LongInt
and return its value.
PROCEDURE GetReal(rd: Rd.T := NIL): REAL RAISES {Error};
Read a real number fromrd
usingLex.Real
and return its value.
PROCEDURE OpenRead(f: TEXT): Rd.T;
Open the file namef
for reading and return a reader on its contents. If the file doesn't exist or is not readable, returnNIL
.
PROCEDURE OpenWrite(f: TEXT): Wr.T;
Open the file namedf
for writing and return a writer on its contents. If the file does not exist it will be created. If the process does not have the authority to modify or create the file, returnNIL
.
END IO.