heirloom-ed

diff regexpr.c @ 0:1493bea5ac22

Initial version of the standalone heirloom-ed
author markus schnalke <meillo@marmaro.de>
date Mon, 05 Sep 2011 16:31:35 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/regexpr.c	Mon Sep 05 16:31:35 2011 +0200
     1.3 @@ -0,0 +1,90 @@
     1.4 +/*
     1.5 + * Simple Regular Expression functions. Derived from Unix 7th Edition,
     1.6 + * /usr/src/cmd/expr.y
     1.7 + *
     1.8 + * Modified by Gunnar Ritter, Freiburg i. Br., Germany, January 2003.
     1.9 + *
    1.10 + * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
    1.11 + *
    1.12 + * Redistribution and use in source and binary forms, with or without
    1.13 + * modification, are permitted provided that the following conditions
    1.14 + * are met:
    1.15 + *   Redistributions of source code and documentation must retain the
    1.16 + *    above copyright notice, this list of conditions and the following
    1.17 + *    disclaimer.
    1.18 + *   Redistributions in binary form must reproduce the above copyright
    1.19 + *    notice, this list of conditions and the following disclaimer in the
    1.20 + *    documentation and/or other materials provided with the distribution.
    1.21 + *   All advertising materials mentioning features or use of this software
    1.22 + *    must display the following acknowledgement:
    1.23 + *      This product includes software developed or owned by Caldera
    1.24 + *      International, Inc.
    1.25 + *   Neither the name of Caldera International, Inc. nor the names of
    1.26 + *    other contributors may be used to endorse or promote products
    1.27 + *    derived from this software without specific prior written permission.
    1.28 + *
    1.29 + * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
    1.30 + * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
    1.31 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.32 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.33 + * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
    1.34 + * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.35 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.36 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
    1.37 + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    1.38 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    1.39 + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    1.40 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.41 + */
    1.42 +
    1.43 +/*	Sccsid @(#)regexpr.c	1.8 (gritter) 10/13/04	*/
    1.44 +
    1.45 +#include	<stdlib.h>
    1.46 +#include	"regexpr.h"
    1.47 +
    1.48 +int	regerrno, reglength;
    1.49 +static int	circf;
    1.50 +
    1.51 +static char	*regexpr_compile(char *, char *, const char *, int);
    1.52 +
    1.53 +char *
    1.54 +compile(const char *instring, char *ep, char *endbuf)
    1.55 +{
    1.56 +	char	*cp;
    1.57 +	int	sz = 0;
    1.58 +
    1.59 +	if (ep == 0) {
    1.60 +		for (cp = (char *)instring; *cp != '\0'; cp++)
    1.61 +			if (*cp == '[')
    1.62 +				sz += 32;
    1.63 +		sz += 2 * (cp - instring) + 5;
    1.64 +		if ((ep = malloc(sz)) == 0) {
    1.65 +			regerrno = 11;
    1.66 +			return 0;
    1.67 +		}
    1.68 +		endbuf = &ep[sz];
    1.69 +		ep[1] = '\0';
    1.70 +	}
    1.71 +	if ((cp=regexpr_compile((char *)instring, &ep[1], endbuf, '\0')) == 0) {
    1.72 +		if (sz)
    1.73 +			free(ep);
    1.74 +		return 0;
    1.75 +	}
    1.76 +	ep[0] = circf;
    1.77 +	reglength = cp - ep;
    1.78 +	return sz ? ep : cp;
    1.79 +}
    1.80 +
    1.81 +#define	INIT			register char *sp = instring;
    1.82 +#define	GETC()			(*sp++)
    1.83 +#define	PEEKC()			(*sp)
    1.84 +#define	UNGETC(c)		(--sp)
    1.85 +#define	RETURN(c)		return (c);
    1.86 +#define	ERROR(c)		{ regerrno = c; return 0; }
    1.87 +
    1.88 +#define	compile(a, b, c, d)	regexpr_compile(a, b, c, d)
    1.89 +#define	regexp_h_static		static
    1.90 +#define	REGEXP_H_STEP_INIT	circf = *p2++;
    1.91 +#define	REGEXP_H_ADVANCE_INIT	circf = *ep++;
    1.92 +
    1.93 +#include	"regexp.h"