Debian Codegraph @

gcc/m2/mc-boot/GFpuIO.cc

raw
1 /* do not edit automatically generated by mc from FpuIO. */
2 /* FpuIO.mod implements a fixed format input/output for REAL/LONGREAL.
3
4 Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <[email protected]>.
6
7 This file is part of GNU Modula-2.
8
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
22
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
27
28 #include "config.h"
29 #include "system.h"
30 #include <stdbool.h>
31 # if !defined (PROC_D)
32 # define PROC_D
33 typedef void (*PROC_t) (void);
34 typedef struct { PROC_t proc; } PROC;
35 # endif
36
37 # if !defined (TRUE)
38 # define TRUE (1==1)
39 # endif
40
41 # if !defined (FALSE)
42 # define FALSE (1==0)
43 # endif
44
45 #define _FpuIO_C
46
47 #include "GFpuIO.h"
48 # include "GStrIO.h"
49 # include "GStrLib.h"
50 # include "GASCII.h"
51 # include "GDynamicStrings.h"
52 # include "GStringConvert.h"
53
54 # define MaxLineLength 100
55 extern "C" void FpuIO_ReadReal (double *x);
56
57 /*
58 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
59 FractionWidth into, string, a.
60 */
61
62 extern "C" void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth);
63
64 /*
65 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
66 FractionWidth into, string, a.
67 */
68
69 extern "C" void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x);
70
71 /*
72 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
73 FractionWidth into a string.
74 */
75
76 extern "C" void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
77 extern "C" void FpuIO_ReadLongReal (long double *x);
78
79 /*
80 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
81 FractionWidth into a string.
82 */
83
84 extern "C" void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
85
86 /*
87 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
88 FractionWidth into a string.
89 */
90
91 extern "C" void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x);
92
93 /*
94 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
95 FractionWidth into a string.
96 */
97
98 extern "C" void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
99
100 /*
101 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
102 FractionWidth into a string.
103 */
104
105 extern "C" void FpuIO_ReadLongInt (long int *x);
106
107 /*
108 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
109 FractionWidth into a string.
110 */
111
112 extern "C" void FpuIO_WriteLongInt (long int x, unsigned int n);
113
114 /*
115 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
116 FractionWidth into a string.
117 */
118
119 extern "C" void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x);
120
121 /*
122 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
123 FractionWidth into a string.
124 */
125
126 extern "C" void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high);
127
128 extern "C" void FpuIO_ReadReal (double *x)
129 {
130 typedef struct ReadReal__T1_a ReadReal__T1;
131
132 struct ReadReal__T1_a { char array[MaxLineLength+1]; };
133 ReadReal__T1 a;
134
135 /*
136 #undef GM2_DEBUG_FPUIO
137 if defined(GM2_DEBUG_FPUIO)
138 # define InitString(X) InitStringDB(X, __FILE__, __LINE__)
139 # define InitStringCharStar(X) InitStringCharStarDB(X, __FILE__, __LINE__)
140 # define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__)
141 # define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__)
142 # define Dup(X) DupDB(X, __FILE__, __LINE__)
143 # define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__)
144 #endif
145 */
146 StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
147 FpuIO_StrToReal ((const char *) &a.array[0], MaxLineLength, x);
148 }
149
150
151 /*
152 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
153 FractionWidth into, string, a.
154 */
155
156 extern "C" void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth)
157 {
158 typedef struct WriteReal__T2_a WriteReal__T2;
159
160 struct WriteReal__T2_a { char array[MaxLineLength+1]; };
161 WriteReal__T2 a;
162
163 FpuIO_RealToStr (x, TotalWidth, FractionWidth, (char *) &a.array[0], MaxLineLength);
164 StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
165 }
166
167
168 /*
169 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
170 FractionWidth into, string, a.
171 */
172
173 extern "C" void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x)
174 {
175 long double lr;
176 char a[_a_high+1];
177
178 /* make a local copy of each unbounded array. */
179 memcpy (a, a_, _a_high+1);
180
181 FpuIO_StrToLongReal ((const char *) a, _a_high, &lr); /* let StrToLongReal do the work and we convert the result back to REAL */
182 (*x) = (double ) (lr); /* let StrToLongReal do the work and we convert the result back to REAL */
183 }
184
185
186 /*
187 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
188 FractionWidth into a string.
189 */
190
191 extern "C" void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
192 {
193 long double lr;
194
195 lr = (long double ) (x);
196 FpuIO_LongRealToStr (lr, TotalWidth, FractionWidth, (char *) a, _a_high);
197 }
198
199 extern "C" void FpuIO_ReadLongReal (long double *x)
200 {
201 typedef struct ReadLongReal__T3_a ReadLongReal__T3;
202
203 struct ReadLongReal__T3_a { char array[MaxLineLength+1]; };
204 ReadLongReal__T3 a;
205
206 StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
207 FpuIO_StrToLongReal ((const char *) &a.array[0], MaxLineLength, x);
208 }
209
210
211 /*
212 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
213 FractionWidth into a string.
214 */
215
216 extern "C" void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth)
217 {
218 typedef struct WriteLongReal__T4_a WriteLongReal__T4;
219
220 struct WriteLongReal__T4_a { char array[MaxLineLength+1]; };
221 WriteLongReal__T4 a;
222
223 FpuIO_LongRealToStr (x, TotalWidth, FractionWidth, (char *) &a.array[0], MaxLineLength);
224 StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
225 }
226
227
228 /*
229 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
230 FractionWidth into a string.
231 */
232
233 extern "C" void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x)
234 {
235 bool found;
236 DynamicStrings_String s;
237 char a[_a_high+1];
238
239 /* make a local copy of each unbounded array. */
240 memcpy (a, a_, _a_high+1);
241
242 s = DynamicStrings_InitString ((const char *) a, _a_high);
243 (*x) = StringConvert_StringToLongreal (s, &found);
244 s = DynamicStrings_KillString (s);
245 }
246
247
248 /*
249 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
250 FractionWidth into a string.
251 */
252
253 extern "C" void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
254 {
255 DynamicStrings_String s;
256
257 s = StringConvert_LongrealToString (x, TotalWidth, FractionWidth);
258 DynamicStrings_CopyOut ((char *) a, _a_high, s);
259 s = DynamicStrings_KillString (s);
260 }
261
262
263 /*
264 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
265 FractionWidth into a string.
266 */
267
268 extern "C" void FpuIO_ReadLongInt (long int *x)
269 {
270 typedef struct ReadLongInt__T5_a ReadLongInt__T5;
271
272 struct ReadLongInt__T5_a { char array[MaxLineLength+1]; };
273 ReadLongInt__T5 a;
274
275 StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
276 FpuIO_StrToLongInt ((const char *) &a.array[0], MaxLineLength, x);
277 }
278
279
280 /*
281 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
282 FractionWidth into a string.
283 */
284
285 extern "C" void FpuIO_WriteLongInt (long int x, unsigned int n)
286 {
287 typedef struct WriteLongInt__T6_a WriteLongInt__T6;
288
289 struct WriteLongInt__T6_a { char array[MaxLineLength+1]; };
290 WriteLongInt__T6 a;
291
292 FpuIO_LongIntToStr (x, n, (char *) &a.array[0], MaxLineLength);
293 StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
294 }
295
296
297 /*
298 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
299 FractionWidth into a string.
300 */
301
302 extern "C" void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x)
303 {
304 DynamicStrings_String s;
305 bool found;
306 char a[_a_high+1];
307
308 /* make a local copy of each unbounded array. */
309 memcpy (a, a_, _a_high+1);
310
311 s = DynamicStrings_InitString ((const char *) a, _a_high);
312 (*x) = StringConvert_StringToLongInteger (s, 10, &found);
313 s = DynamicStrings_KillString (s);
314 }
315
316
317 /*
318 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
319 FractionWidth into a string.
320 */
321
322 extern "C" void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high)
323 {
324 DynamicStrings_String s;
325
326 s = StringConvert_LongIntegerToString (x, n, ' ', false, 10, true);
327 DynamicStrings_CopyOut ((char *) a, _a_high, s);
328 s = DynamicStrings_KillString (s);
329 }
330
331 extern "C" void _M2_FpuIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
332 {
333 }
334
335 extern "C" void _M2_FpuIO_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
336 {
337 }