Print this page
remove support for non-ANSI compilation


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1988 AT&T     */
  22 /*        All Rights Reserved   */
  23 
  24 
  25 /*


  26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 #ifndef _REGEXP_H
  31 #define _REGEXP_H
  32 
  33 #pragma ident   "%Z%%M% %I%     %E% SMI"        /* SVr4.0 1.9   */
  34 
  35 #include <string.h>
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 #define CBRA    2
  42 #define CCHR    4
  43 #define CDOT    8
  44 #define CCL     12
  45 #define CXCL    16
  46 #define CDOL    20
  47 #define CCEOF   22
  48 #define CKET    24
  49 #define CBACK   36
  50 #define NCCL    40
  51 
  52 #define STAR    01
  53 #define RNGE    03
  54 
  55 #define NBRA    9
  56 
  57 #define PLACE(c)        ep[c >> 3] |= bittab[c & 07]
  58 #define ISTHERE(c)      (ep[c >> 3] & bittab[c & 07])
  59 #define ecmp(s1, s2, n) (strncmp(s1, s2, n) == 0)
  60 
  61 static char     *braslist[NBRA];
  62 static char     *braelist[NBRA];
  63 int     sed, nbra;
  64 char    *loc1, *loc2, *locs;
  65 static int      nodelim;
  66 
  67 int     circf;
  68 static int      low;
  69 static int      size;
  70 
  71 static unsigned char    bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
  72 
  73 #ifdef  __STDC__
  74 int advance(const char *lp, const char *ep);
  75 static void getrnge(const char *str);
  76 #else
  77 int advance();
  78 static void getrnge();
  79 #endif
  80 
  81 char *
  82 #ifdef  __STDC__
  83 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 {
  91         INIT    /* Dependent declarations and initializations */
  92         register int c;
  93         register int eof = seof;
  94         char *lastep;
  95         int cclcnt;
  96         char bracket[NBRA], *bracketp;
  97         int closed;
  98         int neg;
  99         int lc;
 100         int i, cflg;
 101         int iflag; /* used for non-ascii characters in brackets */
 102 
 103 #ifdef __lint
 104         /* make lint happy */
 105         c = nodelim;
 106 #endif
 107 
 108         lastep = NULL;
 109         if ((c = GETC()) == eof || c == '\n') {


 298                                 if (c >= '1' && c <= '9') {
 299                                         if ((c -= '1') >= closed)
 300                                                 ERROR(25);
 301                                         *ep++ = CBACK;
 302                                         *ep++ = (char)c;
 303                                         continue;
 304                                 }
 305                         }
 306         /* Drop through to default to use \ to turn off special chars */
 307 
 308                 defchar:
 309                 default:
 310                         lastep = ep;
 311                         *ep++ = CCHR;
 312                         *ep++ = (char)c;
 313                 }
 314         }
 315         /*NOTREACHED*/
 316 }
 317 
 318 #ifdef  __STDC__
 319 int
 320 step(const char *p1, const char *p2)
 321 #else
 322 int
 323 step(p1, p2)
 324 register char *p1, *p2;
 325 #endif
 326 {
 327         char c;
 328 
 329 
 330         if (circf) {
 331                 loc1 = (char *)p1;
 332                 return (advance(p1, p2));
 333         }
 334         /* fast check for first character */
 335         if (*p2 == CCHR) {
 336                 c = p2[1];
 337                 do {
 338                         if (*p1 != c)
 339                                 continue;
 340                         if (advance(p1, p2)) {
 341                                 loc1 = (char *)p1;
 342                                 return (1);
 343                         }
 344                 } while (*p1++);
 345                 return (0);
 346         }
 347                 /* regular algorithm */
 348         do {
 349                 if (advance(p1, p2)) {
 350                         loc1 = (char *)p1;
 351                         return (1);
 352                 }
 353         } while (*p1++);
 354         return (0);
 355 }
 356 
 357 int
 358 #ifdef  __STDC__
 359 advance(const char *lp, const char *ep)
 360 #else
 361 advance(lp, ep)
 362 register char *lp, *ep;
 363 #endif
 364 {
 365 #ifdef  __STDC__
 366         const char *curlp;
 367 #else
 368         register char *curlp;
 369 #endif
 370         int c;
 371         char *bbeg;
 372         register char neg;
 373         size_t ct;
 374 
 375         for (;;) {
 376                 neg = 0;
 377                 switch (*ep++) {
 378 
 379                 case CCHR:
 380                         if (*ep++ == *lp++)
 381                                 continue;
 382                         return (0);
 383                         /*FALLTHRU*/
 384 
 385                 case CDOT:
 386                         if (*lp++)
 387                                 continue;
 388                         return (0);
 389                         /*FALLTHRU*/


 563                         } while (((c & 0200) == 0 && ISTHERE(c)) ^ neg);
 564                         ep += 16;
 565                         goto star;
 566                         /*FALLTHRU*/
 567 
 568                 star:
 569                         do {
 570                                 if (--lp == locs)
 571                                         break;
 572                                 if (advance(lp, ep))
 573                                         return (1);
 574                         } while (lp > curlp);
 575                         return (0);
 576 
 577                 }
 578         }
 579         /*NOTREACHED*/
 580 }
 581 
 582 static void
 583 #ifdef  __STDC__
 584 getrnge(const char *str)
 585 #else
 586 getrnge(str)
 587 register char *str;
 588 #endif
 589 {
 590         low = *str++ & 0377;
 591         size = ((*str & 0377) == 255)? 20000: (*str &0377) - low;
 592 }
 593 
 594 #ifdef  __cplusplus
 595 }
 596 #endif
 597 
 598 #endif  /* _REGEXP_H */


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1988 AT&T     */
  22 /*        All Rights Reserved   */
  23 

  24 /*
  25  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  26  *
  27  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #ifndef _REGEXP_H
  32 #define _REGEXP_H
  33 


  34 #include <string.h>
  35 
  36 #ifdef  __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 #define CBRA    2
  41 #define CCHR    4
  42 #define CDOT    8
  43 #define CCL     12
  44 #define CXCL    16
  45 #define CDOL    20
  46 #define CCEOF   22
  47 #define CKET    24
  48 #define CBACK   36
  49 #define NCCL    40
  50 
  51 #define STAR    01
  52 #define RNGE    03
  53 
  54 #define NBRA    9
  55 
  56 #define PLACE(c)        ep[c >> 3] |= bittab[c & 07]
  57 #define ISTHERE(c)      (ep[c >> 3] & bittab[c & 07])
  58 #define ecmp(s1, s2, n) (strncmp(s1, s2, n) == 0)
  59 
  60 static char     *braslist[NBRA];
  61 static char     *braelist[NBRA];
  62 int     sed, nbra;
  63 char    *loc1, *loc2, *locs;
  64 static int      nodelim;
  65 
  66 int     circf;
  67 static int      low;
  68 static int      size;
  69 
  70 static unsigned char    bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
  71 

  72 int advance(const char *lp, const char *ep);
  73 static void getrnge(const char *str);




  74 
  75 char *

  76 compile(char *instring, char *ep, const char *endbuf, int seof)






  77 {
  78         INIT    /* Dependent declarations and initializations */
  79         register int c;
  80         register int eof = seof;
  81         char *lastep;
  82         int cclcnt;
  83         char bracket[NBRA], *bracketp;
  84         int closed;
  85         int neg;
  86         int lc;
  87         int i, cflg;
  88         int iflag; /* used for non-ascii characters in brackets */
  89 
  90 #ifdef __lint
  91         /* make lint happy */
  92         c = nodelim;
  93 #endif
  94 
  95         lastep = NULL;
  96         if ((c = GETC()) == eof || c == '\n') {


 285                                 if (c >= '1' && c <= '9') {
 286                                         if ((c -= '1') >= closed)
 287                                                 ERROR(25);
 288                                         *ep++ = CBACK;
 289                                         *ep++ = (char)c;
 290                                         continue;
 291                                 }
 292                         }
 293         /* Drop through to default to use \ to turn off special chars */
 294 
 295                 defchar:
 296                 default:
 297                         lastep = ep;
 298                         *ep++ = CCHR;
 299                         *ep++ = (char)c;
 300                 }
 301         }
 302         /*NOTREACHED*/
 303 }
 304 

 305 int
 306 step(const char *p1, const char *p2)





 307 {
 308         char c;
 309 
 310 
 311         if (circf) {
 312                 loc1 = (char *)p1;
 313                 return (advance(p1, p2));
 314         }
 315         /* fast check for first character */
 316         if (*p2 == CCHR) {
 317                 c = p2[1];
 318                 do {
 319                         if (*p1 != c)
 320                                 continue;
 321                         if (advance(p1, p2)) {
 322                                 loc1 = (char *)p1;
 323                                 return (1);
 324                         }
 325                 } while (*p1++);
 326                 return (0);
 327         }
 328                 /* regular algorithm */
 329         do {
 330                 if (advance(p1, p2)) {
 331                         loc1 = (char *)p1;
 332                         return (1);
 333                 }
 334         } while (*p1++);
 335         return (0);
 336 }
 337 
 338 int

 339 advance(const char *lp, const char *ep)




 340 {

 341         const char *curlp;



 342         int c;
 343         char *bbeg;
 344         register char neg;
 345         size_t ct;
 346 
 347         for (;;) {
 348                 neg = 0;
 349                 switch (*ep++) {
 350 
 351                 case CCHR:
 352                         if (*ep++ == *lp++)
 353                                 continue;
 354                         return (0);
 355                         /*FALLTHRU*/
 356 
 357                 case CDOT:
 358                         if (*lp++)
 359                                 continue;
 360                         return (0);
 361                         /*FALLTHRU*/


 535                         } while (((c & 0200) == 0 && ISTHERE(c)) ^ neg);
 536                         ep += 16;
 537                         goto star;
 538                         /*FALLTHRU*/
 539 
 540                 star:
 541                         do {
 542                                 if (--lp == locs)
 543                                         break;
 544                                 if (advance(lp, ep))
 545                                         return (1);
 546                         } while (lp > curlp);
 547                         return (0);
 548 
 549                 }
 550         }
 551         /*NOTREACHED*/
 552 }
 553 
 554 static void

 555 getrnge(const char *str)




 556 {
 557         low = *str++ & 0377;
 558         size = ((*str & 0377) == 255)? 20000: (*str &0377) - low;
 559 }
 560 
 561 #ifdef  __cplusplus
 562 }
 563 #endif
 564 
 565 #endif  /* _REGEXP_H */