1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
3
4
5 /*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 /* All Rights Reserved */
12
13 /*
14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 * All rights reserved.
16 */
17
18 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
19
20 /* LINTLIBRARY */
21
22 #include <stdio.h>
23 #include <mp.h>
24 #include <sys/types.h>
25 #include "libmp.h"
26 #include <stdlib.h>
27
28 static int
29 m_in(MINT *a, short b, FILE *f)
30 {
31 MINT x, y, ten;
32 int sign, c;
33 short qten, qy;
34
35 _mp_xfree(a);
36 sign = 1;
37 ten.len = 1;
38 ten.val = &qten;
39 qten = b;
40 x.len = 0;
41 y.len = 1;
42 y.val = &qy;
43 while ((c = getc(f)) != EOF)
44 switch (c) {
45
46 case '\\':
47 (void) getc(f);
48 continue;
49 case '\t':
50 case '\n':
51 a->len *= sign;
52 _mp_xfree(&x);
53 return (0);
54 case ' ':
55 continue;
56 case '-':
57 sign = -sign;
58 continue;
59 default:
60 if (c >= '0' && c <= '9') {
61 qy = c - '0';
62 mp_mult(&x, &ten, a);
63 mp_madd(a, &y, a);
64 _mp_move(a, &x);
65 continue;
66 } else {
67 (void) ungetc(c, stdin);
68 a->len *= sign;
69 return (0);
70 }
71 }
72 return (EOF);
73 }
74
75 static void
76 m_out(MINT *a, short b, FILE *f)
77 {
78 int sign, xlen, i;
79 short r;
80 MINT x;
81
82 char *obuf;
83 char *bp;
84
85 if (a == NULL)
86 return;
87 sign = 1;
88 xlen = a->len;
89 if (xlen < 0) {
90 xlen = -xlen;
91 sign = -1;
|
1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
3
4
5 /*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 /* All Rights Reserved */
12
13 /*
14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 * All rights reserved.
16 */
17
18 /*
19 * Copyright (c) 2018, Joyent, Inc.
20 */
21
22 /* LINTLIBRARY */
23
24 #include <stdio.h>
25 #include <mp.h>
26 #include <sys/types.h>
27 #include "libmp.h"
28 #include <stdlib.h>
29
30 static int
31 m_in(MINT *a, short b, FILE *f)
32 {
33 MINT x, y, ten;
34 int sign, c;
35 short qten, qy;
36
37 _mp_xfree(a);
38 sign = 1;
39 ten.len = 1;
40 ten.val = &qten;
41 qten = b;
42 x.len = 0;
43 y.len = 1;
44 y.val = &qy;
45 while ((c = getc(f)) != EOF) {
46 switch (c) {
47
48 case '\\':
49 (void) getc(f);
50 continue;
51 case '\t':
52 case '\n':
53 a->len *= sign;
54 _mp_xfree(&x);
55 return (0);
56 case ' ':
57 continue;
58 case '-':
59 sign = -sign;
60 continue;
61 default:
62 if (c >= '0' && c <= '9') {
63 qy = c - '0';
64 mp_mult(&x, &ten, a);
65 mp_madd(a, &y, a);
66 _mp_move(a, &x);
67 continue;
68 } else {
69 (void) ungetc(c, stdin);
70 a->len *= sign;
71 return (0);
72 }
73 }
74 }
75
76 return (EOF);
77 }
78
79 static void
80 m_out(MINT *a, short b, FILE *f)
81 {
82 int sign, xlen, i;
83 short r;
84 MINT x;
85
86 char *obuf;
87 char *bp;
88
89 if (a == NULL)
90 return;
91 sign = 1;
92 xlen = a->len;
93 if (xlen < 0) {
94 xlen = -xlen;
95 sign = -1;
|