| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- (***********************************************************************)
- (* *)
- (* Modula_2 Compiler InOut Library Module *)
- (* *)
- (* High level input and output procedures for *)
- (* characters, strings, integers and cardinals *)
- (* and allows redirection of I/O to/from files *)
- (* *)
- (* original module : N. Wirth, PIM-2, 1982 *)
- (* modifications : 29-JUN-89 import from UxFiles *)
- (* *)
- (* *)
- (***********************************************************************)
- FOREIGN DEFINITION MODULE InOut;
- IMPORT IMPLEMENTATION FROM "inout.obj";
- CONST
- EOL = 12C; (* End-of-line character *)
- VAR
- Done : BOOLEAN ; (* Status of some InOut procedure calls.
- TRUE if the operation was successful,
- FALSE otherwise. *)
- termCh : CHAR ; (* Terminating character of some input
- procedures. ReadString, ReadInt, ReadCard *)
- PROCEDURE OpenInput(Extension : ARRAY OF CHAR);
- (* Precondition : TRUE
- Postcondition : The primary input stream is redefined to be the
- external file name whose names has been supplied
- by the user. If the name ends with a "." the string
- Extension is appended to the end of it.
- Done = TRUE if and only if the file is opened
- successfully *)
- PROCEDURE OpenOutput(Extension : ARRAY OF CHAR);
- (* Precondition : TRUE
- Postcondition : The primary output stream is redefined to be the
- external file name whose names has been supplied
- by the user. If the name ends with a "." the string
- Extension is appended to the end of it.
- Done = TRUE if and only if the file is opened
- successfully *)
-
- PROCEDURE CloseInput;
- (* Precondition : TRUE
- Postcondition : The primary input stream is redefined to be the
- terminal keyboard and the previously used input
- stream is closed *)
-
- PROCEDURE CloseOutput;
- (* Precondition : TRUE
- Postcondition : The primary output stream is redefined to be the
- terminal keyboard and the previously used output
- stream is closed *)
- PROCEDURE Read(VAR c:CHAR);
- (* Precondition : TRUE
- Postcondition : Done = FALSE if and only if the end of the primary
- input stream is reached, otherwise c is the next
- character in the stream. *)
- PROCEDURE ReadLn();
- (* Precondition : TRUE
- Postcondition : Done = FALSE if and only if the end of the primary
- input stream is reached. Characters up to and
- including the EOLN mark are read and consumed *)
- PROCEDURE ReadString(VAR s: ARRAY OF CHAR);
- (* Precondition : TRUE
- Postcondition : Inputs a character string from the primary input
- stream until any character less than or equal to
- a blank is read. The variable termCh is set to the
- value of this terminating character.
- The NUL character (0C) or the end of the array is
- used to mark the end of the string.
- Leading blanks and/or tabs are ignored. Excess
- characters beyond the length of s are discarded. *)
- PROCEDURE ReadCard(VAR n: CARDINAL);
- (* Precondition : TRUE
- Postcondition : Done = TRUE if and only if the next sequence of
- characters on the input stream represents a
- CARDINAL value. The variable termCh is set to the
- value of the character that terminates this
- sequence. *)
-
- PROCEDURE ReadInt(VAR i : INTEGER);
- (* Precondition : TRUE
- Postcondition : Done = TRUE if and only if the next sequence of
- characters on the input stream represents a
- INTEGER value. The variable termCh is set to the
- value of the character that terminates this
- sequence. *)
-
- PROCEDURE Write(c:CHAR);
- (* Precondition : c is defined.
- Postcondition : The character representation corresponding to the
- value of c is written to the output stream. *)
- PROCEDURE WriteLn;
- (* Precondition : TRUE
- Postcondition : Equivalent to Write(EOL). *)
- PROCEDURE WriteString(s : ARRAY OF CHAR);
- (* Precondition : s is defined.
- Postcondition : Outputs a string of characters until a NUL character
- or the end of the array is encountered. *)
- PROCEDURE WriteCard(n: CARDINAL; w: CARDINAL);
- (* Precondition : n and w are defined.
- Postcondition : The value of n is written to the output stream
- occupying at least w character positions. Leading
- blanks fill out the space if it is not all required.
- The decimal number system is used. *)
- PROCEDURE WriteInt(i: INTEGER; w: CARDINAL);
- (* Precondition : i and w are defined.
- Postcondition : The value of i is written to the output stream
- occupying at least w character positions. Leading
- blanks fill out the space if it is not all required.
- The decimal number system is used and a sign is
- displayed only for negative numbers. *)
- PROCEDURE WriteOct(n: CARDINAL; w: CARDINAL);
- (* Precondition : n and w are defined.
- Postcondition : The value of n is written to the output stream
- occupying at least w character positions. Leading
- blanks fill out the space if it is not all required.
- The octal number system is used. *)
- PROCEDURE WriteHex(n: CARDINAL; w: CARDINAL);
- (* Precondition : n and w are defined.
- Postcondition : The value of n is written to the output stream
- occupying at least w character positions. Leading
- blanks fill out the space if it is not all required.
- The hexadecimal number system is used. *)
-
- END InOut.
|