hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

regexpr.c (3140B)


      1 /*
      2  * Simple Regular Expression functions. Derived from Unix 7th Edition,
      3  * /usr/src/cmd/expr.y
      4  *
      5  * Modified by Gunnar Ritter, Freiburg i. Br., Germany, January 2003.
      6  *
      7  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  *   Redistributions of source code and documentation must retain the
     13  *    above copyright notice, this list of conditions and the following
     14  *    disclaimer.
     15  *   Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *   All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed or owned by Caldera
     21  *      International, Inc.
     22  *   Neither the name of Caldera International, Inc. nor the names of
     23  *    other contributors may be used to endorse or promote products
     24  *    derived from this software without specific prior written permission.
     25  *
     26  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
     27  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
     28  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     29  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
     31  * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     34  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     35  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     36  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     37  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*	Sccsid @(#)regexpr.c	1.8 (gritter) 10/13/04	*/
     41 
     42 #include	<stdlib.h>
     43 #include	"regexpr.h"
     44 
     45 int	regerrno, reglength;
     46 static int	circf;
     47 
     48 static char	*regexpr_compile(char *, char *, const char *, int);
     49 
     50 char *
     51 compile(const char *instring, char *ep, char *endbuf)
     52 {
     53 	char	*cp;
     54 	int	sz = 0;
     55 
     56 	if (ep == 0) {
     57 		for (cp = (char *)instring; *cp != '\0'; cp++)
     58 			if (*cp == '[')
     59 				sz += 32;
     60 		sz += 2 * (cp - instring) + 5;
     61 		if ((ep = malloc(sz)) == 0) {
     62 			regerrno = 11;
     63 			return 0;
     64 		}
     65 		endbuf = &ep[sz];
     66 		ep[1] = '\0';
     67 	}
     68 	if ((cp=regexpr_compile((char *)instring, &ep[1], endbuf, '\0')) == 0) {
     69 		if (sz)
     70 			free(ep);
     71 		return 0;
     72 	}
     73 	ep[0] = circf;
     74 	reglength = cp - ep;
     75 	return sz ? ep : cp;
     76 }
     77 
     78 #define	INIT			register char *sp = instring;
     79 #define	GETC()			(*sp++)
     80 #define	PEEKC()			(*sp)
     81 #define	UNGETC(c)		(--sp)
     82 #define	RETURN(c)		return (c);
     83 #define	ERROR(c)		{ regerrno = c; return 0; }
     84 
     85 #define	compile(a, b, c, d)	regexpr_compile(a, b, c, d)
     86 #define	regexp_h_static		static
     87 #define	REGEXP_H_STEP_INIT	circf = *p2++;
     88 #define	REGEXP_H_ADVANCE_INIT	circf = *ep++;
     89 
     90 #include	"regexp.h"