ack/lang/m2/libm2/PascalIO.def

153 lines
5.9 KiB
Modula-2
Raw Normal View History

1987-07-03 16:07:18 +00:00
DEFINITION MODULE PascalIO;
1988-02-19 13:05:03 +00:00
(*
Module: Pascal-like Input/Output
Author: Ceriel J.H. Jacobs
Version: $Header$
This module provides for I/O that is essentially equivalent to the I/O
1987-06-26 15:59:52 +00:00
provided by Pascal with "text", or "file of char".
1988-02-19 13:05:03 +00:00
Output buffers are automaically flushed at program termination.
The CloseOutput routine is just there for compatibility with earlier
versions of this module.
1987-06-26 15:59:52 +00:00
*)
1987-07-03 16:07:18 +00:00
CONST Eos = 0C; (* End of string character *)
1987-06-26 15:59:52 +00:00
TYPE Text;
1987-07-03 16:07:18 +00:00
VAR Input, Output: Text; (* standard input and standard output available
1987-06-26 15:59:52 +00:00
immediately.
Standard output is not buffered when
connected to a terminal.
*)
1987-07-03 16:07:18 +00:00
VAR Notext: Text; (* Initialize your Text variables with this *)
1987-06-26 15:59:52 +00:00
PROCEDURE Reset(VAR InputText: Text; Filename: ARRAY OF CHAR);
1987-07-03 16:07:18 +00:00
(* When InputText indicates an open textfile, it is first flushed
and closed. Then, the file indicated by "Filename" is opened for reading.
If this fails, a runtime error results. Otherwise, InputText is
1987-06-26 15:59:52 +00:00
associated with the new input file.
*)
PROCEDURE Rewrite(VAR OutputText: Text; Filename: ARRAY OF CHAR);
1987-07-03 16:07:18 +00:00
(* When OutputText indicates an open textfile, it is first flushed
and closed. Then, the file indicated by "Filename" is opened for writing.
If this fails, a runtime error results. Otherwise, OutputText is
1987-06-26 15:59:52 +00:00
associated with the new output file.
*)
1987-07-03 16:07:18 +00:00
PROCEDURE CloseOutput();
1987-06-26 15:59:52 +00:00
(* To be called at the end of the program, to flush all output buffers *)
(***************************************************************************
Input routines;
All these routines result in a runtime error when not called with either
1987-07-03 16:07:18 +00:00
"Input", or a "Text" value obtained by Reset.
1987-06-26 15:59:52 +00:00
Also, the routines that actually advance the "read pointer", result in a
runtime error when end of file is reached prematurely.
****************************************************************************)
1987-07-03 16:07:18 +00:00
PROCEDURE NextChar(InputText: Text): CHAR;
(* Returns the next character of the InputText, 0C on end of file.
1987-06-26 15:59:52 +00:00
Does not advance the "read pointer", so behaves much like "input^"
1987-07-03 16:07:18 +00:00
in Pascal. However, unlike Pascal, if Eoln(InputText) is true, it
1987-06-26 15:59:52 +00:00
returns the newline character, rather than a space.
*)
1987-07-03 16:07:18 +00:00
PROCEDURE Get(InputText: Text);
1987-06-26 15:59:52 +00:00
(* Advances the "read pointer" by one character *)
1987-07-03 16:07:18 +00:00
PROCEDURE Eoln(InputText: Text): BOOLEAN;
1987-07-13 13:34:56 +00:00
(* Returns TRUE if the next character of the InputText is a linefeed.
Unlike Pascal however, it does not produce a runtime error when
called when Eof(InputText) is TRUE.
*)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE Eof(InputText: Text): BOOLEAN;
(* Returns TRUE if the end of the InputText is reached *)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE ReadChar(InputText: Text; VAR Char: CHAR);
1987-07-13 13:34:56 +00:00
(* Read a character from the InputText, and leave result in "Char".
Unlike Pascal, if Eoln(InputText) is true, the newline character
is put in "Char".
*)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE ReadLn(InputText: Text);
(* Skip the rest of the current line of the InputText,
including the linefeed
*)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE ReadInteger(InputText: Text; VAR Integer: INTEGER);
1987-06-26 15:59:52 +00:00
(* Skip leading blanks, read an optionally signed integer from the
1987-07-03 16:07:18 +00:00
InputText, and leave the result in "Integer".
1987-06-26 15:59:52 +00:00
If no integer is read, or when overflow occurs, a runtime error results.
Input stops at the character following the integer.
*)
1987-07-03 16:07:18 +00:00
PROCEDURE ReadCardinal(InputText: Text; VAR Cardinal: CARDINAL);
(* Skip leading blanks, read a cardinal from the InputText, and leave the
1987-07-13 13:34:56 +00:00
result in "Cardinal".
1987-06-26 15:59:52 +00:00
If no cardinal is read, or when overflow occurs, a runtime error results.
1987-07-13 13:34:56 +00:00
Input stops at the character following the cardinal.
1987-06-26 15:59:52 +00:00
*)
1987-07-03 16:07:18 +00:00
PROCEDURE ReadReal(InputText: Text; VAR Real: REAL);
(* Skip leading blanks, read a real from the InputText, and leave the
result in "Real".
1987-06-26 15:59:52 +00:00
Syntax:
real --> [(+|-)] digit {digit} [. digit {digit}]
1987-06-29 12:27:50 +00:00
[ E [(+|-)] digit {digit} ]
1987-06-26 15:59:52 +00:00
If no real is read, or when overflow/underflow occurs, a runtime error
results.
1987-07-13 13:34:56 +00:00
Input stops at the character following the real.
1987-06-26 15:59:52 +00:00
*)
(***************************************************************************
Output routines;
All these routines result in a runtime error when not called with either
1987-07-03 16:07:18 +00:00
"Output", or a "Text" value obtained by Rewrite.
1987-06-26 15:59:52 +00:00
****************************************************************************)
1987-07-03 16:07:18 +00:00
PROCEDURE WriteChar(OutputText: Text; Char: CHAR);
(* Writes the character "Char" to the OutputText *)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE WriteLn(OutputText: Text);
(* Writes a linefeed to the OutputText *)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE Page(OutputText: Text);
(* Writes a form-feed to the OutputText *)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE WriteInteger(OutputText: Text; Integer: INTEGER; Width: CARDINAL);
(* Write integer "Integer" to the OutputText, using at least "Width" places,
1987-06-26 15:59:52 +00:00
blank-padding to the left if needed.
*)
1987-07-03 16:07:18 +00:00
PROCEDURE WriteCardinal(OutputText: Text; Cardinal, Width: CARDINAL);
(* Write cardinal "Cardinal" to the OutputText, using at least
"Width" places, blank-padding to the left if needed.
1987-06-26 15:59:52 +00:00
*)
1987-07-03 16:07:18 +00:00
PROCEDURE WriteBoolean(OutputText: Text; Boolean: BOOLEAN; Width: CARDINAL);
(* Write boolean "Boolean" to the OutputText, using at least "Width" places,
1987-06-26 15:59:52 +00:00
blank-padding to the left if needed.
1987-07-13 13:34:56 +00:00
Equivalent to WriteString(OutputText, " TRUE", Width), or
WriteString(OutputText, "FALSE", Width)
1987-06-26 15:59:52 +00:00
*)
1987-07-03 16:07:18 +00:00
PROCEDURE WriteString(OutputText: Text;
String: ARRAY OF CHAR; Width: CARDINAL);
(* Write string "String" to the OutputText, using at least "Width" places,
1987-06-26 15:59:52 +00:00
blank-padding to the left if needed.
1987-07-03 16:07:18 +00:00
The string is terminated either by the character Eos, or the upperbound of
the array "String".
1987-06-26 15:59:52 +00:00
*)
1987-07-03 16:07:18 +00:00
PROCEDURE WriteReal(OutputText: Text; Real: REAL; Width, Nfrac: CARDINAL);
(* Write real "Real" to the OutputText. If "Nfrac" = 0, use scientific
notation, otherwise use fixed-point notation with "Nfrac" digits behind
1987-06-26 15:59:52 +00:00
the dot.
1987-07-03 16:07:18 +00:00
Always use at least "Width" places, blank-padding to the left if needed.
1987-06-26 15:59:52 +00:00
*)
1987-07-03 16:07:18 +00:00
END PascalIO.