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