]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/gm2-libs-log/CardinalIO.mod
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-libs-log / CardinalIO.mod
CommitLineData
1eee94d3
GM
1(* CardinalIO.mod provides a PIM and Logitech compatible module.
2
a945c346 3Copyright (C) 2004-2024 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. *)
26
27IMPLEMENTATION MODULE CardinalIO ;
28
29
30FROM DynamicStrings IMPORT String, InitString, KillString, RemoveWhitePrefix ;
31FROM SYSTEM IMPORT ADR, BYTE ;
32IMPORT InOut ;
33
34FROM StringConvert IMPORT StringToCardinal, CardinalToString,
35 StringToLongCardinal, LongCardinalToString,
36 StringToShortCardinal, ShortCardinalToString ;
37
38
39(*
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.
43*)
44
45PROCEDURE ReadCardinal (VAR c: CARDINAL) ;
46VAR
47 s: String ;
48BEGIN
49 s := RemoveWhitePrefix(InOut.ReadS()) ;
50 IF InOut.Done
51 THEN
52 c := StringToCardinal(s, 10, Done)
53 ELSE
54 Done := FALSE
55 END ;
56 s := KillString(s)
57END ReadCardinal ;
58
59
60(*
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.
64*)
65
66PROCEDURE WriteCardinal (c: CARDINAL; n: CARDINAL) ;
67VAR
68 s: String ;
69BEGIN
70 s := KillString(InOut.WriteS(CardinalToString(c, n, ' ', 10, FALSE))) ;
71 Done := TRUE
72END WriteCardinal ;
73
74
75(*
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.
79*)
80
81PROCEDURE ReadHex (VAR c: CARDINAL) ;
82VAR
83 s: String ;
84BEGIN
85 s := RemoveWhitePrefix(InOut.ReadS()) ;
86 IF InOut.Done
87 THEN
88 c := StringToCardinal(s, 16, Done)
89 ELSE
90 Done := FALSE
91 END ;
92 s := KillString(s)
93END ReadHex ;
94
95
96(*
97 WriteHex - writes out a CARDINAL, c, in hexadecimal format padding
98 with, n, characters (leading with '0')
99*)
100
101PROCEDURE WriteHex (c: CARDINAL; n: CARDINAL) ;
102VAR
103 s: String ;
104BEGIN
105 s := KillString(InOut.WriteS(CardinalToString(c, n, '0', 16, TRUE))) ;
106 Done := TRUE
107END WriteHex ;
108
109
110(*
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.
114*)
115
116PROCEDURE ReadLongCardinal (VAR c: LONGCARD) ;
117VAR
118 s: String ;
119BEGIN
120 s := RemoveWhitePrefix(InOut.ReadS()) ;
121 IF InOut.Done
122 THEN
123 c := StringToLongCardinal(s, 10, Done)
124 ELSE
125 Done := FALSE
126 END ;
127 s := KillString(s)
128END ReadLongCardinal ;
129
130
131(*
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.
135*)
136
137PROCEDURE WriteLongCardinal (c: LONGCARD; n: CARDINAL) ;
138VAR
139 s: String ;
140BEGIN
141 s := KillString(InOut.WriteS(LongCardinalToString(c, n, ' ', 10, FALSE))) ;
142 Done := TRUE
143END WriteLongCardinal ;
144
145
146(*
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.
150*)
151
152PROCEDURE ReadLongHex (VAR c: LONGCARD) ;
153VAR
154 s: String ;
155BEGIN
156 s := RemoveWhitePrefix(InOut.ReadS()) ;
157 IF InOut.Done
158 THEN
159 c := StringToLongCardinal(s, 16, Done)
160 ELSE
161 Done := FALSE
162 END ;
163 s := KillString(s)
164END ReadLongHex ;
165
166
167(*
168 WriteLongHex - writes out a LONGCARD, c, in hexadecimal format padding
169 with, n, characters (leading with '0')
170*)
171
172PROCEDURE WriteLongHex (c: LONGCARD; n: CARDINAL) ;
173VAR
174 s: String ;
175BEGIN
176 s := KillString(InOut.WriteS(LongCardinalToString(c, n, '0', 16, TRUE))) ;
177 Done := TRUE
178END WriteLongHex ;
179
180
181(*
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.
185*)
186
187PROCEDURE ReadShortCardinal (VAR c: SHORTCARD) ;
188VAR
189 s: String ;
190BEGIN
191 s := RemoveWhitePrefix(InOut.ReadS()) ;
192 IF InOut.Done
193 THEN
194 c := StringToShortCardinal(s, 10, Done)
195 ELSE
196 Done := FALSE
197 END ;
198 s := KillString(s)
199END ReadShortCardinal ;
200
201
202(*
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.
206*)
207
208PROCEDURE WriteShortCardinal (c: SHORTCARD; n: CARDINAL) ;
209VAR
210 s: String ;
211BEGIN
212 s := KillString(InOut.WriteS(ShortCardinalToString(c, n, ' ', 10, FALSE))) ;
213 Done := TRUE
214END WriteShortCardinal ;
215
216
217(*
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.
221*)
222
223PROCEDURE ReadShortHex (VAR c: SHORTCARD) ;
224VAR
225 s: String ;
226BEGIN
227 s := RemoveWhitePrefix(InOut.ReadS()) ;
228 IF InOut.Done
229 THEN
230 c := StringToShortCardinal(s, 16, Done)
231 ELSE
232 Done := FALSE
233 END ;
234 s := KillString(s)
235END ReadShortHex ;
236
237
238(*
239 WriteShortHex - writes out a SHORTCARD, c, in hexadecimal format padding
240 with, n, characters (leading with '0')
241*)
242
243PROCEDURE WriteShortHex (c: SHORTCARD; n: CARDINAL) ;
244VAR
245 s: String ;
246BEGIN
247 s := KillString(InOut.WriteS(ShortCardinalToString(c, n, '0', 16, TRUE))) ;
248 Done := TRUE
249END WriteShortHex ;
250
251
252END CardinalIO.
253(*
254 * Local variables:
255 * compile-command: "gm2 -I.:../gm2-libs -g -c -Wsources CardinalIO.mod"
256 * End:
257 *)