meillo@0: /* meillo@0: * Simple Regular Expression functions. Derived from Unix 7th Edition, meillo@0: * /usr/src/cmd/expr.y meillo@0: * meillo@0: * Modified by Gunnar Ritter, Freiburg i. Br., Germany, January 2003. meillo@0: * meillo@0: * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. meillo@0: * meillo@0: * Redistribution and use in source and binary forms, with or without meillo@0: * modification, are permitted provided that the following conditions meillo@0: * are met: meillo@0: * Redistributions of source code and documentation must retain the meillo@0: * above copyright notice, this list of conditions and the following meillo@0: * disclaimer. meillo@0: * Redistributions in binary form must reproduce the above copyright meillo@0: * notice, this list of conditions and the following disclaimer in the meillo@0: * documentation and/or other materials provided with the distribution. meillo@0: * All advertising materials mentioning features or use of this software meillo@0: * must display the following acknowledgement: meillo@0: * This product includes software developed or owned by Caldera meillo@0: * International, Inc. meillo@0: * Neither the name of Caldera International, Inc. nor the names of meillo@0: * other contributors may be used to endorse or promote products meillo@0: * derived from this software without specific prior written permission. meillo@0: * meillo@0: * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA meillo@0: * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR meillo@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED meillo@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE meillo@0: * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE meillo@0: * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR meillo@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF meillo@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR meillo@0: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, meillo@0: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE meillo@0: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, meillo@0: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. meillo@0: */ meillo@0: meillo@0: /* Sccsid @(#)regexpr.c 1.8 (gritter) 10/13/04 */ meillo@0: meillo@0: #include meillo@0: #include "regexpr.h" meillo@0: meillo@0: int regerrno, reglength; meillo@0: static int circf; meillo@0: meillo@0: static char *regexpr_compile(char *, char *, const char *, int); meillo@0: meillo@0: char * meillo@0: compile(const char *instring, char *ep, char *endbuf) meillo@0: { meillo@0: char *cp; meillo@0: int sz = 0; meillo@0: meillo@0: if (ep == 0) { meillo@0: for (cp = (char *)instring; *cp != '\0'; cp++) meillo@0: if (*cp == '[') meillo@0: sz += 32; meillo@0: sz += 2 * (cp - instring) + 5; meillo@0: if ((ep = malloc(sz)) == 0) { meillo@0: regerrno = 11; meillo@0: return 0; meillo@0: } meillo@0: endbuf = &ep[sz]; meillo@0: ep[1] = '\0'; meillo@0: } meillo@0: if ((cp=regexpr_compile((char *)instring, &ep[1], endbuf, '\0')) == 0) { meillo@0: if (sz) meillo@0: free(ep); meillo@0: return 0; meillo@0: } meillo@0: ep[0] = circf; meillo@0: reglength = cp - ep; meillo@0: return sz ? ep : cp; meillo@0: } meillo@0: meillo@0: #define INIT register char *sp = instring; meillo@0: #define GETC() (*sp++) meillo@0: #define PEEKC() (*sp) meillo@0: #define UNGETC(c) (--sp) meillo@0: #define RETURN(c) return (c); meillo@0: #define ERROR(c) { regerrno = c; return 0; } meillo@0: meillo@0: #define compile(a, b, c, d) regexpr_compile(a, b, c, d) meillo@0: #define regexp_h_static static meillo@0: #define REGEXP_H_STEP_INIT circf = *p2++; meillo@0: #define REGEXP_H_ADVANCE_INIT circf = *ep++; meillo@0: meillo@0: #include "regexp.h"