Print this page
10097 indenting fixes in usr/src/{lib,common}
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libmp/common/mout.c
+++ new/usr/src/lib/libmp/common/mout.c
1 1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 2 /* All Rights Reserved */
3 3
4 4
5 5 /*
6 6 * Copyright (c) 1980 Regents of the University of California.
7 7 * All rights reserved. The Berkeley software License Agreement
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
8 8 * specifies the terms and conditions for redistribution.
9 9 */
10 10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 11 /* All Rights Reserved */
12 12
13 13 /*
14 14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 15 * All rights reserved.
16 16 */
17 17
18 -#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
18 +/*
19 + * Copyright (c) 2018, Joyent, Inc.
20 + */
19 21
20 22 /* LINTLIBRARY */
21 23
22 24 #include <stdio.h>
23 25 #include <mp.h>
24 26 #include <sys/types.h>
25 27 #include "libmp.h"
26 28 #include <stdlib.h>
27 29
28 30 static int
29 31 m_in(MINT *a, short b, FILE *f)
30 32 {
31 33 MINT x, y, ten;
32 34 int sign, c;
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
33 35 short qten, qy;
34 36
35 37 _mp_xfree(a);
36 38 sign = 1;
37 39 ten.len = 1;
38 40 ten.val = &qten;
39 41 qten = b;
40 42 x.len = 0;
41 43 y.len = 1;
42 44 y.val = &qy;
43 - while ((c = getc(f)) != EOF)
44 - switch (c) {
45 + while ((c = getc(f)) != EOF) {
46 + switch (c) {
45 47
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);
48 + case '\\':
49 + (void) getc(f);
65 50 continue;
66 - } else {
67 - (void) ungetc(c, stdin);
51 + case '\t':
52 + case '\n':
68 53 a->len *= sign;
54 + _mp_xfree(&x);
69 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 + }
70 73 }
71 74 }
75 +
72 76 return (EOF);
73 77 }
74 78
75 79 static void
76 80 m_out(MINT *a, short b, FILE *f)
77 81 {
78 82 int sign, xlen, i;
79 83 short r;
80 84 MINT x;
81 85
82 86 char *obuf;
83 87 char *bp;
84 88
85 89 if (a == NULL)
86 90 return;
87 91 sign = 1;
88 92 xlen = a->len;
89 93 if (xlen < 0) {
90 94 xlen = -xlen;
91 95 sign = -1;
92 96 }
93 97 if (xlen == 0) {
94 98 (void) fprintf(f, "0\n");
95 99 return;
96 100 }
97 101 x.len = xlen;
98 102 x.val = _mp_xalloc(xlen, "m_out");
99 103 for (i = 0; i < xlen; i++)
100 104 x.val[i] = a->val[i];
101 105 obuf = malloc(7 * (size_t)xlen);
102 106 bp = obuf + 7 * xlen - 1;
103 107 *bp-- = 0;
104 108 while (x.len > 0) {
105 109 for (i = 0; i < 10 && x.len > 0; i++) {
106 110 mp_sdiv(&x, b, &x, &r);
107 111 *bp-- = (char)(r + '0');
108 112 }
109 113 if (x.len > 0)
110 114 *bp-- = ' ';
111 115 }
112 116 if (sign == -1)
113 117 *bp-- = '-';
114 118 (void) fprintf(f, "%s\n", bp + 1);
115 119 free(obuf);
116 120 _mp_xfree(&x);
117 121 }
118 122
119 123 static void s_div(MINT *, short, MINT *, short *);
120 124
121 125 void
122 126 mp_sdiv(MINT *a, short n, MINT *q, short *r)
123 127 {
124 128 MINT x, y;
125 129 short sign;
126 130
127 131 sign = 1;
128 132 x.len = a->len;
129 133 x.val = a->val;
130 134 if (n < 0) {
131 135 sign = -sign;
132 136 n = -n;
133 137 }
134 138 if (x.len < 0) {
135 139 sign = -sign;
136 140 x.len = -x.len;
137 141 }
138 142 s_div(&x, n, &y, r);
139 143 _mp_xfree(q);
140 144 q->val = y.val;
141 145 q->len = sign * y.len;
142 146 *r = *r * sign;
143 147 }
144 148
145 149 static void
146 150 s_div(MINT *a, short n, MINT *q, short *r)
147 151 {
148 152 int qlen;
149 153 int i;
150 154 int x;
151 155 short *qval;
152 156 short *aval;
153 157
154 158 x = 0;
155 159 qlen = a->len;
156 160 q->val = _mp_xalloc(qlen, "s_div");
157 161 aval = a->val + qlen;
158 162 qval = q->val + qlen;
159 163 for (i = qlen - 1; i >= 0; i--) {
160 164 x = x * 0100000 + *--aval;
161 165 *--qval = (short)(x / n);
162 166 x = x % n;
163 167 }
164 168 *r = (short)x;
165 169 if (qlen && q->val[qlen-1] == 0)
166 170 qlen--;
167 171 q->len = qlen;
168 172 if (qlen == 0)
169 173 free(q->val);
170 174 }
171 175
172 176 int
173 177 mp_min(MINT *a)
174 178 {
175 179 return (m_in(a, 10, stdin));
176 180 }
177 181
178 182 int
179 183 mp_omin(MINT *a)
180 184 {
181 185 return (m_in(a, 8, stdin));
182 186 }
183 187
184 188 void
185 189 mp_mout(MINT *a)
186 190 {
187 191 m_out(a, 10, stdout);
188 192 }
189 193
190 194 void
191 195 mp_omout(MINT *a)
192 196 {
193 197 m_out(a, 8, stdout);
194 198 }
195 199
196 200 void
197 201 mp_fmout(MINT *a, FILE *f)
198 202 {
199 203 m_out(a, 10, f);
200 204 }
201 205
202 206 int
203 207 mp_fmin(MINT *a, FILE *f)
204 208 {
205 209 return (m_in(a, 10, f));
206 210 }
↓ open down ↓ |
125 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX