]>
Commit | Line | Data |
---|---|---|
1eee94d3 GM |
1 | /* do not edit automatically generated by mc from NumberIO. */ |
2 | /* NumberIO.mod provides conversion of ordinal numbers. | |
3 | ||
83ffe9cd | 4 | Copyright (C) 2001-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
5 | Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
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 | # if !defined (PROC_D) | |
29 | # define PROC_D | |
30 | typedef void (*PROC_t) (void); | |
31 | typedef struct { PROC_t proc; } PROC; | |
32 | # endif | |
33 | ||
34 | # if !defined (TRUE) | |
35 | # define TRUE (1==1) | |
36 | # endif | |
37 | ||
38 | # if !defined (FALSE) | |
39 | # define FALSE (1==0) | |
40 | # endif | |
41 | ||
42 | #include <string.h> | |
43 | #include <limits.h> | |
44 | #include <stdlib.h> | |
45 | #define _NumberIO_H | |
46 | #define _NumberIO_C | |
47 | ||
48 | # include "GASCII.h" | |
49 | # include "GStrIO.h" | |
50 | # include "GStrLib.h" | |
51 | # include "GM2RTS.h" | |
52 | ||
53 | # define MaxLineLength 79 | |
54 | # define MaxDigits 20 | |
55 | # define MaxHexDigits 20 | |
56 | # define MaxOctDigits 40 | |
57 | # define MaxBits 64 | |
58 | extern "C" void NumberIO_ReadCard (unsigned int *x); | |
59 | extern "C" void NumberIO_WriteCard (unsigned int x, unsigned int n); | |
60 | extern "C" void NumberIO_ReadHex (unsigned int *x); | |
61 | extern "C" void NumberIO_WriteHex (unsigned int x, unsigned int n); | |
62 | extern "C" void NumberIO_ReadInt (int *x); | |
63 | extern "C" void NumberIO_WriteInt (int x, unsigned int n); | |
64 | extern "C" void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high); | |
65 | extern "C" void NumberIO_StrToCard (const char *a_, unsigned int _a_high, unsigned int *x); | |
66 | extern "C" void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high); | |
67 | extern "C" void NumberIO_StrToHex (const char *a_, unsigned int _a_high, unsigned int *x); | |
68 | extern "C" void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high); | |
69 | extern "C" void NumberIO_StrToInt (const char *a_, unsigned int _a_high, int *x); | |
70 | extern "C" void NumberIO_ReadOct (unsigned int *x); | |
71 | extern "C" void NumberIO_WriteOct (unsigned int x, unsigned int n); | |
72 | extern "C" void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high); | |
73 | extern "C" void NumberIO_StrToOct (const char *a_, unsigned int _a_high, unsigned int *x); | |
74 | extern "C" void NumberIO_ReadBin (unsigned int *x); | |
75 | extern "C" void NumberIO_WriteBin (unsigned int x, unsigned int n); | |
76 | extern "C" void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high); | |
77 | extern "C" void NumberIO_StrToBin (const char *a_, unsigned int _a_high, unsigned int *x); | |
78 | extern "C" void NumberIO_StrToBinInt (const char *a_, unsigned int _a_high, int *x); | |
79 | extern "C" void NumberIO_StrToHexInt (const char *a_, unsigned int _a_high, int *x); | |
80 | extern "C" void NumberIO_StrToOctInt (const char *a_, unsigned int _a_high, int *x); | |
81 | ||
82 | extern "C" void NumberIO_ReadCard (unsigned int *x) | |
83 | { | |
84 | typedef struct ReadCard__T1_a ReadCard__T1; | |
85 | ||
86 | struct ReadCard__T1_a { char array[MaxLineLength+1]; }; | |
87 | ReadCard__T1 a; | |
88 | ||
89 | StrIO_ReadString ((char *) &a.array[0], MaxLineLength); | |
90 | NumberIO_StrToCard ((const char *) &a.array[0], MaxLineLength, x); | |
91 | } | |
92 | ||
93 | extern "C" void NumberIO_WriteCard (unsigned int x, unsigned int n) | |
94 | { | |
95 | typedef struct WriteCard__T2_a WriteCard__T2; | |
96 | ||
97 | struct WriteCard__T2_a { char array[MaxLineLength+1]; }; | |
98 | WriteCard__T2 a; | |
99 | ||
100 | NumberIO_CardToStr (x, n, (char *) &a.array[0], MaxLineLength); | |
101 | StrIO_WriteString ((const char *) &a.array[0], MaxLineLength); | |
102 | } | |
103 | ||
104 | extern "C" void NumberIO_ReadHex (unsigned int *x) | |
105 | { | |
106 | typedef struct ReadHex__T3_a ReadHex__T3; | |
107 | ||
108 | struct ReadHex__T3_a { char array[MaxLineLength+1]; }; | |
109 | ReadHex__T3 a; | |
110 | ||
111 | StrIO_ReadString ((char *) &a.array[0], MaxLineLength); | |
112 | NumberIO_StrToHex ((const char *) &a.array[0], MaxLineLength, x); | |
113 | } | |
114 | ||
115 | extern "C" void NumberIO_WriteHex (unsigned int x, unsigned int n) | |
116 | { | |
117 | typedef struct WriteHex__T4_a WriteHex__T4; | |
118 | ||
119 | struct WriteHex__T4_a { char array[MaxLineLength+1]; }; | |
120 | WriteHex__T4 a; | |
121 | ||
122 | NumberIO_HexToStr (x, n, (char *) &a.array[0], MaxLineLength); | |
123 | StrIO_WriteString ((const char *) &a.array[0], MaxLineLength); | |
124 | } | |
125 | ||
126 | extern "C" void NumberIO_ReadInt (int *x) | |
127 | { | |
128 | typedef struct ReadInt__T5_a ReadInt__T5; | |
129 | ||
130 | struct ReadInt__T5_a { char array[MaxLineLength+1]; }; | |
131 | ReadInt__T5 a; | |
132 | ||
133 | StrIO_ReadString ((char *) &a.array[0], MaxLineLength); | |
134 | NumberIO_StrToInt ((const char *) &a.array[0], MaxLineLength, x); | |
135 | } | |
136 | ||
137 | extern "C" void NumberIO_WriteInt (int x, unsigned int n) | |
138 | { | |
139 | typedef struct WriteInt__T6_a WriteInt__T6; | |
140 | ||
141 | struct WriteInt__T6_a { char array[MaxLineLength+1]; }; | |
142 | WriteInt__T6 a; | |
143 | ||
144 | NumberIO_IntToStr (x, n, (char *) &a.array[0], MaxLineLength); | |
145 | StrIO_WriteString ((const char *) &a.array[0], MaxLineLength); | |
146 | } | |
147 | ||
148 | extern "C" void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high) | |
149 | { | |
150 | typedef struct CardToStr__T7_a CardToStr__T7; | |
151 | ||
152 | struct CardToStr__T7_a { unsigned int array[MaxDigits-1+1]; }; | |
153 | unsigned int i; | |
154 | unsigned int j; | |
155 | unsigned int Higha; | |
156 | CardToStr__T7 buf; | |
157 | ||
158 | i = 0; | |
159 | do { | |
160 | i += 1; | |
161 | if (i > MaxDigits) | |
162 | { | |
163 | StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29); | |
164 | StrIO_WriteLn (); | |
165 | M2RTS_HALT (-1); | |
166 | __builtin_unreachable (); | |
167 | } | |
168 | buf.array[i-1] = x % 10; | |
169 | x = x / 10; | |
170 | } while (! (x == 0)); | |
171 | j = 0; | |
172 | Higha = _a_high; | |
173 | while ((n > i) && (j <= Higha)) | |
174 | { | |
175 | a[j] = ' '; | |
176 | j += 1; | |
177 | n -= 1; | |
178 | } | |
179 | while ((i > 0) && (j <= Higha)) | |
180 | { | |
181 | a[j] = ((char) (buf.array[i-1]+ ((unsigned int) ('0')))); | |
182 | j += 1; | |
183 | i -= 1; | |
184 | } | |
185 | if (j <= Higha) | |
186 | { | |
187 | a[j] = ASCII_nul; | |
188 | } | |
189 | } | |
190 | ||
191 | extern "C" void NumberIO_StrToCard (const char *a_, unsigned int _a_high, unsigned int *x) | |
192 | { | |
193 | unsigned int i; | |
194 | unsigned int ok; | |
195 | unsigned int higha; | |
196 | char a[_a_high+1]; | |
197 | ||
198 | /* make a local copy of each unbounded array. */ | |
199 | memcpy (a, a_, _a_high+1); | |
200 | ||
201 | StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high); | |
202 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
203 | i = 0; | |
204 | ok = TRUE; | |
205 | while (ok) | |
206 | { | |
207 | if (i < higha) | |
208 | { | |
209 | if ((a[i] < '0') || (a[i] > '9')) | |
210 | { | |
211 | i += 1; | |
212 | } | |
213 | else | |
214 | { | |
215 | ok = FALSE; | |
216 | } | |
217 | } | |
218 | else | |
219 | { | |
220 | ok = FALSE; | |
221 | } | |
222 | } | |
223 | (*x) = 0; | |
224 | if (i < higha) | |
225 | { | |
226 | ok = TRUE; | |
227 | do { | |
228 | (*x) = (10*(*x))+( ((unsigned int) (a[i]))- ((unsigned int) ('0'))); | |
229 | if (i < higha) | |
230 | { | |
231 | /* avoid dangling else. */ | |
232 | i += 1; | |
233 | if ((a[i] < '0') || (a[i] > '9')) | |
234 | { | |
235 | ok = FALSE; | |
236 | } | |
237 | } | |
238 | else | |
239 | { | |
240 | ok = FALSE; | |
241 | } | |
242 | } while (! (! ok)); | |
243 | } | |
244 | } | |
245 | ||
246 | extern "C" void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high) | |
247 | { | |
248 | typedef struct HexToStr__T8_a HexToStr__T8; | |
249 | ||
250 | struct HexToStr__T8_a { unsigned int array[MaxHexDigits-1+1]; }; | |
251 | unsigned int i; | |
252 | unsigned int j; | |
253 | unsigned int Higha; | |
254 | HexToStr__T8 buf; | |
255 | ||
256 | i = 0; | |
257 | do { | |
258 | i += 1; | |
259 | if (i > MaxHexDigits) | |
260 | { | |
261 | StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29); | |
262 | StrIO_WriteLn (); | |
263 | M2RTS_HALT (-1); | |
264 | __builtin_unreachable (); | |
265 | } | |
266 | buf.array[i-1] = x % 0x010; | |
267 | x = x / 0x010; | |
268 | } while (! (x == 0)); | |
269 | j = 0; | |
270 | Higha = _a_high; | |
271 | while ((n > i) && (j <= Higha)) | |
272 | { | |
273 | a[j] = '0'; | |
274 | j += 1; | |
275 | n -= 1; | |
276 | } | |
277 | while ((i != 0) && (j <= Higha)) | |
278 | { | |
279 | if (buf.array[i-1] < 10) | |
280 | { | |
281 | a[j] = ((char) (buf.array[i-1]+ ((unsigned int) ('0')))); | |
282 | } | |
283 | else | |
284 | { | |
285 | a[j] = ((char) ((buf.array[i-1]+ ((unsigned int) ('A')))-10)); | |
286 | } | |
287 | j += 1; | |
288 | i -= 1; | |
289 | } | |
290 | if (j <= Higha) | |
291 | { | |
292 | a[j] = ASCII_nul; | |
293 | } | |
294 | } | |
295 | ||
296 | extern "C" void NumberIO_StrToHex (const char *a_, unsigned int _a_high, unsigned int *x) | |
297 | { | |
298 | int i; | |
299 | char a[_a_high+1]; | |
300 | ||
301 | /* make a local copy of each unbounded array. */ | |
302 | memcpy (a, a_, _a_high+1); | |
303 | ||
304 | NumberIO_StrToHexInt ((const char *) a, _a_high, &i); | |
305 | (*x) = (unsigned int ) (i); | |
306 | } | |
307 | ||
308 | extern "C" void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high) | |
309 | { | |
310 | typedef struct IntToStr__T9_a IntToStr__T9; | |
311 | ||
312 | struct IntToStr__T9_a { unsigned int array[MaxDigits-1+1]; }; | |
313 | unsigned int i; | |
314 | unsigned int j; | |
315 | unsigned int c; | |
316 | unsigned int Higha; | |
317 | IntToStr__T9 buf; | |
318 | unsigned int Negative; | |
319 | ||
320 | if (x < 0) | |
321 | { | |
322 | /* avoid dangling else. */ | |
323 | Negative = TRUE; | |
324 | c = ((unsigned int ) (abs (x+1)))+1; | |
325 | if (n > 0) | |
326 | { | |
327 | n -= 1; | |
328 | } | |
329 | } | |
330 | else | |
331 | { | |
332 | c = x; | |
333 | Negative = FALSE; | |
334 | } | |
335 | i = 0; | |
336 | do { | |
337 | i += 1; | |
338 | if (i > MaxDigits) | |
339 | { | |
340 | StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29); | |
341 | StrIO_WriteLn (); | |
342 | M2RTS_HALT (-1); | |
343 | __builtin_unreachable (); | |
344 | } | |
345 | buf.array[i-1] = c % 10; | |
346 | c = c / 10; | |
347 | } while (! (c == 0)); | |
348 | j = 0; | |
349 | Higha = _a_high; | |
350 | while ((n > i) && (j <= Higha)) | |
351 | { | |
352 | a[j] = ' '; | |
353 | j += 1; | |
354 | n -= 1; | |
355 | } | |
356 | if (Negative) | |
357 | { | |
358 | a[j] = '-'; | |
359 | j += 1; | |
360 | } | |
361 | while ((i != 0) && (j <= Higha)) | |
362 | { | |
363 | a[j] = ((char) (buf.array[i-1]+ ((unsigned int) ('0')))); | |
364 | j += 1; | |
365 | i -= 1; | |
366 | } | |
367 | if (j <= Higha) | |
368 | { | |
369 | a[j] = ASCII_nul; | |
370 | } | |
371 | } | |
372 | ||
373 | extern "C" void NumberIO_StrToInt (const char *a_, unsigned int _a_high, int *x) | |
374 | { | |
375 | unsigned int i; | |
376 | unsigned int ok; | |
377 | unsigned int Negative; | |
378 | unsigned int higha; | |
379 | char a[_a_high+1]; | |
380 | ||
381 | /* make a local copy of each unbounded array. */ | |
382 | memcpy (a, a_, _a_high+1); | |
383 | ||
384 | StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high); | |
385 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
386 | i = 0; | |
387 | Negative = FALSE; | |
388 | ok = TRUE; | |
389 | while (ok) | |
390 | { | |
391 | if (i < higha) | |
392 | { | |
393 | if (a[i] == '-') | |
394 | { | |
395 | i += 1; | |
396 | Negative = ! Negative; | |
397 | } | |
398 | else if ((a[i] < '0') || (a[i] > '9')) | |
399 | { | |
400 | /* avoid dangling else. */ | |
401 | i += 1; | |
402 | } | |
403 | else | |
404 | { | |
405 | /* avoid dangling else. */ | |
406 | ok = FALSE; | |
407 | } | |
408 | } | |
409 | else | |
410 | { | |
411 | ok = FALSE; | |
412 | } | |
413 | } | |
414 | (*x) = 0; | |
415 | if (i < higha) | |
416 | { | |
417 | ok = TRUE; | |
418 | do { | |
419 | if (Negative) | |
420 | { | |
421 | (*x) = (10*(*x))-((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))); | |
422 | } | |
423 | else | |
424 | { | |
425 | (*x) = (10*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))); | |
426 | } | |
427 | if (i < higha) | |
428 | { | |
429 | /* avoid dangling else. */ | |
430 | i += 1; | |
431 | if ((a[i] < '0') || (a[i] > '9')) | |
432 | { | |
433 | ok = FALSE; | |
434 | } | |
435 | } | |
436 | else | |
437 | { | |
438 | ok = FALSE; | |
439 | } | |
440 | } while (! (! ok)); | |
441 | } | |
442 | } | |
443 | ||
444 | extern "C" void NumberIO_ReadOct (unsigned int *x) | |
445 | { | |
446 | typedef struct ReadOct__T10_a ReadOct__T10; | |
447 | ||
448 | struct ReadOct__T10_a { char array[MaxLineLength+1]; }; | |
449 | ReadOct__T10 a; | |
450 | ||
451 | StrIO_ReadString ((char *) &a.array[0], MaxLineLength); | |
452 | NumberIO_StrToOct ((const char *) &a.array[0], MaxLineLength, x); | |
453 | } | |
454 | ||
455 | extern "C" void NumberIO_WriteOct (unsigned int x, unsigned int n) | |
456 | { | |
457 | typedef struct WriteOct__T11_a WriteOct__T11; | |
458 | ||
459 | struct WriteOct__T11_a { char array[MaxLineLength+1]; }; | |
460 | WriteOct__T11 a; | |
461 | ||
462 | NumberIO_OctToStr (x, n, (char *) &a.array[0], MaxLineLength); | |
463 | StrIO_WriteString ((const char *) &a.array[0], MaxLineLength); | |
464 | } | |
465 | ||
466 | extern "C" void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high) | |
467 | { | |
468 | typedef struct OctToStr__T12_a OctToStr__T12; | |
469 | ||
470 | struct OctToStr__T12_a { unsigned int array[MaxOctDigits-1+1]; }; | |
471 | unsigned int i; | |
472 | unsigned int j; | |
473 | unsigned int Higha; | |
474 | OctToStr__T12 buf; | |
475 | ||
476 | i = 0; | |
477 | do { | |
478 | i += 1; | |
479 | if (i > MaxOctDigits) | |
480 | { | |
481 | StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29); | |
482 | StrIO_WriteLn (); | |
483 | M2RTS_HALT (-1); | |
484 | __builtin_unreachable (); | |
485 | } | |
486 | buf.array[i-1] = x % 8; | |
487 | x = x / 8; | |
488 | } while (! (x == 0)); | |
489 | j = 0; | |
490 | Higha = _a_high; | |
491 | while ((n > i) && (j <= Higha)) | |
492 | { | |
493 | a[j] = ' '; | |
494 | j += 1; | |
495 | n -= 1; | |
496 | } | |
497 | while ((i > 0) && (j <= Higha)) | |
498 | { | |
499 | a[j] = ((char) (buf.array[i-1]+ ((unsigned int) ('0')))); | |
500 | j += 1; | |
501 | i -= 1; | |
502 | } | |
503 | if (j <= Higha) | |
504 | { | |
505 | a[j] = ASCII_nul; | |
506 | } | |
507 | } | |
508 | ||
509 | extern "C" void NumberIO_StrToOct (const char *a_, unsigned int _a_high, unsigned int *x) | |
510 | { | |
511 | int i; | |
512 | char a[_a_high+1]; | |
513 | ||
514 | /* make a local copy of each unbounded array. */ | |
515 | memcpy (a, a_, _a_high+1); | |
516 | ||
517 | NumberIO_StrToOctInt ((const char *) a, _a_high, &i); | |
518 | (*x) = (unsigned int ) (i); | |
519 | } | |
520 | ||
521 | extern "C" void NumberIO_ReadBin (unsigned int *x) | |
522 | { | |
523 | typedef struct ReadBin__T13_a ReadBin__T13; | |
524 | ||
525 | struct ReadBin__T13_a { char array[MaxLineLength+1]; }; | |
526 | ReadBin__T13 a; | |
527 | ||
528 | StrIO_ReadString ((char *) &a.array[0], MaxLineLength); | |
529 | NumberIO_StrToBin ((const char *) &a.array[0], MaxLineLength, x); | |
530 | } | |
531 | ||
532 | extern "C" void NumberIO_WriteBin (unsigned int x, unsigned int n) | |
533 | { | |
534 | typedef struct WriteBin__T14_a WriteBin__T14; | |
535 | ||
536 | struct WriteBin__T14_a { char array[MaxLineLength+1]; }; | |
537 | WriteBin__T14 a; | |
538 | ||
539 | NumberIO_BinToStr (x, n, (char *) &a.array[0], MaxLineLength); | |
540 | StrIO_WriteString ((const char *) &a.array[0], MaxLineLength); | |
541 | } | |
542 | ||
543 | extern "C" void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high) | |
544 | { | |
545 | typedef struct BinToStr__T15_a BinToStr__T15; | |
546 | ||
547 | struct BinToStr__T15_a { unsigned int array[MaxBits-1+1]; }; | |
548 | unsigned int i; | |
549 | unsigned int j; | |
550 | unsigned int Higha; | |
551 | BinToStr__T15 buf; | |
552 | ||
553 | i = 0; | |
554 | do { | |
555 | i += 1; | |
556 | if (i > MaxBits) | |
557 | { | |
558 | StrIO_WriteString ((const char *) "NumberIO - increase MaxBits", 27); | |
559 | StrIO_WriteLn (); | |
560 | M2RTS_HALT (-1); | |
561 | __builtin_unreachable (); | |
562 | } | |
563 | buf.array[i-1] = x % 2; | |
564 | x = x / 2; | |
565 | } while (! (x == 0)); | |
566 | j = 0; | |
567 | Higha = _a_high; | |
568 | while ((n > i) && (j <= Higha)) | |
569 | { | |
570 | a[j] = ' '; | |
571 | j += 1; | |
572 | n -= 1; | |
573 | } | |
574 | while ((i > 0) && (j <= Higha)) | |
575 | { | |
576 | a[j] = ((char) (buf.array[i-1]+ ((unsigned int) ('0')))); | |
577 | j += 1; | |
578 | i -= 1; | |
579 | } | |
580 | if (j <= Higha) | |
581 | { | |
582 | a[j] = ASCII_nul; | |
583 | } | |
584 | } | |
585 | ||
586 | extern "C" void NumberIO_StrToBin (const char *a_, unsigned int _a_high, unsigned int *x) | |
587 | { | |
588 | int i; | |
589 | char a[_a_high+1]; | |
590 | ||
591 | /* make a local copy of each unbounded array. */ | |
592 | memcpy (a, a_, _a_high+1); | |
593 | ||
594 | NumberIO_StrToBinInt ((const char *) a, _a_high, &i); | |
595 | (*x) = (unsigned int ) (i); | |
596 | } | |
597 | ||
598 | extern "C" void NumberIO_StrToBinInt (const char *a_, unsigned int _a_high, int *x) | |
599 | { | |
600 | unsigned int i; | |
601 | unsigned int ok; | |
602 | unsigned int higha; | |
603 | char a[_a_high+1]; | |
604 | ||
605 | /* make a local copy of each unbounded array. */ | |
606 | memcpy (a, a_, _a_high+1); | |
607 | ||
608 | StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high); | |
609 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
610 | i = 0; | |
611 | ok = TRUE; | |
612 | while (ok) | |
613 | { | |
614 | if (i < higha) | |
615 | { | |
616 | if ((a[i] < '0') || (a[i] > '1')) | |
617 | { | |
618 | i += 1; | |
619 | } | |
620 | else | |
621 | { | |
622 | ok = FALSE; | |
623 | } | |
624 | } | |
625 | else | |
626 | { | |
627 | ok = FALSE; | |
628 | } | |
629 | } | |
630 | (*x) = 0; | |
631 | if (i < higha) | |
632 | { | |
633 | ok = TRUE; | |
634 | do { | |
635 | (*x) = (2*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))); | |
636 | if (i < higha) | |
637 | { | |
638 | /* avoid dangling else. */ | |
639 | i += 1; | |
640 | if ((a[i] < '0') || (a[i] > '1')) | |
641 | { | |
642 | ok = FALSE; | |
643 | } | |
644 | } | |
645 | else | |
646 | { | |
647 | ok = FALSE; | |
648 | } | |
649 | } while (! (! ok)); | |
650 | } | |
651 | } | |
652 | ||
653 | extern "C" void NumberIO_StrToHexInt (const char *a_, unsigned int _a_high, int *x) | |
654 | { | |
655 | unsigned int i; | |
656 | unsigned int ok; | |
657 | unsigned int higha; | |
658 | char a[_a_high+1]; | |
659 | ||
660 | /* make a local copy of each unbounded array. */ | |
661 | memcpy (a, a_, _a_high+1); | |
662 | ||
663 | StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high); | |
664 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
665 | i = 0; | |
666 | ok = TRUE; | |
667 | while (ok) | |
668 | { | |
669 | if (i < higha) | |
670 | { | |
671 | if (((a[i] >= '0') && (a[i] <= '9')) || ((a[i] >= 'A') && (a[i] <= 'F'))) | |
672 | { | |
673 | ok = FALSE; | |
674 | } | |
675 | else | |
676 | { | |
677 | i += 1; | |
678 | } | |
679 | } | |
680 | else | |
681 | { | |
682 | ok = FALSE; | |
683 | } | |
684 | } | |
685 | (*x) = 0; | |
686 | if (i < higha) | |
687 | { | |
688 | ok = TRUE; | |
689 | do { | |
690 | if ((a[i] >= '0') && (a[i] <= '9')) | |
691 | { | |
692 | (*x) = (0x010*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))); | |
693 | } | |
694 | else if ((a[i] >= 'A') && (a[i] <= 'F')) | |
695 | { | |
696 | /* avoid dangling else. */ | |
697 | (*x) = (0x010*(*x))+((int ) (( ((unsigned int) (a[i]))- ((unsigned int) ('A')))+10)); | |
698 | } | |
699 | if (i < higha) | |
700 | { | |
701 | /* avoid dangling else. */ | |
702 | i += 1; | |
703 | if (((a[i] < '0') || (a[i] > '9')) && ((a[i] < 'A') || (a[i] > 'F'))) | |
704 | { | |
705 | ok = FALSE; | |
706 | } | |
707 | } | |
708 | else | |
709 | { | |
710 | ok = FALSE; | |
711 | } | |
712 | } while (! (! ok)); | |
713 | } | |
714 | } | |
715 | ||
716 | extern "C" void NumberIO_StrToOctInt (const char *a_, unsigned int _a_high, int *x) | |
717 | { | |
718 | unsigned int i; | |
719 | unsigned int ok; | |
720 | unsigned int higha; | |
721 | char a[_a_high+1]; | |
722 | ||
723 | /* make a local copy of each unbounded array. */ | |
724 | memcpy (a, a_, _a_high+1); | |
725 | ||
726 | StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high); | |
727 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
728 | i = 0; | |
729 | ok = TRUE; | |
730 | while (ok) | |
731 | { | |
732 | if (i < higha) | |
733 | { | |
734 | if ((a[i] < '0') || (a[i] > '7')) | |
735 | { | |
736 | i += 1; | |
737 | } | |
738 | else | |
739 | { | |
740 | ok = FALSE; | |
741 | } | |
742 | } | |
743 | else | |
744 | { | |
745 | ok = FALSE; | |
746 | } | |
747 | } | |
748 | (*x) = 0; | |
749 | if (i < higha) | |
750 | { | |
751 | ok = TRUE; | |
752 | do { | |
753 | (*x) = (8*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))); | |
754 | if (i < higha) | |
755 | { | |
756 | /* avoid dangling else. */ | |
757 | i += 1; | |
758 | if ((a[i] < '0') || (a[i] > '7')) | |
759 | { | |
760 | ok = FALSE; | |
761 | } | |
762 | } | |
763 | else | |
764 | { | |
765 | ok = FALSE; | |
766 | } | |
767 | } while (! (! ok)); | |
768 | } | |
769 | } | |
770 | ||
771 | extern "C" void _M2_NumberIO_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[]) | |
772 | { | |
773 | } | |
774 | ||
775 | extern "C" void _M2_NumberIO_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[]) | |
776 | { | |
777 | } |