1 (* InOut.def provides a compatible PIM [234] InOut module.
3 Copyright (C) 2004-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
27 DEFINITION MODULE InOut ;
30 FROM DynamicStrings IMPORT String ;
31 EXPORT QUALIFIED EOL, Done, termCH, OpenInput, OpenOutput,
32 CloseInput, CloseOutput,
33 Read, ReadString, ReadInt, ReadCard,
34 Write, WriteLn, WriteString, WriteInt, WriteCard,
47 OpenInput - reads a string from stdin as the filename for reading.
48 If the filename ends with `.' then it appends the defext
49 extension. The global variable Done is set if all
53 PROCEDURE OpenInput (defext: ARRAY OF CHAR) ;
57 CloseInput - closes an opened input file and returns input back to
61 PROCEDURE CloseInput ;
65 OpenOutput - reads a string from stdin as the filename for writing.
66 If the filename ends with `.' then it appends the defext
67 extension. The global variable Done is set if all
71 PROCEDURE OpenOutput (defext: ARRAY OF CHAR) ;
75 CloseOutput - closes an opened output file and returns output back to
79 PROCEDURE CloseOutput ;
83 Read - reads a single character from the current input file.
84 Done is set to FALSE if end of file is reached or an
88 PROCEDURE Read (VAR ch: CHAR) ;
92 ReadString - reads a sequence of characters. Leading white space
93 is ignored and the string is terminated with a character
97 PROCEDURE ReadString (VAR s: ARRAY OF CHAR) ;
101 WriteString - writes a string to the output file.
104 PROCEDURE WriteString (s: ARRAY OF CHAR) ;
108 Write - writes out a single character, ch, to the current output file.
111 PROCEDURE Write (ch: CHAR) ;
115 WriteLn - writes a newline to the output file.
122 ReadInt - reads a string and converts it into an INTEGER, x.
123 Done is set if an INTEGER is read.
126 PROCEDURE ReadInt (VAR x: INTEGER) ;
130 ReadInt - reads a string and converts it into an INTEGER, x.
131 Done is set if an INTEGER is read.
134 PROCEDURE ReadCard (VAR x: CARDINAL) ;
138 WriteCard - writes the CARDINAL, x, to the output file. It ensures
139 that the number occupies, n, characters. Leading spaces
140 are added if required.
143 PROCEDURE WriteCard (x, n: CARDINAL) ;
147 WriteInt - writes the INTEGER, x, to the output file. It ensures
148 that the number occupies, n, characters. Leading spaces
149 are added if required.
152 PROCEDURE WriteInt (x: INTEGER; n: CARDINAL) ;
156 WriteOct - writes the CARDINAL, x, to the output file in octal.
157 It ensures that the number occupies, n, characters.
158 Leading spaces are added if required.
161 PROCEDURE WriteOct (x, n: CARDINAL) ;
165 WriteHex - writes the CARDINAL, x, to the output file in hexadecimal.
166 It ensures that the number occupies, n, characters.
167 Leading spaces are added if required.
170 PROCEDURE WriteHex (x, n: CARDINAL) ;
174 ReadS - returns a string which has is a sequence of characters.
175 Leading white space is ignored and string is terminated
176 with a character <= ' '.
179 PROCEDURE ReadS () : String ;
183 WriteS - writes a String to the output device.
184 It returns the string, s.
187 PROCEDURE WriteS (s: String) : String ;