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