Modula-2 || Compiler & Tools || Library || Search Engine


Ulm's Modula-2 Library:
InOut


NAME

InOut - formatted input and output to stdin and stdout

SYNOPSIS

CONST EOL = 12C;


VAR Done: BOOLEAN; VAR termCH: CHAR;

PROCEDURE Read(VAR ch: CHAR); PROCEDURE ReadString(VAR s: ARRAY OF CHAR); PROCEDURE ReadCard(VAR c: CARDINAL); PROCEDURE ReadInt(VAR i: INTEGER);

PROCEDURE Write(ch: CHAR); PROCEDURE WriteLn; PROCEDURE WriteString(s: ARRAY OF CHAR); PROCEDURE WriteInt(x: INTEGER; n: CARDINAL); PROCEDURE WriteCard(x: CARDINAL; n: CARDINAL); PROCEDURE WriteOct(x: CARDINAL; n: CARDINAL); PROCEDURE WriteHex(x: CARDINAL; n: CARDINAL);

DESCRIPTION

InOut bases on the Terminal module and writes to StdIO.stdout and reads from StdIO.stdin.

Read reads a character and stores it in ch.

ReadString reads a sequence of characters not containing blanks nor control characters. Leading blanks and tabs are ignored. The terminating character is assigned to termCH. When str is filled up to its limit during reading, ReadString returns after reading one additional character that is assigned to termCH.

ReadCard and ReadInt read a string and convert it to cardinal or integer, respectively. Leading blanks are ignored. The terminating character is assigned to termCH.

Write writes ch to stdout.

WriteLn is equivalent to Write(EOL).

WriteString writes s to stdout.

WriteInt and WriteCard write an integer or cardinal, respectively, x with at least n characters on stdout. If n is greater than the number of digits needed, blanks are added preceding the number.

WriteOct and WriteHex write a cardinal number in octal/hexadecimal format.

EXAMPLE

Reading of two integer values from standard input:
WriteString("i = "); ReadInt(i);
WriteString("j = "); ReadInt(j);

DIAGNOSTICS

Done is TRUE on successful calls, otherwise FALSE. Note that some reading procedures return well defined values even in case of errors: Read returns 0C and ReadString returns the characters read so far.

SEE ALSO

FtdIO, StdIO, Terminal

HISTORY

A similar module was written by Niklaus Wirth for the Lilith system. The operations OpenInput, OpenOutput, CloseInput, and CloseOutput have been omitted. StdIO and FtdIO should be used instead.

Note that the semantics of the remaining operations is slightly different from the Lilith implementation due to the line-oriented input mode under UNIX. On Lilith, the example above has to be extended with explicit invocations of WriteLn because line terminators were neither to be typed (every other non-digit would work as well) nor echoed:

WriteString("i = "); ReadInt(i); WriteLn;
WriteString("j = "); ReadInt(j); WriteLn;

The current implementation is due to Andreas Borchert.


Edited by: borchert, last change: 1999/01/26, revision: 1.3, converted to HTML: 1999/01/26

Modula-2 || Compiler & Tools || Library || Search Engine