1 (* StrIO.mod provides simple string input output routines.
3 Copyright (C) 2001-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 StrIO
;
30 FROM ASCII
IMPORT cr
, nul
, lf
, bel
, del
, bs
, nak
, etb
, ff
, eof
;
31 FROM StdIO
IMPORT Read
, Write
;
32 FROM libc
IMPORT isatty
;
36 IsATTY
: BOOLEAN ; (* Is default input from the keyboard? *)
40 WriteLn - writes a carriage return and a newline
52 ReadString - reads a sequence of characters into a string.
53 Line editing accepts Del, Ctrl H, Ctrl W and
57 PROCEDURE ReadString (VAR a
: ARRAY OF CHAR) ;
67 IF (ch
=del
) OR (ch
=bs
)
76 ELSIF ch
=nak (* Ctrl U *)
82 ELSIF ch
=etb (* Ctrl W *)
87 ELSIF AlphaNum(a
[n
-1])
92 UNTIL (n
=0) OR (NOT AlphaNum(a
[n
-1]))
130 UNTIL (ch
=cr
) OR (ch
=lf
)
135 WriteString - writes a string to the default output.
138 PROCEDURE WriteString (a
: ARRAY OF CHAR) ;
145 WHILE (n
<= high
) AND (a
[n
] # nul
) DO
153 Erase - writes a backspace, space and backspace to remove the
154 last character displayed.
166 Echo - echos the character, ch, onto the output channel if IsATTY
170 PROCEDURE Echo (ch
: CHAR) ;
180 AlphaNum- returns true if character, ch, is an alphanumeric character.
183 PROCEDURE AlphaNum (ch
: CHAR) : BOOLEAN ;
185 RETURN ((ch
>='a') AND (ch
<='z')) OR
186 ((ch
>='A') AND (ch
<='Z')) OR
187 ((ch
>='0') AND (ch
<='9'))
192 (* IsATTY := isatty() *)