Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / libm2 / PascalIO.def
1 DEFINITION MODULE PascalIO;
2 (* 
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 $
6
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.
12 *)
13
14   CONST Eos = 0C;               (* End of string character *)
15
16   TYPE  Text;
17
18   VAR   Input, Output: Text;    (* standard input and standard output available
19                                    immediately.
20                                    Standard output is not buffered when
21                                    connected to a terminal.
22                                 *)
23   VAR   Notext: Text;           (* Initialize your Text variables with this *)
24
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.
30   *)
31
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.
37   *)
38
39   PROCEDURE CloseOutput();
40   (* To be called at the end of the program, to flush all output buffers. *)
41
42   (***************************************************************************
43      Input routines;
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   ****************************************************************************)
49
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.
55   *)
56
57   PROCEDURE Get(InputText: Text);
58   (* Advances the "read pointer" by one character. *)
59
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.
64   *)
65
66   PROCEDURE Eof(InputText: Text): BOOLEAN;
67   (* Returns TRUE if the end of the InputText is reached. *)
68
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
72      is put in "Char".
73   *)
74
75   PROCEDURE ReadLn(InputText: Text);
76   (* Skip the rest of the current line from the InputText,
77      including the linefeed.
78   *)
79
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.
85   *)
86
87   PROCEDURE ReadCardinal(InputText: Text; VAR Cardinal: CARDINAL);
88   (* Skip leading blanks, read a cardinal from the InputText, and leave the
89      result in "Cardinal".
90      If no cardinal is read, or when overflow occurs, a runtime error results.
91      Input stops at the character following the cardinal.
92   *)
93
94   PROCEDURE ReadReal(InputText: Text; VAR Real: REAL);
95   (* Skip leading blanks, read a real from the InputText, and leave the
96      result in "Real".
97      Syntax:
98       real -->  [(+|-)] digit {digit} [. digit {digit}]
99                 [ E [(+|-)] digit {digit} ]
100      If no real is read, or when overflow/underflow occurs, a runtime error
101      results.
102      Input stops at the character following the real.
103   *)
104
105   PROCEDURE ReadLongReal(InputText: Text; VAR Real: LONGREAL);
106   (* Like ReadReal, but for LONGREAL *)
107
108   (***************************************************************************
109      Output routines;
110      All these routines result in a runtime error when not called with either
111      "Output", or a "Text" value obtained by Rewrite.
112   ****************************************************************************)
113
114   PROCEDURE WriteChar(OutputText: Text; Char: CHAR);
115   (* Writes the character "Char" to the OutputText. *)
116
117   PROCEDURE WriteLn(OutputText: Text);
118   (* Writes a linefeed to the OutputText. *)
119
120   PROCEDURE Page(OutputText: Text);
121   (* Writes a form-feed to the OutputText *)
122
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.
126   *)
127
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.
131   *)
132
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).
138   *)
139
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".
146   *)
147
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
151      the dot.
152      Always use at least "Width" places, blank-padding to the left if needed.
153   *)
154
155   PROCEDURE WriteLongReal(OutputText: Text; Real: LONGREAL;
156                           Width, Nfrac: CARDINAL);
157   (* Like WriteReal, but for LONGREAL *)
158 END PascalIO.