1 DEFINITION MODULE PascalIO;
3 Module: Pascal-like Input/Output
4 Author: Ceriel J.H. Jacobs
5 Version: $Id: PascalIO.def,v 1.9 1994/06/24 12:49:09 ceriel Exp $
7 This module provides for I/O that is essentially equivalent to the I/O
8 provided by Pascal with "text", or "file of char".
9 Output buffers are automatically flushed at program termination.
10 The CloseOutput routine is just there for compatibility with earlier
11 versions of this module.
14 CONST Eos = 0C; (* End of string character *)
18 VAR Input, Output: Text; (* standard input and standard output available
20 Standard output is not buffered when
21 connected to a terminal.
23 VAR Notext: Text; (* Initialize your Text variables with this *)
25 PROCEDURE Reset(VAR InputText: Text; Filename: ARRAY OF CHAR);
26 (* When InputText indicates an open textfile, it is first flushed
27 and closed. Then, the file indicated by "Filename" is opened for reading.
28 If this fails, a runtime error results. Otherwise, InputText is
29 associated with the new input file.
32 PROCEDURE Rewrite(VAR OutputText: Text; Filename: ARRAY OF CHAR);
33 (* When OutputText indicates an open textfile, it is first flushed
34 and closed. Then, the file indicated by "Filename" is opened for writing.
35 If this fails, a runtime error results. Otherwise, OutputText is
36 associated with the new output file.
39 PROCEDURE CloseOutput();
40 (* To be called at the end of the program, to flush all output buffers. *)
42 (***************************************************************************
44 All these routines result in a runtime error when not called with either
45 "Input", or a "Text" value obtained by Reset.
46 Also, the routines that actually advance the "read pointer", result in a
47 runtime error when end of file is reached prematurely.
48 ****************************************************************************)
50 PROCEDURE NextChar(InputText: Text): CHAR;
51 (* Returns the next character from the InputText, 0C on end of file.
52 Does not advance the "read pointer", so behaves much like "input^"
53 in Pascal. However, unlike Pascal, if Eoln(InputText) is TRUE, it
54 returns the newline character, rather than a space.
57 PROCEDURE Get(InputText: Text);
58 (* Advances the "read pointer" by one character. *)
60 PROCEDURE Eoln(InputText: Text): BOOLEAN;
61 (* Returns TRUE if the next character from the InputText is a linefeed.
62 Unlike Pascal however, it does not produce a runtime error when
63 called when Eof(InputText) is TRUE.
66 PROCEDURE Eof(InputText: Text): BOOLEAN;
67 (* Returns TRUE if the end of the InputText is reached. *)
69 PROCEDURE ReadChar(InputText: Text; VAR Char: CHAR);
70 (* Read a character from the InputText, and leave the result in "Char".
71 Unlike Pascal, if Eoln(InputText) is TRUE, the newline character
75 PROCEDURE ReadLn(InputText: Text);
76 (* Skip the rest of the current line from the InputText,
77 including the linefeed.
80 PROCEDURE ReadInteger(InputText: Text; VAR Integer: INTEGER);
81 (* Skip leading blanks, read an optionally signed integer from the
82 InputText, and leave the result in "Integer".
83 If no integer is read, or when overflow occurs, a runtime error results.
84 Input stops at the character following the integer.
87 PROCEDURE ReadCardinal(InputText: Text; VAR Cardinal: CARDINAL);
88 (* Skip leading blanks, read a cardinal from the InputText, and leave the
90 If no cardinal is read, or when overflow occurs, a runtime error results.
91 Input stops at the character following the cardinal.
94 PROCEDURE ReadReal(InputText: Text; VAR Real: REAL);
95 (* Skip leading blanks, read a real from the InputText, and leave the
98 real --> [(+|-)] digit {digit} [. digit {digit}]
99 [ E [(+|-)] digit {digit} ]
100 If no real is read, or when overflow/underflow occurs, a runtime error
102 Input stops at the character following the real.
105 PROCEDURE ReadLongReal(InputText: Text; VAR Real: LONGREAL);
106 (* Like ReadReal, but for LONGREAL *)
108 (***************************************************************************
110 All these routines result in a runtime error when not called with either
111 "Output", or a "Text" value obtained by Rewrite.
112 ****************************************************************************)
114 PROCEDURE WriteChar(OutputText: Text; Char: CHAR);
115 (* Writes the character "Char" to the OutputText. *)
117 PROCEDURE WriteLn(OutputText: Text);
118 (* Writes a linefeed to the OutputText. *)
120 PROCEDURE Page(OutputText: Text);
121 (* Writes a form-feed to the OutputText *)
123 PROCEDURE WriteInteger(OutputText: Text; Integer: INTEGER; Width: CARDINAL);
124 (* Write integer "Integer" to the OutputText, using at least "Width" places,
125 blank-padding to the left if needed.
128 PROCEDURE WriteCardinal(OutputText: Text; Cardinal, Width: CARDINAL);
129 (* Write cardinal "Cardinal" to the OutputText, using at least
130 "Width" places, blank-padding to the left if needed.
133 PROCEDURE WriteBoolean(OutputText: Text; Boolean: BOOLEAN; Width: CARDINAL);
134 (* Write boolean "Boolean" to the OutputText, using at least "Width" places,
135 blank-padding to the left if needed.
136 Equivalent to WriteString(OutputText, " TRUE", Width), or
137 WriteString(OutputText, "FALSE", Width).
140 PROCEDURE WriteString(OutputText: Text;
141 String: ARRAY OF CHAR; Width: CARDINAL);
142 (* Write string "String" to the OutputText, using at least "Width" places,
143 blank-padding to the left if needed.
144 The string is terminated either by the character Eos, or by the upperbound
145 of the array "String".
148 PROCEDURE WriteReal(OutputText: Text; Real: REAL; Width, Nfrac: CARDINAL);
149 (* Write real "Real" to the OutputText. If "Nfrac" = 0, use scientific
150 notation, otherwise use fixed-point notation with "Nfrac" digits behind
152 Always use at least "Width" places, blank-padding to the left if needed.
155 PROCEDURE WriteLongReal(OutputText: Text; Real: LONGREAL;
156 Width, Nfrac: CARDINAL);
157 (* Like WriteReal, but for LONGREAL *)