1 (* STextIO.mod implement the ISO STextIO specification.
3 Copyright (C) 2008-2024 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 IMPLEMENTATION MODULE STextIO
;
29 IMPORT StdChans
, TextIO
;
31 (* Input and output of character and string types over default channels. The read result
32 is of the type IOConsts.ReadResults.
35 (* The following procedures do not read past line marks *)
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.
43 TextIO.
ReadChar(StdChans.
StdInChan(), ch
)
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
55 TextIO.
ReadRestLine(StdChans.
StdInChan(), s
)
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.
66 TextIO.
ReadString(StdChans.
StdInChan(), s
)
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.
78 TextIO.
ReadToken(StdChans.
StdInChan(), s
)
82 (* The following procedure reads past the next line mark *)
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.
91 TextIO.
SkipLine(StdChans.
StdInChan())
95 (* Output procedures *)
97 PROCEDURE WriteChar (ch
: CHAR);
98 (* Writes the value of ch to the default output stream. *)
100 TextIO.
WriteChar(StdChans.
StdOutChan(), ch
)
105 (* Writes a line mark to the default output stream. *)
107 TextIO.
WriteLn(StdChans.
StdOutChan())
111 PROCEDURE WriteString (s
: ARRAY OF CHAR);
112 (* Writes the string value of s to the default output stream. *)
114 TextIO.
WriteString(StdChans.
StdOutChan(), s
)