Print this page
10097 indenting fixes in usr/src/{lib,common}
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libeti/form/common/regex.c
+++ new/usr/src/lib/libeti/form/common/regex.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
21 21 */
22 22 /* Copyright (c) 1988 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 29 */
30 30
31 +/*
32 + * Copyright (c) 2018, Joyent, Inc.
33 + */
34 +
31 35 /*LINTLIBRARY*/
32 36
33 37 #include <sys/types.h>
34 38 #include <stdlib.h>
35 39 #include <unistd.h>
36 40 #include "utility.h"
37 41
38 42 /*
39 43 * this code was taken from REGCMP(3X)
40 44 */
41 45 /*VARARGS*/
42 46 /*ARGSUSED*/
43 47
44 48 #define SSIZE 50
45 49 #define TGRP 48
46 50 #define A256 01
47 51 #define A512 02
48 52 #define A768 03
49 53 #define NBRA 10
50 54 #define CIRCFL 32
51 55
52 56 #define CBRA 60
53 57 #define GRP 40
54 58 #define SGRP 56
55 59 #define PGRP 68
56 60 #define EGRP 44
57 61 #define RNGE 03
58 62 #define CCHR 20
59 63 #define CDOT 64
60 64 #define CCL 24
61 65 #define NCCL 8
62 66 #define CDOL 28
63 67 #define FCEOF 52 /* This was originally CEOF but it clashes with the header */
64 68 /* definition so it was changed to FCEOF */
65 69 #define CKET 12
66 70
67 71 #define STAR 01
68 72 #define PLUS 02
69 73 #define MINUS 16
70 74
71 75 char *__braslist[NBRA];
72 76 char *__braelist[NBRA];
73 77 char *__loc1;
74 78 intptr_t __bravar[NBRA];
75 79 intptr_t *__st[SSIZE + 1];
76 80 intptr_t *__eptr_, *__lptr_;
77 81 intptr_t __cflg;
78 82
79 83 char *
80 84 libform_regex(char *addrc, char *addrl, char *a1)
81 85 {
82 86 intptr_t cur, in;
83 87 intptr_t *adx;
84 88 char *p1, *p2;
85 89
86 90 for (in = 0; in < NBRA; in++) {
87 91 __braslist[in] = 0;
88 92 __bravar[in] = -1;
89 93 }
90 94 __cflg = 0;
91 95 cur = __execute(addrc, addrl);
92 96 adx = (intptr_t *)&a1;
93 97 for (in = 0; in < NBRA; in++) {
94 98 if (((p1 = __braslist[in]) != 0) && (__bravar[in] >= 0)) {
95 99 p2 = (char *)adx[__bravar[in]];
96 100 while (p1 < __braelist[in]) *p2++ = *p1++;
97 101 *p2 = '\0';
98 102 }
99 103 }
100 104 if (!__cflg)
101 105 return ((addrl == (char *)cur) ? (char *)0 : (char *)cur);
102 106 else
103 107 return ((char *)cur);
104 108 }
105 109
106 110 intptr_t
107 111 __execute(char *addrc, char *addrl)
108 112 {
109 113 char *p1, *p2, c;
110 114 intptr_t i;
111 115
112 116 p1 = addrl;
113 117 p2 = addrc;
114 118 __eptr_ = (intptr_t *)&__st[SSIZE];
115 119 __lptr_ = (intptr_t *)&__st[0];
116 120 if (*p2 == CIRCFL) {
117 121 __loc1 = p1;
118 122 return ((i = __advance(p1, ++p2)) ? i : (intptr_t)addrl);
119 123 }
120 124 /* fast check for first character */
121 125 if (*p2 == CCHR) {
122 126 c = p2[1];
123 127 do {
124 128 if (*p1 != c)
125 129 continue;
126 130 __eptr_ = (intptr_t *)&__st[SSIZE];
↓ open down ↓ |
86 lines elided |
↑ open up ↑ |
127 131 __lptr_ = (intptr_t *)&__st[0];
128 132 if (i = __advance(p1, p2)) {
129 133 __loc1 = p1;
130 134 return (i);
131 135 }
132 136 } while (*p1++);
133 137 return ((intptr_t)addrl);
134 138 }
135 139 /* regular algorithm */
136 140 do {
137 - __eptr_ = (intptr_t *)&__st[SSIZE];
138 - __lptr_ = (intptr_t *)&__st[0];
141 + __eptr_ = (intptr_t *)&__st[SSIZE];
142 + __lptr_ = (intptr_t *)&__st[0];
139 143 if (i = __advance(p1, p2)) {
140 144 __loc1 = p1;
141 145 return (i);
142 146 }
143 147 } while (*p1++);
144 148 return ((intptr_t)addrl);
145 149 }
146 150
147 151 intptr_t
148 152 __advance(char *alp, char *aep)
149 153 {
150 154 char *lp, *ep, *curlp;
151 155 char *sep, *dp;
152 156 intptr_t i, lcnt, dcnt, gflg;
153 157
154 158 lp = alp;
155 159 ep = aep;
156 160 gflg = 0;
157 161 for (; ; ) {
158 162 switch (*ep++) {
159 163
160 164 case CCHR:
161 165 if (*ep++ == *lp++)
162 166 continue;
163 167 return (0);
164 168
165 169 case EGRP|RNGE:
166 170 return ((intptr_t)lp);
167 171 case EGRP:
168 172 case GRP:
169 173 ep++;
170 174 continue;
171 175
172 176 case EGRP|STAR:
173 177 (void) __xpop(0);
174 178 /* FALLTHROUGH */
175 179 case EGRP|PLUS:
176 180 (void) __xpush(0, ++ep);
177 181 return ((intptr_t)lp);
178 182
179 183 case CDOT:
180 184 if (*lp++)
181 185 continue;
182 186 return (0);
183 187
184 188 case CDOL:
185 189 if (*lp == 0)
186 190 continue;
187 191 lp++;
188 192 return (0);
189 193
190 194 case FCEOF:
191 195 __cflg = 1;
192 196 return ((intptr_t)lp);
193 197
194 198 case TGRP:
195 199 case TGRP|A768:
196 200 case TGRP|A512:
197 201 case TGRP|A256:
198 202 i = (((ep[-1] & 03) << 8) + (*ep) & 0377);
199 203 ep++;
200 204 (void) __xpush(0, ep + i + 2);
201 205 (void) __xpush(0, ++ep);
202 206 (void) __xpush(0, ++ep);
203 207 gflg = 1;
204 208 (void) __getrnge(&lcnt, &dcnt, &ep[i]);
205 209 while (lcnt--)
206 210 if (!(lp = (char *)__advance(lp, ep)))
207 211 return (0);
208 212 (void) __xpush(1, curlp = lp);
209 213 while (dcnt--)
210 214 if (!(dp = (char *)__advance(lp, ep))) break;
211 215 else
212 216 (void) __xpush(1, lp = dp);
213 217 ep = (char *)__xpop(0);
214 218 goto star;
215 219 case CCHR|RNGE:
216 220 sep = ep++;
217 221 (void) __getrnge(&lcnt, &dcnt, ep);
218 222 while (lcnt--)
219 223 if (*lp++ != *sep)
220 224 return (0);
221 225 curlp = lp;
222 226 while (dcnt--)
223 227 if (*lp++ != *sep) break;
224 228 if (dcnt < 0) lp++;
225 229 ep += 2;
226 230 goto star;
227 231 case CDOT|RNGE:
228 232 (void) __getrnge(&lcnt, &dcnt, ep);
229 233 while (lcnt--)
230 234 if (*lp++ == '\0')
231 235 return (0);
232 236 curlp = lp;
233 237 while (dcnt--)
234 238 if (*lp++ == '\0') break;
235 239 if (dcnt < 0) lp++;
236 240 ep += 2;
237 241 goto star;
238 242 case CCL|RNGE:
239 243 case NCCL|RNGE:
240 244 (void) __getrnge(&lcnt, &dcnt, (ep + (*ep & 0377)));
241 245 while (lcnt--)
242 246 if (!__cclass(ep, *lp++, ep[-1] == (CCL | RNGE)))
243 247 return (0);
244 248 curlp = lp;
245 249 while (dcnt--)
246 250 if (!__cclass(ep, *lp++, ep[-1] == (CCL|RNGE)))
247 251 break;
248 252 if (dcnt < 0) lp++;
249 253 ep += (*ep + 2);
250 254 goto star;
251 255 case CCL:
252 256 if (__cclass(ep, *lp++, 1)) {
253 257 ep += *ep;
254 258 continue;
255 259 }
256 260 return (0);
257 261
258 262 case NCCL:
259 263 if (__cclass(ep, *lp++, 0)) {
260 264 ep += *ep;
261 265 continue;
262 266 }
263 267 return (0);
264 268
265 269 case CBRA:
266 270 __braslist[*ep++] = lp;
267 271 continue;
268 272
269 273 case CKET:
270 274 __braelist[*ep] = lp;
271 275 __bravar[*ep] = ep[1];
272 276 ep += 2;
273 277 continue;
274 278
275 279 case CDOT|PLUS:
276 280 if (*lp++ == '\0')
277 281 return (0);
278 282 /* FALLTHROUGH */
279 283 case CDOT|STAR:
280 284 curlp = lp;
281 285 while (*lp++)
282 286 ;
283 287 goto star;
284 288
285 289 case CCHR|PLUS:
286 290 if (*lp++ != *ep)
287 291 return (0);
288 292 /* FALLTHROUGH */
289 293 case CCHR|STAR:
290 294 curlp = lp;
291 295 while (*lp++ == *ep)
292 296 ;
293 297 ep++;
294 298 goto star;
295 299
296 300 case PGRP:
297 301 case PGRP|A256:
298 302 case PGRP|A512:
299 303 case PGRP|A768:
300 304 if (!(lp = (char *)__advance(lp, ep+1)))
301 305 return (0);
302 306 /* FALLTHROUGH */
303 307 case SGRP|A768:
304 308 case SGRP|A512:
305 309 case SGRP|A256:
306 310 case SGRP:
307 311 i = (((ep[-1]&03) << 8) + (*ep & 0377));
308 312 ep++;
309 313 (void) __xpush(0, ep + i);
310 314 (void) __xpush(1, curlp = lp);
311 315 while (i = __advance(lp, ep))
312 316 (void) __xpush(1, lp = (char *)i);
313 317 ep = (char *)__xpop(0);
314 318 gflg = 1;
315 319 goto star;
316 320
317 321 case CCL|PLUS:
318 322 case NCCL|PLUS:
319 323 if (!__cclass(ep, *lp++, ep[-1] == (CCL | PLUS)))
320 324 return (0);
321 325 /* FALLTHROUGH */
322 326 case CCL|STAR:
323 327 case NCCL|STAR:
324 328 curlp = lp;
325 329 while (__cclass(ep, *lp++, ((ep[-1] == (CCL | STAR)) ||
326 330 (ep[-1] == (CCL | PLUS)))))
327 331 ;
328 332 ep += *ep;
329 333 goto star;
330 334
331 335 star:
332 336 do {
333 337 if (!gflg) lp--;
334 338 else if (!(lp = (char *)__xpop(1))) break;
335 339 if (i = __advance(lp, ep))
336 340 return (i);
337 341 } while (lp > curlp);
338 342 return (0);
339 343
340 344 default:
341 345 return (0);
342 346 }
343 347 }
344 348 }
345 349
346 350 intptr_t
347 351 __cclass(char *aset, char ac, intptr_t af)
348 352 {
349 353 char *set, c;
350 354 intptr_t n;
351 355
352 356 set = (char *)aset;
353 357 if ((c = ac) == 0)
354 358 return (0);
355 359 n = *set++;
356 360 while (--n) {
357 361 if (*set == MINUS) {
358 362 if ((set[2] - set[1]) < 0)
359 363 return (0);
360 364 if (*++set <= c) {
361 365 if (c <= *++set)
362 366 return (af);
363 367 } else
364 368 ++set;
365 369 ++set;
366 370 n -= 2;
367 371 continue;
368 372 }
369 373 if (*set++ == c)
370 374 return (af);
371 375 }
372 376 return (!af);
373 377 }
374 378
375 379 intptr_t
376 380 __xpush(intptr_t i, char *p)
377 381 {
378 382 if (__lptr_ >= __eptr_) {
379 383 (void) write(2, "stack overflow\n", 15);
380 384 (void) exit(1);
381 385 }
382 386 if (i)
383 387 *__lptr_++ = (intptr_t)p;
384 388 else
385 389 *__eptr_-- = (intptr_t)p;
386 390 return (1);
387 391 }
388 392
389 393 intptr_t
390 394 __xpop(intptr_t i)
391 395 {
392 396 if (i)
393 397 return ((__lptr_ < (intptr_t *)&__st[0]) ? 0 : *--__lptr_);
394 398 else
395 399 return ((__eptr_ > (intptr_t *)&__st[SSIZE]) ? 0 : *++__eptr_);
396 400 }
397 401
398 402 intptr_t
399 403 __getrnge(intptr_t *i, intptr_t *j, char *k)
400 404 {
401 405 *i = (*k++&0377);
402 406 if (*k == (char)-1)
403 407 *j = 20000;
404 408 else
405 409 *j = ((*k&0377) - *i);
406 410 return (1);
407 411 }
↓ open down ↓ |
259 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX