1 (* CardinalIO.mod provides a PIM and Logitech compatible 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 IMPLEMENTATION MODULE CardinalIO ;
30 FROM DynamicStrings IMPORT String, InitString, KillString, RemoveWhitePrefix ;
31 FROM SYSTEM IMPORT ADR, BYTE ;
34 FROM StringConvert IMPORT StringToCardinal, CardinalToString,
35 StringToLongCardinal, LongCardinalToString,
36 StringToShortCardinal, ShortCardinalToString ;
40 ReadCardinal - read an unsigned decimal number from the terminal.
41 The read continues until a space, newline, esc or
42 end of file is reached.
45 PROCEDURE ReadCardinal (VAR c: CARDINAL) ;
49 s := RemoveWhitePrefix(InOut.ReadS()) ;
52 c := StringToCardinal(s, 10, Done)
61 WriteCardinal - writes the value, c, to the terminal and ensures
62 that at least, n, characters are written. The number
63 will be padded out by preceeding spaces if necessary.
66 PROCEDURE WriteCardinal (c: CARDINAL; n: CARDINAL) ;
70 s := KillString(InOut.WriteS(CardinalToString(c, n, ' ', 10, FALSE))) ;
76 ReadHex - reads in an unsigned hexadecimal number from the terminal.
77 The read continues until a space, newline, esc or
78 end of file is reached.
81 PROCEDURE ReadHex (VAR c: CARDINAL) ;
85 s := RemoveWhitePrefix(InOut.ReadS()) ;
88 c := StringToCardinal(s, 16, Done)
97 WriteHex - writes out a CARDINAL, c, in hexadecimal format padding
98 with, n, characters (leading with '0')
101 PROCEDURE WriteHex (c: CARDINAL; n: CARDINAL) ;
105 s := KillString(InOut.WriteS(CardinalToString(c, n, '0', 16, TRUE))) ;
111 ReadLongCardinal - read an unsigned decimal number from the terminal.
112 The read continues until a space, newline, esc or
113 end of file is reached.
116 PROCEDURE ReadLongCardinal (VAR c: LONGCARD) ;
120 s := RemoveWhitePrefix(InOut.ReadS()) ;
123 c := StringToLongCardinal(s, 10, Done)
128 END ReadLongCardinal ;
132 WriteLongCardinal - writes the value, c, to the terminal and ensures
133 that at least, n, characters are written. The number
134 will be padded out by preceeding spaces if necessary.
137 PROCEDURE WriteLongCardinal (c: LONGCARD; n: CARDINAL) ;
141 s := KillString(InOut.WriteS(LongCardinalToString(c, n, ' ', 10, FALSE))) ;
143 END WriteLongCardinal ;
147 ReadLongHex - reads in an unsigned hexadecimal number from the terminal.
148 The read continues until a space, newline, esc or
149 end of file is reached.
152 PROCEDURE ReadLongHex (VAR c: LONGCARD) ;
156 s := RemoveWhitePrefix(InOut.ReadS()) ;
159 c := StringToLongCardinal(s, 16, Done)
168 WriteLongHex - writes out a LONGCARD, c, in hexadecimal format padding
169 with, n, characters (leading with '0')
172 PROCEDURE WriteLongHex (c: LONGCARD; n: CARDINAL) ;
176 s := KillString(InOut.WriteS(LongCardinalToString(c, n, '0', 16, TRUE))) ;
182 ReadShortCardinal - read an unsigned decimal number from the terminal.
183 The read continues until a space, newline, esc or
184 end of file is reached.
187 PROCEDURE ReadShortCardinal (VAR c: SHORTCARD) ;
191 s := RemoveWhitePrefix(InOut.ReadS()) ;
194 c := StringToShortCardinal(s, 10, Done)
199 END ReadShortCardinal ;
203 WriteShortCardinal - writes the value, c, to the terminal and ensures
204 that at least, n, characters are written. The number
205 will be padded out by preceeding spaces if necessary.
208 PROCEDURE WriteShortCardinal (c: SHORTCARD; n: CARDINAL) ;
212 s := KillString(InOut.WriteS(ShortCardinalToString(c, n, ' ', 10, FALSE))) ;
214 END WriteShortCardinal ;
218 ReadShortHex - reads in an unsigned hexadecimal number from the terminal.
219 The read continues until a space, newline, esc or
220 end of file is reached.
223 PROCEDURE ReadShortHex (VAR c: SHORTCARD) ;
227 s := RemoveWhitePrefix(InOut.ReadS()) ;
230 c := StringToShortCardinal(s, 16, Done)
239 WriteShortHex - writes out a SHORTCARD, c, in hexadecimal format padding
240 with, n, characters (leading with '0')
243 PROCEDURE WriteShortHex (c: SHORTCARD; n: CARDINAL) ;
247 s := KillString(InOut.WriteS(ShortCardinalToString(c, n, '0', 16, TRUE))) ;
255 * compile-command: "gm2 -I.:../gm2-libs -g -c -Wsources CardinalIO.mod"