ack/lang/m2/libm2/PascalIO.def

159 lines
6.1 KiB
Modula-2
Raw Permalink 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
1994-06-24 14:02:31 +00:00
Version: $Id$
1988-02-19 13:05:03 +00:00
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-06-16 11:44:31 +00:00
Output buffers are automatically flushed at program termination.
1988-02-19 13:05:03 +00:00
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();
1988-06-16 11:44:31 +00:00
(* To be called at the end of the program, to flush all output buffers. *)
1987-06-26 15:59:52 +00:00
(***************************************************************************
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;
1988-06-16 11:44:31 +00:00
(* Returns the next character from 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^"
1988-06-16 11:44:31 +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);
1988-06-16 11:44:31 +00:00
(* Advances the "read pointer" by one character. *)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE Eoln(InputText: Text): BOOLEAN;
1988-06-16 11:44:31 +00:00
(* Returns TRUE if the next character from the InputText is a linefeed.
1987-07-13 13:34:56 +00:00
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;
1988-06-16 11:44:31 +00:00
(* 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);
1988-06-16 11:44:31 +00:00
(* Read a character from the InputText, and leave the result in "Char".
Unlike Pascal, if Eoln(InputText) is TRUE, the newline character
1987-07-13 13:34:56 +00:00
is put in "Char".
*)
1987-06-26 15:59:52 +00:00
1987-07-03 16:07:18 +00:00
PROCEDURE ReadLn(InputText: Text);
1988-06-16 11:44:31 +00:00
(* Skip the rest of the current line from the InputText,
including the linefeed.
1987-07-03 16:07:18 +00:00
*)
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
*)
PROCEDURE ReadLongReal(InputText: Text; VAR Real: LONGREAL);
(* Like ReadReal, but for LONGREAL *)
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);
1988-06-16 11:44:31 +00:00
(* 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);
1988-06-16 11:44:31 +00:00
(* 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
1988-06-16 11:44:31 +00:00
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.
1988-06-16 11:44:31 +00:00
The string is terminated either by the character Eos, or by 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
*)
PROCEDURE WriteLongReal(OutputText: Text; Real: LONGREAL;
Width, Nfrac: CARDINAL);
(* Like WriteReal, but for LONGREAL *)
1987-07-03 16:07:18 +00:00
END PascalIO.