| 1 |
(* STextIO.mod implement the ISO STextIO specification. |
| 2 |
|
| 3 |
Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 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) |
| 11 |
any later version. |
| 12 |
|
| 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. |
| 17 |
|
| 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. |
| 21 |
|
| 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/>. *) |
| 26 |
|
| 27 |
IMPLEMENTATION MODULE STextIO; |
| 28 |
|
| 29 |
IMPORT StdChans, TextIO ; |
| 30 |
|
| 31 |
(* Input and output of character and string types over default channels. The read result |
| 32 |
is of the type IOConsts.ReadResults. |
| 33 |
*) |
| 34 |
|
| 35 |
(* The following procedures do not read past line marks *) |
| 36 |
|
| 37 |
PROCEDURE ReadChar (VAR ch: CHAR); |
| 38 |
(* If possible, removes a character from the default input |
| 39 |
stream, and assigns the corresponding value to ch. |
| 40 |
The read result is set to allRight, endOfLine or endOfInput. |
| 41 |
*) |
| 42 |
BEGIN |
| 43 |
TextIO.ReadChar(StdChans.StdInChan(), ch) |
| 44 |
END ReadChar ; |
| 45 |
|
| 46 |
|
| 47 |
PROCEDURE ReadRestLine (VAR s: ARRAY OF CHAR); |
| 48 |
(* Removes any remaining characters from the default input |
| 49 |
stream before the next line mark, copying to s as many |
| 50 |
as can be accommodated as a string value. The read result |
| 51 |
is set to the value allRight, outOfRange, endOfLine, or |
| 52 |
endOfInput. |
| 53 |
*) |
| 54 |
BEGIN |
| 55 |
TextIO.ReadRestLine(StdChans.StdInChan(), s) |
| 56 |
END ReadRestLine ; |
| 57 |
|
| 58 |
|
| 59 |
PROCEDURE ReadString (VAR s: ARRAY OF CHAR); |
| 60 |
(* Removes only those characters from the default input stream |
| 61 |
before the next line mark that can be accommodated in s as |
| 62 |
a string value, and copies them to s. The read result |
| 63 |
is set to the value allRight, endOfLine, or endOfInput. |
| 64 |
*) |
| 65 |
BEGIN |
| 66 |
TextIO.ReadString(StdChans.StdInChan(), s) |
| 67 |
END ReadString ; |
| 68 |
|
| 69 |
|
| 70 |
PROCEDURE ReadToken (VAR s: ARRAY OF CHAR); |
| 71 |
(* Skips leading spaces, and then removes characters from the |
| 72 |
default input stream before the next space or line mark, |
| 73 |
copying to s as many as can be accommodated as a string |
| 74 |
value. The read result is set to the value allRight, |
| 75 |
outOfRange, endOfLine, or endOfInput. |
| 76 |
*) |
| 77 |
BEGIN |
| 78 |
TextIO.ReadToken(StdChans.StdInChan(), s) |
| 79 |
END ReadToken ; |
| 80 |
|
| 81 |
|
| 82 |
(* The following procedure reads past the next line mark *) |
| 83 |
|
| 84 |
PROCEDURE SkipLine; |
| 85 |
(* Removes successive items from the default input stream up |
| 86 |
to and including the next line mark or until the end of |
| 87 |
input is reached. The read result is set to the value |
| 88 |
allRight, or endOfInput. |
| 89 |
*) |
| 90 |
BEGIN |
| 91 |
TextIO.SkipLine(StdChans.StdInChan()) |
| 92 |
END SkipLine ; |
| 93 |
|
| 94 |
|
| 95 |
(* Output procedures *) |
| 96 |
|
| 97 |
PROCEDURE WriteChar (ch: CHAR); |
| 98 |
(* Writes the value of ch to the default output stream. *) |
| 99 |
BEGIN |
| 100 |
TextIO.WriteChar(StdChans.StdOutChan(), ch) |
| 101 |
END WriteChar ; |
| 102 |
|
| 103 |
|
| 104 |
PROCEDURE WriteLn; |
| 105 |
(* Writes a line mark to the default output stream. *) |
| 106 |
BEGIN |
| 107 |
TextIO.WriteLn(StdChans.StdOutChan()) |
| 108 |
END WriteLn ; |
| 109 |
|
| 110 |
|
| 111 |
PROCEDURE WriteString (s: ARRAY OF CHAR); |
| 112 |
(* Writes the string value of s to the default output stream. *) |
| 113 |
BEGIN |
| 114 |
TextIO.WriteString(StdChans.StdOutChan(), s) |
| 115 |
END WriteString ; |
| 116 |
|
| 117 |
|
| 118 |
END STextIO. |