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


Ulm's Modula-2 Library:
InOut


NAME

InOut - formatted i/o

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 are ignored. The terminating character is assigned to termCH.

ReadCardandReadInt 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.

WriteIntandWriteCard 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.

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: 1997/02/25, revision: 1.2, converted to HTML: 1997/02/25

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