Module In Reference

Module In provides a set of basic routines for formatted input of characters, character sequences, numbers, and names. It assumes a standard input stream with a current position that can be reset to the beginning of the stream (but may not always do so on Linux/Unix or Windows).

Module In as in Oakwood Guidlines for Oberon-2 Compiler Developers, 1995.

With the following changes:

LongInt, Int, Int16 read and parse minus signs first.

Char reads a 2-byte character. On Linux it decodes input as UTF-8. On Windows it uses ReadConsoleW WinAPI call if console is attached, otherwise ReadFile is used and input is decoded from UTF-8.

Open may not rewind.

Extra procedures: Line, HugeInt, Int16.

Constants

This section is empty.

Types

BYTE = UBYTE;

8-bit unsigned integer, 0..255.

Variables

Done: BOOLEAN;

TRUE after every Open, FALSE after the first error.

Done indicates the success of an input operation. If Done is TRUE after an input operation, the operation was successful and its result is valid. An unsuccessful input operation sets Done to FALSE; it remains FALSE until the next call to Open. In particular, Done is set to FALSE if an attempt is made to read beyond the end of the input stream.

Procedures

Initialization

PROCEDURE Byte (VAR x: BYTE);

Puts in x the byte at the current position

PROCEDURE Char (VAR ch: CHAR);

Puts in ch the character at the current position. May read 1 to 4 bytes if decoding from UTF-8 (on Linux/Unix and on Windows if input is redirected).

PROCEDURE HugeInt (VAR h: LONGINT);

Returns 64-bit integer at the current position according to the format:

IntConst = [-] (digit {digit} | digit {hexDigit} "H").

PROCEDURE Int (VAR i: INTEGER);

Returns 32-bit integer in the same way as HugeInt does

PROCEDURE Int16 (VAR i: SHORTINT);

Returns 16-bit integer in the same way as HugeInt does

PROCEDURE Line (VAR line: ARRAY OF CHAR);

Reads a line of characters until CR, LF or end of file

PROCEDURE LongInt (VAR i: INTEGER);

Alias for Int. Does the same thing.

PROCEDURE LongReal (VAR x: REAL);

Reads and puts in x a 64-bit real number (LONGREAL) in format:

["-"] digit {digit} [{digit} ["E" ("+" | "-") digit {digit}]].

PROCEDURE Name (VAR s: ARRAY OF CHAR);

Reads the name s at the current position according to the file name format of the operating system (e.g. "lib/My.Mod" under Unix). Skips the 0AX in the end (if any).

PROCEDURE Open;

Open sets the current position to the beginning of the input stream. Done indicates if the operation was successful.

Note that on Windows or Linux/Unix rewind may not be possible. Also on these OS Open is not strictly required before any other operation.

PROCEDURE Real (VAR x: SHORTREAL);

Reads and puts in x a 32-bit real number (REAL) in format:

["-"] digit {digit} [{digit} ["E" ("+" | "-") digit {digit}]].

PROCEDURE String (VAR s: ARRAY OF CHAR);

Reads a string literal and puts it in s.

A string literal is a quoted sequence of characters that may include spaces but not other whitespaces (tabs, new lines etc.). The quotes can be single or double quotes. The string must begin and end with the same quotation marks.

PROCEDURE Word (VAR s: ARRAY OF CHAR);

Reads a word and put it in s.

Skips whitespaces, reads characters until the next whitespace and puts the read word in s, then skips whitespaces until the next non-whitespace or a new line character. Skips the new line character.