1 /* do not edit automatically generated by mc from FpuIO. */
2 /* FpuIO.mod implements a fixed format input/output for REAL/LONGREAL.
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
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)
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.
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.
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/>. */
30 # if !defined (PROC_D)
32 typedef void (*PROC_t
) (void);
33 typedef struct { PROC_t proc
; } PROC
;
50 # include "GDynamicStrings.h"
51 # include "GStringConvert.h"
53 # define MaxLineLength 100
54 extern "C" void FpuIO_ReadReal (double *x
);
57 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
58 FractionWidth into, string, a.
61 extern "C" void FpuIO_WriteReal (double x
, unsigned int TotalWidth
, unsigned int FractionWidth
);
64 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
65 FractionWidth into, string, a.
68 extern "C" void FpuIO_StrToReal (const char *a_
, unsigned int _a_high
, double *x
);
71 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
72 FractionWidth into a string.
75 extern "C" void FpuIO_RealToStr (double x
, unsigned int TotalWidth
, unsigned int FractionWidth
, char *a
, unsigned int _a_high
);
76 extern "C" void FpuIO_ReadLongReal (long double *x
);
79 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
80 FractionWidth into a string.
83 extern "C" void FpuIO_WriteLongReal (long double x
, unsigned int TotalWidth
, unsigned int FractionWidth
);
86 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
87 FractionWidth into a string.
90 extern "C" void FpuIO_StrToLongReal (const char *a_
, unsigned int _a_high
, long double *x
);
93 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
94 FractionWidth into a string.
97 extern "C" void FpuIO_LongRealToStr (long double x
, unsigned int TotalWidth
, unsigned int FractionWidth
, char *a
, unsigned int _a_high
);
100 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
101 FractionWidth into a string.
104 extern "C" void FpuIO_ReadLongInt (long int *x
);
107 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
108 FractionWidth into a string.
111 extern "C" void FpuIO_WriteLongInt (long int x
, unsigned int n
);
114 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
115 FractionWidth into a string.
118 extern "C" void FpuIO_StrToLongInt (const char *a_
, unsigned int _a_high
, long int *x
);
121 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
122 FractionWidth into a string.
125 extern "C" void FpuIO_LongIntToStr (long int x
, unsigned int n
, char *a
, unsigned int _a_high
);
127 extern "C" void FpuIO_ReadReal (double *x
)
129 typedef struct ReadReal__T1_a ReadReal__T1
;
131 struct ReadReal__T1_a
{ char array
[MaxLineLength
+1]; };
135 #undef GM2_DEBUG_FPUIO
136 if 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__)
145 StrIO_ReadString ((char *) &a
.array
[0], MaxLineLength
);
146 FpuIO_StrToReal ((const char *) &a
.array
[0], MaxLineLength
, x
);
151 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
152 FractionWidth into, string, a.
155 extern "C" void FpuIO_WriteReal (double x
, unsigned int TotalWidth
, unsigned int FractionWidth
)
157 typedef struct WriteReal__T2_a WriteReal__T2
;
159 struct WriteReal__T2_a
{ char array
[MaxLineLength
+1]; };
162 FpuIO_RealToStr (x
, TotalWidth
, FractionWidth
, (char *) &a
.array
[0], MaxLineLength
);
163 StrIO_WriteString ((const char *) &a
.array
[0], MaxLineLength
);
168 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
169 FractionWidth into, string, a.
172 extern "C" void FpuIO_StrToReal (const char *a_
, unsigned int _a_high
, double *x
)
177 /* make a local copy of each unbounded array. */
178 memcpy (a
, a_
, _a_high
+1);
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 */
186 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
187 FractionWidth into a string.
190 extern "C" void FpuIO_RealToStr (double x
, unsigned int TotalWidth
, unsigned int FractionWidth
, char *a
, unsigned int _a_high
)
194 lr
= (long double ) (x
);
195 FpuIO_LongRealToStr (lr
, TotalWidth
, FractionWidth
, (char *) a
, _a_high
);
198 extern "C" void FpuIO_ReadLongReal (long double *x
)
200 typedef struct ReadLongReal__T3_a ReadLongReal__T3
;
202 struct ReadLongReal__T3_a
{ char array
[MaxLineLength
+1]; };
205 StrIO_ReadString ((char *) &a
.array
[0], MaxLineLength
);
206 FpuIO_StrToLongReal ((const char *) &a
.array
[0], MaxLineLength
, x
);
211 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
212 FractionWidth into a string.
215 extern "C" void FpuIO_WriteLongReal (long double x
, unsigned int TotalWidth
, unsigned int FractionWidth
)
217 typedef struct WriteLongReal__T4_a WriteLongReal__T4
;
219 struct WriteLongReal__T4_a
{ char array
[MaxLineLength
+1]; };
222 FpuIO_LongRealToStr (x
, TotalWidth
, FractionWidth
, (char *) &a
.array
[0], MaxLineLength
);
223 StrIO_WriteString ((const char *) &a
.array
[0], MaxLineLength
);
228 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
229 FractionWidth into a string.
232 extern "C" void FpuIO_StrToLongReal (const char *a_
, unsigned int _a_high
, long double *x
)
235 DynamicStrings_String s
;
238 /* make a local copy of each unbounded array. */
239 memcpy (a
, a_
, _a_high
+1);
241 s
= DynamicStrings_InitString ((const char *) a
, _a_high
);
242 (*x
) = StringConvert_StringToLongreal (s
, &found
);
243 s
= DynamicStrings_KillString (s
);
248 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
249 FractionWidth into a string.
252 extern "C" void FpuIO_LongRealToStr (long double x
, unsigned int TotalWidth
, unsigned int FractionWidth
, char *a
, unsigned int _a_high
)
254 DynamicStrings_String s
;
256 s
= StringConvert_LongrealToString (x
, TotalWidth
, FractionWidth
);
257 DynamicStrings_CopyOut ((char *) a
, _a_high
, s
);
258 s
= DynamicStrings_KillString (s
);
263 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
264 FractionWidth into a string.
267 extern "C" void FpuIO_ReadLongInt (long int *x
)
269 typedef struct ReadLongInt__T5_a ReadLongInt__T5
;
271 struct ReadLongInt__T5_a
{ char array
[MaxLineLength
+1]; };
274 StrIO_ReadString ((char *) &a
.array
[0], MaxLineLength
);
275 FpuIO_StrToLongInt ((const char *) &a
.array
[0], MaxLineLength
, x
);
280 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
281 FractionWidth into a string.
284 extern "C" void FpuIO_WriteLongInt (long int x
, unsigned int n
)
286 typedef struct WriteLongInt__T6_a WriteLongInt__T6
;
288 struct WriteLongInt__T6_a
{ char array
[MaxLineLength
+1]; };
291 FpuIO_LongIntToStr (x
, n
, (char *) &a
.array
[0], MaxLineLength
);
292 StrIO_WriteString ((const char *) &a
.array
[0], MaxLineLength
);
297 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
298 FractionWidth into a string.
301 extern "C" void FpuIO_StrToLongInt (const char *a_
, unsigned int _a_high
, long int *x
)
303 DynamicStrings_String s
;
307 /* make a local copy of each unbounded array. */
308 memcpy (a
, a_
, _a_high
+1);
310 s
= DynamicStrings_InitString ((const char *) a
, _a_high
);
311 (*x
) = StringConvert_StringToLongInteger (s
, 10, &found
);
312 s
= DynamicStrings_KillString (s
);
317 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
318 FractionWidth into a string.
321 extern "C" void FpuIO_LongIntToStr (long int x
, unsigned int n
, char *a
, unsigned int _a_high
)
323 DynamicStrings_String s
;
325 s
= StringConvert_LongIntegerToString (x
, n
, ' ', FALSE
, 10, TRUE
);
326 DynamicStrings_CopyOut ((char *) a
, _a_high
, s
);
327 s
= DynamicStrings_KillString (s
);
330 extern "C" void _M2_FpuIO_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
334 extern "C" void _M2_FpuIO_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])