Print this page
remove support for non-ANSI compilation
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/head/regexp.h
+++ new/usr/src/head/regexp.h
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 (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /* Copyright (c) 1988 AT&T */
22 22 /* All Rights Reserved */
23 23
24 -
25 24 /*
25 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
26 + *
26 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 28 * Use is subject to license terms.
28 29 */
29 30
30 31 #ifndef _REGEXP_H
31 32 #define _REGEXP_H
32 33
33 -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
34 -
35 34 #include <string.h>
36 35
37 36 #ifdef __cplusplus
38 37 extern "C" {
39 38 #endif
40 39
41 40 #define CBRA 2
42 41 #define CCHR 4
43 42 #define CDOT 8
44 43 #define CCL 12
45 44 #define CXCL 16
46 45 #define CDOL 20
47 46 #define CCEOF 22
48 47 #define CKET 24
49 48 #define CBACK 36
50 49 #define NCCL 40
51 50
52 51 #define STAR 01
53 52 #define RNGE 03
54 53
55 54 #define NBRA 9
56 55
57 56 #define PLACE(c) ep[c >> 3] |= bittab[c & 07]
58 57 #define ISTHERE(c) (ep[c >> 3] & bittab[c & 07])
59 58 #define ecmp(s1, s2, n) (strncmp(s1, s2, n) == 0)
60 59
61 60 static char *braslist[NBRA];
62 61 static char *braelist[NBRA];
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
63 62 int sed, nbra;
64 63 char *loc1, *loc2, *locs;
65 64 static int nodelim;
66 65
67 66 int circf;
68 67 static int low;
69 68 static int size;
70 69
71 70 static unsigned char bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
72 71
73 -#ifdef __STDC__
74 72 int advance(const char *lp, const char *ep);
75 73 static void getrnge(const char *str);
76 -#else
77 -int advance();
78 -static void getrnge();
79 -#endif
80 74
81 75 char *
82 -#ifdef __STDC__
83 76 compile(char *instring, char *ep, const char *endbuf, int seof)
84 -#else
85 -compile(instring, ep, endbuf, seof)
86 -register char *ep;
87 -char *instring, *endbuf;
88 -int seof;
89 -#endif
90 77 {
91 78 INIT /* Dependent declarations and initializations */
92 79 register int c;
93 80 register int eof = seof;
94 81 char *lastep;
95 82 int cclcnt;
96 83 char bracket[NBRA], *bracketp;
97 84 int closed;
98 85 int neg;
99 86 int lc;
100 87 int i, cflg;
101 88 int iflag; /* used for non-ascii characters in brackets */
102 89
103 90 #ifdef __lint
104 91 /* make lint happy */
105 92 c = nodelim;
106 93 #endif
107 94
108 95 lastep = NULL;
109 96 if ((c = GETC()) == eof || c == '\n') {
110 97 if (c == '\n') {
111 98 UNGETC(c);
112 99 nodelim = 1;
113 100 }
114 101 if (*ep == 0 && !sed)
115 102 ERROR(41);
116 103 RETURN(ep);
117 104 }
118 105 bracketp = bracket;
119 106 circf = closed = nbra = 0;
120 107 if (c == '^')
121 108 circf++;
122 109 else
123 110 UNGETC(c);
124 111 for (;;) {
125 112 if (ep >= endbuf)
126 113 ERROR(50);
127 114 c = GETC();
128 115 if (c != '*' && ((c != '\\') || (PEEKC() != '{')))
129 116 lastep = ep;
130 117 if (c == eof) {
131 118 *ep++ = CCEOF;
132 119 if (bracketp != bracket)
133 120 ERROR(42);
134 121 RETURN(ep);
135 122 }
136 123 switch (c) {
137 124
138 125 case '.':
139 126 *ep++ = CDOT;
140 127 continue;
141 128
142 129 case '\n':
143 130 if (!sed) {
144 131 UNGETC(c);
145 132 *ep++ = CCEOF;
146 133 nodelim = 1;
147 134 if (bracketp != bracket)
148 135 ERROR(42);
149 136 RETURN(ep);
150 137 } else ERROR(36);
151 138 case '*':
152 139 if (lastep == NULL || *lastep == CBRA ||
153 140 *lastep == CKET)
154 141 goto defchar;
155 142 *lastep |= STAR;
156 143 continue;
157 144
158 145 case '$':
159 146 if (PEEKC() != eof && PEEKC() != '\n')
160 147 goto defchar;
161 148 *ep++ = CDOL;
162 149 continue;
163 150
164 151 case '[':
165 152 if (&ep[17] >= endbuf)
166 153 ERROR(50);
167 154
168 155 *ep++ = CCL;
169 156 lc = 0;
170 157 for (i = 0; i < 16; i++)
171 158 ep[i] = 0;
172 159
173 160 neg = 0;
174 161 if ((c = GETC()) == '^') {
175 162 neg = 1;
176 163 c = GETC();
177 164 }
178 165 iflag = 1;
179 166 do {
180 167 c &= 0377;
181 168 if (c == '\0' || c == '\n')
182 169 ERROR(49);
183 170 if ((c & 0200) && iflag) {
184 171 iflag = 0;
185 172 if (&ep[32] >= endbuf)
186 173 ERROR(50);
187 174 ep[-1] = CXCL;
188 175 for (i = 16; i < 32; i++)
189 176 ep[i] = 0;
190 177 }
191 178 if (c == '-' && lc != 0) {
192 179 if ((c = GETC()) == ']') {
193 180 PLACE('-');
194 181 break;
195 182 }
196 183 if ((c & 0200) && iflag) {
197 184 iflag = 0;
198 185 if (&ep[32] >= endbuf)
199 186 ERROR(50);
200 187 ep[-1] = CXCL;
201 188 for (i = 16; i < 32; i++)
202 189 ep[i] = 0;
203 190 }
204 191 while (lc < c) {
205 192 PLACE(lc);
206 193 lc++;
207 194 }
208 195 }
209 196 lc = c;
210 197 PLACE(c);
211 198 } while ((c = GETC()) != ']');
212 199
213 200 if (iflag)
214 201 iflag = 16;
215 202 else
216 203 iflag = 32;
217 204
218 205 if (neg) {
219 206 if (iflag == 32) {
220 207 for (cclcnt = 0; cclcnt < iflag;
221 208 cclcnt++)
222 209 ep[cclcnt] ^= 0377;
223 210 ep[0] &= 0376;
224 211 } else {
225 212 ep[-1] = NCCL;
226 213 /* make nulls match so test fails */
227 214 ep[0] |= 01;
228 215 }
229 216 }
230 217
231 218 ep += iflag;
232 219
233 220 continue;
234 221
235 222 case '\\':
236 223 switch (c = GETC()) {
237 224
238 225 case '(':
239 226 if (nbra >= NBRA)
240 227 ERROR(43);
241 228 *bracketp++ = (char)nbra;
242 229 *ep++ = CBRA;
243 230 *ep++ = (char)nbra++;
244 231 continue;
245 232
246 233 case ')':
247 234 if (bracketp <= bracket)
248 235 ERROR(42);
249 236 *ep++ = CKET;
250 237 *ep++ = *--bracketp;
251 238 closed++;
252 239 continue;
253 240
254 241 case '{':
255 242 if (lastep == NULL)
256 243 goto defchar;
257 244 *lastep |= RNGE;
258 245 cflg = 0;
259 246 nlim:
260 247 c = GETC();
261 248 i = 0;
262 249 do {
263 250 if ('0' <= c && c <= '9')
264 251 i = 10 * i + c - '0';
265 252 else
266 253 ERROR(16);
267 254 } while (((c = GETC()) != '\\') && (c != ','));
268 255 if (i >= 255)
269 256 ERROR(11);
270 257 *ep++ = (char)i;
271 258 if (c == ',') {
272 259 if (cflg++)
273 260 ERROR(44);
274 261 if ((c = GETC()) == '\\')
275 262 *ep++ = (char)255;
276 263 else {
277 264 UNGETC(c);
278 265 goto nlim;
279 266 /* get 2'nd number */
280 267 }
281 268 }
282 269 if (GETC() != '}')
283 270 ERROR(45);
284 271 if (!cflg) /* one number */
285 272 *ep++ = (char)i;
286 273 else if ((ep[-1] & 0377) < (ep[-2] & 0377))
287 274 ERROR(46);
288 275 continue;
289 276
290 277 case '\n':
291 278 ERROR(36);
292 279
293 280 case 'n':
294 281 c = '\n';
295 282 goto defchar;
296 283
297 284 default:
298 285 if (c >= '1' && c <= '9') {
299 286 if ((c -= '1') >= closed)
300 287 ERROR(25);
301 288 *ep++ = CBACK;
302 289 *ep++ = (char)c;
303 290 continue;
304 291 }
305 292 }
306 293 /* Drop through to default to use \ to turn off special chars */
307 294
↓ open down ↓ |
208 lines elided |
↑ open up ↑ |
308 295 defchar:
309 296 default:
310 297 lastep = ep;
311 298 *ep++ = CCHR;
312 299 *ep++ = (char)c;
313 300 }
314 301 }
315 302 /*NOTREACHED*/
316 303 }
317 304
318 -#ifdef __STDC__
319 305 int
320 306 step(const char *p1, const char *p2)
321 -#else
322 -int
323 -step(p1, p2)
324 -register char *p1, *p2;
325 -#endif
326 307 {
327 308 char c;
328 309
329 310
330 311 if (circf) {
331 312 loc1 = (char *)p1;
332 313 return (advance(p1, p2));
333 314 }
334 315 /* fast check for first character */
335 316 if (*p2 == CCHR) {
336 317 c = p2[1];
337 318 do {
338 319 if (*p1 != c)
339 320 continue;
340 321 if (advance(p1, p2)) {
341 322 loc1 = (char *)p1;
342 323 return (1);
343 324 }
344 325 } while (*p1++);
345 326 return (0);
346 327 }
347 328 /* regular algorithm */
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
348 329 do {
349 330 if (advance(p1, p2)) {
350 331 loc1 = (char *)p1;
351 332 return (1);
352 333 }
353 334 } while (*p1++);
354 335 return (0);
355 336 }
356 337
357 338 int
358 -#ifdef __STDC__
359 339 advance(const char *lp, const char *ep)
360 -#else
361 -advance(lp, ep)
362 -register char *lp, *ep;
363 -#endif
364 340 {
365 -#ifdef __STDC__
366 341 const char *curlp;
367 -#else
368 - register char *curlp;
369 -#endif
370 342 int c;
371 343 char *bbeg;
372 344 register char neg;
373 345 size_t ct;
374 346
375 347 for (;;) {
376 348 neg = 0;
377 349 switch (*ep++) {
378 350
379 351 case CCHR:
380 352 if (*ep++ == *lp++)
381 353 continue;
382 354 return (0);
383 355 /*FALLTHRU*/
384 356
385 357 case CDOT:
386 358 if (*lp++)
387 359 continue;
388 360 return (0);
389 361 /*FALLTHRU*/
390 362
391 363 case CDOL:
392 364 if (*lp == 0)
393 365 continue;
394 366 return (0);
395 367 /*FALLTHRU*/
396 368
397 369 case CCEOF:
398 370 loc2 = (char *)lp;
399 371 return (1);
400 372 /*FALLTHRU*/
401 373
402 374 case CXCL:
403 375 c = (unsigned char)*lp++;
404 376 if (ISTHERE(c)) {
405 377 ep += 32;
406 378 continue;
407 379 }
408 380 return (0);
409 381 /*FALLTHRU*/
410 382
411 383 case NCCL:
412 384 neg = 1;
413 385 /*FALLTHRU*/
414 386
415 387 case CCL:
416 388 c = *lp++;
417 389 if (((c & 0200) == 0 && ISTHERE(c)) ^ neg) {
418 390 ep += 16;
419 391 continue;
420 392 }
421 393 return (0);
422 394 /*FALLTHRU*/
423 395
424 396 case CBRA:
425 397 braslist[*ep++] = (char *)lp;
426 398 continue;
427 399 /*FALLTHRU*/
428 400
429 401 case CKET:
430 402 braelist[*ep++] = (char *)lp;
431 403 continue;
432 404 /*FALLTHRU*/
433 405
434 406 case CCHR | RNGE:
435 407 c = *ep++;
436 408 getrnge(ep);
437 409 while (low--)
438 410 if (*lp++ != c)
439 411 return (0);
440 412 curlp = lp;
441 413 while (size--)
442 414 if (*lp++ != c)
443 415 break;
444 416 if (size < 0)
445 417 lp++;
446 418 ep += 2;
447 419 goto star;
448 420 /*FALLTHRU*/
449 421
450 422 case CDOT | RNGE:
451 423 getrnge(ep);
452 424 while (low--)
453 425 if (*lp++ == '\0')
454 426 return (0);
455 427 curlp = lp;
456 428 while (size--)
457 429 if (*lp++ == '\0')
458 430 break;
459 431 if (size < 0)
460 432 lp++;
461 433 ep += 2;
462 434 goto star;
463 435 /*FALLTHRU*/
464 436
465 437 case CXCL | RNGE:
466 438 getrnge(ep + 32);
467 439 while (low--) {
468 440 c = (unsigned char)*lp++;
469 441 if (!ISTHERE(c))
470 442 return (0);
471 443 }
472 444 curlp = lp;
473 445 while (size--) {
474 446 c = (unsigned char)*lp++;
475 447 if (!ISTHERE(c))
476 448 break;
477 449 }
478 450 if (size < 0)
479 451 lp++;
480 452 ep += 34; /* 32 + 2 */
481 453 goto star;
482 454 /*FALLTHRU*/
483 455
484 456 case NCCL | RNGE:
485 457 neg = 1;
486 458 /*FALLTHRU*/
487 459
488 460 case CCL | RNGE:
489 461 getrnge(ep + 16);
490 462 while (low--) {
491 463 c = *lp++;
492 464 if (((c & 0200) || !ISTHERE(c)) ^ neg)
493 465 return (0);
494 466 }
495 467 curlp = lp;
496 468 while (size--) {
497 469 c = *lp++;
498 470 if (((c & 0200) || !ISTHERE(c)) ^ neg)
499 471 break;
500 472 }
501 473 if (size < 0)
502 474 lp++;
503 475 ep += 18; /* 16 + 2 */
504 476 goto star;
505 477 /*FALLTHRU*/
506 478
507 479 case CBACK:
508 480 bbeg = braslist[*ep];
509 481 ct = braelist[*ep++] - bbeg;
510 482
511 483 if (ecmp(bbeg, lp, ct)) {
512 484 lp += ct;
513 485 continue;
514 486 }
515 487 return (0);
516 488 /*FALLTHRU*/
517 489
518 490 case CBACK | STAR:
519 491 bbeg = braslist[*ep];
520 492 ct = braelist[*ep++] - bbeg;
521 493 curlp = lp;
522 494 while (ecmp(bbeg, lp, ct))
523 495 lp += ct;
524 496
525 497 while (lp >= curlp) {
526 498 if (advance(lp, ep))
527 499 return (1);
528 500 lp -= ct;
529 501 }
530 502 return (0);
531 503 /*FALLTHRU*/
532 504
533 505 case CDOT | STAR:
534 506 curlp = lp;
535 507 while (*lp++);
536 508 goto star;
537 509 /*FALLTHRU*/
538 510
539 511 case CCHR | STAR:
540 512 curlp = lp;
541 513 while (*lp++ == *ep);
542 514 ep++;
543 515 goto star;
544 516 /*FALLTHRU*/
545 517
546 518 case CXCL | STAR:
547 519 curlp = lp;
548 520 do {
549 521 c = (unsigned char)*lp++;
550 522 } while (ISTHERE(c));
551 523 ep += 32;
552 524 goto star;
553 525 /*FALLTHRU*/
554 526
555 527 case NCCL | STAR:
556 528 neg = 1;
557 529 /*FALLTHRU*/
558 530
559 531 case CCL | STAR:
560 532 curlp = lp;
561 533 do {
562 534 c = *lp++;
563 535 } while (((c & 0200) == 0 && ISTHERE(c)) ^ neg);
564 536 ep += 16;
565 537 goto star;
566 538 /*FALLTHRU*/
567 539
568 540 star:
569 541 do {
570 542 if (--lp == locs)
571 543 break;
572 544 if (advance(lp, ep))
↓ open down ↓ |
193 lines elided |
↑ open up ↑ |
573 545 return (1);
574 546 } while (lp > curlp);
575 547 return (0);
576 548
577 549 }
578 550 }
579 551 /*NOTREACHED*/
580 552 }
581 553
582 554 static void
583 -#ifdef __STDC__
584 555 getrnge(const char *str)
585 -#else
586 -getrnge(str)
587 -register char *str;
588 -#endif
589 556 {
590 557 low = *str++ & 0377;
591 558 size = ((*str & 0377) == 255)? 20000: (*str &0377) - low;
592 559 }
593 560
594 561 #ifdef __cplusplus
595 562 }
596 563 #endif
597 564
598 565 #endif /* _REGEXP_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX