heirloom-ed

diff regexp.h @ 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/regexp.h	Mon Sep 05 16:31:35 2011 +0200
     1.3 @@ -0,0 +1,1211 @@
     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, February 2002.
     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 +#if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4
    1.44 +#define	REGEXP_H_USED	__attribute__ ((used))
    1.45 +#elif defined __GNUC__
    1.46 +#define	REGEXP_H_USED	__attribute__ ((unused))
    1.47 +#else
    1.48 +#define	REGEXP_H_USED
    1.49 +#endif
    1.50 +static const char regexp_h_sccsid[] REGEXP_H_USED =
    1.51 +	"@(#)regexp.sl	1.56 (gritter) 5/29/05";
    1.52 +
    1.53 +#if !defined (REGEXP_H_USED_FROM_VI) && !defined (__dietlibc__)
    1.54 +#define	REGEXP_H_WCHARS
    1.55 +#endif
    1.56 +
    1.57 +#define	CBRA	2
    1.58 +#define	CCHR	4
    1.59 +#define	CDOT	8
    1.60 +#define	CCL	12
    1.61 +/*	CLNUM	14	used in sed */
    1.62 +/*	CEND	16	used in sed */
    1.63 +#define	CDOL	20
    1.64 +#define	CCEOF	22
    1.65 +#define	CKET	24
    1.66 +#define	CBACK	36
    1.67 +#define	CNCL	40
    1.68 +#define	CBRC	44
    1.69 +#define	CLET	48
    1.70 +#define	CCH1	52
    1.71 +#define	CCH2	56
    1.72 +#define	CCH3	60
    1.73 +
    1.74 +#define	STAR	01
    1.75 +#define RNGE	03
    1.76 +#define	REGEXP_H_LEAST	0100
    1.77 +
    1.78 +#ifdef	REGEXP_H_WCHARS
    1.79 +#define	CMB	0200
    1.80 +#else	/* !REGEXP_H_WCHARS */
    1.81 +#define	CMB	0
    1.82 +#endif	/* !REGEXP_H_WCHARS */
    1.83 +
    1.84 +#define	NBRA	9
    1.85 +
    1.86 +#define PLACE(c)	ep[c >> 3] |= bittab[c & 07]
    1.87 +#define ISTHERE(c)	(ep[c >> 3] & bittab[c & 07])
    1.88 +
    1.89 +#ifdef	REGEXP_H_WCHARS
    1.90 +#define	REGEXP_H_IS_THERE(ep, c)	((ep)[c >> 3] & bittab[c & 07])
    1.91 +#endif
    1.92 +
    1.93 +#include	<ctype.h>
    1.94 +#include	<string.h>
    1.95 +#include	<limits.h>
    1.96 +#ifdef	REGEXP_H_WCHARS
    1.97 +#include	<stdlib.h>
    1.98 +#include	<wchar.h>
    1.99 +#include	<wctype.h>
   1.100 +#endif	/* REGEXP_H_WCHARS */
   1.101 +
   1.102 +#define	regexp_h_uletter(c)	(isalpha(c) || (c) == '_')
   1.103 +#ifdef	REGEXP_H_WCHARS
   1.104 +#define	regexp_h_wuletter(c)	(iswalpha(c) || (c) == L'_')
   1.105 +
   1.106 +/*
   1.107 + * Used to allocate memory for the multibyte star algorithm.
   1.108 + */
   1.109 +#ifndef	regexp_h_malloc
   1.110 +#define	regexp_h_malloc(n)	malloc(n)
   1.111 +#endif
   1.112 +#ifndef	regexp_h_free
   1.113 +#define	regexp_h_free(p)	free(p)
   1.114 +#endif
   1.115 +
   1.116 +/*
   1.117 + * Can be predefined to 'inline' to inline some multibyte functions;
   1.118 + * may improve performance for files that contain many multibyte
   1.119 + * sequences.
   1.120 + */
   1.121 +#ifndef	regexp_h_inline
   1.122 +#define	regexp_h_inline
   1.123 +#endif
   1.124 +
   1.125 +/*
   1.126 + * Mask to determine whether the first byte of a sequence possibly
   1.127 + * starts a multibyte character. Set to 0377 to force mbtowc() for
   1.128 + * any byte sequence (except 0).
   1.129 + */
   1.130 +#ifndef	REGEXP_H_MASK
   1.131 +#define	REGEXP_H_MASK	0200
   1.132 +#endif
   1.133 +#endif	/* REGEXP_H_WCHARS */
   1.134 +
   1.135 +/*
   1.136 + * For regexpr.h.
   1.137 + */
   1.138 +#ifndef	regexp_h_static
   1.139 +#define	regexp_h_static
   1.140 +#endif
   1.141 +#ifndef	REGEXP_H_STEP_INIT
   1.142 +#define	REGEXP_H_STEP_INIT
   1.143 +#endif
   1.144 +#ifndef	REGEXP_H_ADVANCE_INIT
   1.145 +#define	REGEXP_H_ADVANCE_INIT
   1.146 +#endif
   1.147 +
   1.148 +char	*braslist[NBRA];
   1.149 +char	*braelist[NBRA];
   1.150 +int	nbra;
   1.151 +char	*loc1, *loc2, *locs;
   1.152 +int	sed;
   1.153 +int	nodelim;
   1.154 +
   1.155 +regexp_h_static int	circf;
   1.156 +regexp_h_static int	low;
   1.157 +regexp_h_static int	size;
   1.158 +
   1.159 +regexp_h_static unsigned char	bittab[] = {
   1.160 +	1,
   1.161 +	2,
   1.162 +	4,
   1.163 +	8,
   1.164 +	16,
   1.165 +	32,
   1.166 +	64,
   1.167 +	128
   1.168 +};
   1.169 +static int	regexp_h_advance(register const char *lp,
   1.170 +			register const char *ep);
   1.171 +static void	regexp_h_getrnge(register const char *str, int least);
   1.172 +
   1.173 +static const char	*regexp_h_bol;	/* beginning of input line (for \<) */
   1.174 +
   1.175 +#ifdef	REGEXP_H_WCHARS
   1.176 +static int	regexp_h_wchars;
   1.177 +static int	regexp_h_mbcurmax;
   1.178 +
   1.179 +static const char	*regexp_h_firstwc;	/* location of first
   1.180 +						   multibyte character
   1.181 +						   on input line */
   1.182 +
   1.183 +#define	regexp_h_getwc(c)	{ \
   1.184 +	if (regexp_h_wchars) { \
   1.185 +		char mbbuf[MB_LEN_MAX + 1], *mbptr; \
   1.186 +		wchar_t wcbuf; \
   1.187 +		int mb, len; \
   1.188 +		mbptr = mbbuf; \
   1.189 +		do { \
   1.190 +			mb = GETC(); \
   1.191 +			*mbptr++ = mb; \
   1.192 +			*mbptr = '\0'; \
   1.193 +		} while ((len = mbtowc(&wcbuf, mbbuf, regexp_h_mbcurmax)) < 0 \
   1.194 +			&& mb != eof && mbptr < mbbuf + MB_LEN_MAX); \
   1.195 +		if (len == -1) \
   1.196 +			ERROR(67); \
   1.197 +		c = wcbuf; \
   1.198 +	} else { \
   1.199 +		c = GETC(); \
   1.200 +	} \
   1.201 +}
   1.202 +
   1.203 +#define	regexp_h_store(wc, mb, me)	{ \
   1.204 +	int len; \
   1.205 +	if (wc == WEOF) \
   1.206 +		ERROR(67); \
   1.207 +	if ((len = me - mb) <= regexp_h_mbcurmax) { \
   1.208 +		char mt[MB_LEN_MAX]; \
   1.209 +		if (wctomb(mt, wc) >= len) \
   1.210 +			ERROR(50); \
   1.211 +	} \
   1.212 +	switch (len = wctomb(mb, wc)) { \
   1.213 +	case -1: \
   1.214 +		 ERROR(67); \
   1.215 +	case 0: \
   1.216 +		mb++; \
   1.217 +		break; \
   1.218 +	default: \
   1.219 +		mb += len; \
   1.220 +	} \
   1.221 +}
   1.222 +
   1.223 +static regexp_h_inline wint_t
   1.224 +regexp_h_fetchwc(const char **mb, int islp)
   1.225 +{
   1.226 +	wchar_t wc;
   1.227 +	int len;
   1.228 +
   1.229 +	if ((len = mbtowc(&wc, *mb, regexp_h_mbcurmax)) < 0) {
   1.230 +		(*mb)++;
   1.231 +		return WEOF;
   1.232 +	}
   1.233 +	if (islp && regexp_h_firstwc == NULL)
   1.234 +		regexp_h_firstwc = *mb;
   1.235 +	/*if (len == 0) {
   1.236 +		(*mb)++;
   1.237 +		return L'\0';
   1.238 +	} handled in singlebyte code */
   1.239 +	*mb += len;
   1.240 +	return wc;
   1.241 +}
   1.242 +
   1.243 +#define	regexp_h_fetch(mb, islp)	((*(mb) & REGEXP_H_MASK) == 0 ? \
   1.244 +						(*(mb)++&0377): \
   1.245 +						regexp_h_fetchwc(&(mb), islp))
   1.246 +
   1.247 +static regexp_h_inline wint_t
   1.248 +regexp_h_showwc(const char *mb)
   1.249 +{
   1.250 +	wchar_t wc;
   1.251 +
   1.252 +	if (mbtowc(&wc, mb, regexp_h_mbcurmax) < 0)
   1.253 +		return WEOF;
   1.254 +	return wc;
   1.255 +}
   1.256 +
   1.257 +#define	regexp_h_show(mb)	((*(mb) & REGEXP_H_MASK) == 0 ? (*(mb)&0377): \
   1.258 +					regexp_h_showwc(mb))
   1.259 +
   1.260 +/*
   1.261 + * Return the character immediately preceding mb. Since no byte is
   1.262 + * required to be the first byte of a character, the longest multibyte
   1.263 + * character ending at &[mb-1] is searched.
   1.264 + */
   1.265 +static regexp_h_inline wint_t
   1.266 +regexp_h_previous(const char *mb)
   1.267 +{
   1.268 +	const char *p = mb;
   1.269 +	wchar_t wc, lastwc = WEOF;
   1.270 +	int len, max = 0;
   1.271 +
   1.272 +	if (regexp_h_firstwc == NULL || mb <= regexp_h_firstwc)
   1.273 +		return (mb > regexp_h_bol ? (mb[-1] & 0377) : WEOF);
   1.274 +	while (p-- > regexp_h_bol) {
   1.275 +		mbtowc(NULL, NULL, 0);
   1.276 +		if ((len = mbtowc(&wc, p, mb - p)) >= 0) {
   1.277 +			if (len < max || len < mb - p)
   1.278 +				break;
   1.279 +			max = len;
   1.280 +			lastwc = wc;
   1.281 +		} else if (len < 0 && max > 0)
   1.282 +			break;
   1.283 +	}
   1.284 +	return lastwc;
   1.285 +}
   1.286 +
   1.287 +#define	regexp_h_cclass(set, c, af)	\
   1.288 +	((c) == 0 || (c) == WEOF ? 0 : ( \
   1.289 +		((c) > 0177) ? \
   1.290 +			regexp_h_cclass_wc(set, c, af) : ( \
   1.291 +				REGEXP_H_IS_THERE((set)+1, (c)) ? (af) : !(af) \
   1.292 +			) \
   1.293 +		) \
   1.294 +	)
   1.295 +
   1.296 +static regexp_h_inline int
   1.297 +regexp_h_cclass_wc(const char *set, register wint_t c, int af)
   1.298 +{
   1.299 +	register wint_t wc, wl = WEOF;
   1.300 +	const char *end;
   1.301 +
   1.302 +	end = &set[18] + set[0] - 1;
   1.303 +	set += 17;
   1.304 +	while (set < end) {
   1.305 +		wc = regexp_h_fetch(set, 0);
   1.306 +#ifdef	REGEXP_H_VI_BACKSLASH
   1.307 +		if (wc == '\\' && set < end &&
   1.308 +				(*set == ']' || *set == '-' ||
   1.309 +				 *set == '^' || *set == '\\')) {
   1.310 +			wc = regexp_h_fetch(set, 0);
   1.311 +		} else
   1.312 +#endif	/* REGEXP_H_VI_BACKSLASH */
   1.313 +		if (wc == '-' && wl != WEOF && set < end) {
   1.314 +			wc = regexp_h_fetch(set, 0);
   1.315 +#ifdef	REGEXP_H_VI_BACKSLASH
   1.316 +			if (wc == '\\' && set < end &&
   1.317 +					(*set == ']' || *set == '-' ||
   1.318 +					 *set == '^' || *set == '\\')) {
   1.319 +				wc = regexp_h_fetch(set, 0);
   1.320 +			}
   1.321 +#endif	/* REGEXP_H_VI_BACKSLASH */
   1.322 +			if (c > wl && c < wc)
   1.323 +				return af;
   1.324 +		}
   1.325 +		if (c == wc)
   1.326 +			return af;
   1.327 +		wl = wc;
   1.328 +	}
   1.329 +	return !af;
   1.330 +}
   1.331 +#else	/* !REGEXP_H_WCHARS */
   1.332 +#define	regexp_h_wchars		0
   1.333 +#define	regexp_h_getwc(c)	{ c = GETC(); }
   1.334 +#endif	/* !REGEXP_H_WCHARS */
   1.335 +
   1.336 +regexp_h_static char *
   1.337 +compile(char *instring, char *ep, const char *endbuf, int seof)
   1.338 +{
   1.339 +	INIT	/* Dependent declarations and initializations */
   1.340 +	register int c;
   1.341 +	register int eof = seof;
   1.342 +	char *lastep = instring;
   1.343 +	int cclcnt;
   1.344 +	char bracket[NBRA], *bracketp;
   1.345 +	int closed;
   1.346 +	char neg;
   1.347 +	int lc;
   1.348 +	int i, cflg;
   1.349 +
   1.350 +#ifdef	REGEXP_H_WCHARS
   1.351 +	char *eq;
   1.352 +	regexp_h_mbcurmax = MB_CUR_MAX;
   1.353 +	regexp_h_wchars = regexp_h_mbcurmax > 1 ? CMB : 0;
   1.354 +#endif
   1.355 +	lastep = 0;
   1.356 +	bracketp = bracket;
   1.357 +	if((c = GETC()) == eof || c == '\n') {
   1.358 +		if (c == '\n') {
   1.359 +			UNGETC(c);
   1.360 +			nodelim = 1;
   1.361 +		}
   1.362 +		if(*ep == 0 && !sed)
   1.363 +			ERROR(41);
   1.364 +		if (bracketp > bracket)
   1.365 +			ERROR(42);
   1.366 +		RETURN(ep);
   1.367 +	}
   1.368 +	circf = closed = nbra = 0;
   1.369 +	if (c == '^')
   1.370 +		circf++;
   1.371 +	else
   1.372 +		UNGETC(c);
   1.373 +	for (;;) {
   1.374 +		if (ep >= endbuf)
   1.375 +			ERROR(50);
   1.376 +		regexp_h_getwc(c);
   1.377 +		if(c != '*' && ((c != '\\') || (PEEKC() != '{')))
   1.378 +			lastep = ep;
   1.379 +		if (c == eof) {
   1.380 +			*ep++ = CCEOF;
   1.381 +			if (bracketp > bracket)
   1.382 +				ERROR(42);
   1.383 +			RETURN(ep);
   1.384 +		}
   1.385 +		switch (c) {
   1.386 +
   1.387 +		case '.':
   1.388 +			*ep++ = CDOT|regexp_h_wchars;
   1.389 +			continue;
   1.390 +
   1.391 +		case '\n':
   1.392 +			if (sed == 0) {
   1.393 +				UNGETC(c);
   1.394 +				*ep++ = CCEOF;
   1.395 +				nodelim = 1;
   1.396 +				RETURN(ep);
   1.397 +			}
   1.398 +			ERROR(36);
   1.399 +		case '*':
   1.400 +			if (lastep==0 || *lastep==CBRA || *lastep==CKET ||
   1.401 +					*lastep==(CBRC|regexp_h_wchars) ||
   1.402 +					*lastep==(CLET|regexp_h_wchars))
   1.403 +				goto defchar;
   1.404 +			*lastep |= STAR;
   1.405 +			continue;
   1.406 +
   1.407 +		case '$':
   1.408 +			if(PEEKC() != eof)
   1.409 +				goto defchar;
   1.410 +			*ep++ = CDOL;
   1.411 +			continue;
   1.412 +
   1.413 +		case '[':
   1.414 +#ifdef	REGEXP_H_WCHARS
   1.415 +			if (regexp_h_wchars == 0) {
   1.416 +#endif
   1.417 +				if(&ep[33] >= endbuf)
   1.418 +					ERROR(50);
   1.419 +
   1.420 +				*ep++ = CCL;
   1.421 +				lc = 0;
   1.422 +				for(i = 0; i < 32; i++)
   1.423 +					ep[i] = 0;
   1.424 +
   1.425 +				neg = 0;
   1.426 +				if((c = GETC()) == '^') {
   1.427 +					neg = 1;
   1.428 +					c = GETC();
   1.429 +				}
   1.430 +
   1.431 +				do {
   1.432 +					c &= 0377;
   1.433 +					if(c == '\0' || c == '\n')
   1.434 +						ERROR(49);
   1.435 +#ifdef	REGEXP_H_VI_BACKSLASH
   1.436 +					if(c == '\\' && ((c = PEEKC()) == ']' ||
   1.437 +							c == '-' || c == '^' ||
   1.438 +							c == '\\')) {
   1.439 +						c = GETC();
   1.440 +						c &= 0377;
   1.441 +					} else
   1.442 +#endif	/* REGEXP_H_VI_BACKSLASH */
   1.443 +					if(c == '-' && lc != 0) {
   1.444 +						if ((c = GETC()) == ']') {
   1.445 +							PLACE('-');
   1.446 +							break;
   1.447 +						}
   1.448 +#ifdef	REGEXP_H_VI_BACKSLASH
   1.449 +						if(c == '\\' &&
   1.450 +							((c = PEEKC()) == ']' ||
   1.451 +								c == '-' ||
   1.452 +								c == '^' ||
   1.453 +								c == '\\'))
   1.454 +							c = GETC();
   1.455 +#endif	/* REGEXP_H_VI_BACKSLASH */
   1.456 +						c &= 0377;
   1.457 +						while(lc < c) {
   1.458 +							PLACE(lc);
   1.459 +							lc++;
   1.460 +						}
   1.461 +					}
   1.462 +					lc = c;
   1.463 +					PLACE(c);
   1.464 +				} while((c = GETC()) != ']');
   1.465 +				if(neg) {
   1.466 +					for(cclcnt = 0; cclcnt < 32; cclcnt++)
   1.467 +						ep[cclcnt] ^= 0377;
   1.468 +					ep[0] &= 0376;
   1.469 +				}
   1.470 +
   1.471 +				ep += 32;
   1.472 +#ifdef	REGEXP_H_WCHARS
   1.473 +			} else {
   1.474 +				if (&ep[18] >= endbuf)
   1.475 +					ERROR(50);
   1.476 +				*ep++ = CCL|CMB;
   1.477 +				*ep++ = 0;
   1.478 +				lc = 0;
   1.479 +				for (i = 0; i < 16; i++)
   1.480 +					ep[i] = 0;
   1.481 +				eq = &ep[16];
   1.482 +				regexp_h_getwc(c);
   1.483 +				if (c == L'^') {
   1.484 +					regexp_h_getwc(c);
   1.485 +					ep[-2] = CNCL|CMB;
   1.486 +				}
   1.487 +				do {
   1.488 +					if (c == '\0' || c == '\n')
   1.489 +						ERROR(49);
   1.490 +#ifdef	REGEXP_H_VI_BACKSLASH
   1.491 +					if(c == '\\' && ((c = PEEKC()) == ']' ||
   1.492 +							c == '-' || c == '^' ||
   1.493 +							c == '\\')) {
   1.494 +						regexp_h_store(c, eq, endbuf);
   1.495 +						regexp_h_getwc(c);
   1.496 +					} else
   1.497 +#endif	/* REGEXP_H_VI_BACKSLASH */
   1.498 +					if (c == '-' && lc != 0 && lc <= 0177) {
   1.499 +						regexp_h_store(c, eq, endbuf);
   1.500 +						regexp_h_getwc(c);
   1.501 +						if (c == ']') {
   1.502 +							PLACE('-');
   1.503 +							break;
   1.504 +						}
   1.505 +#ifdef	REGEXP_H_VI_BACKSLASH
   1.506 +						if(c == '\\' &&
   1.507 +							((c = PEEKC()) == ']' ||
   1.508 +								c == '-' ||
   1.509 +								c == '^' ||
   1.510 +								c == '\\')) {
   1.511 +							regexp_h_store(c, eq,
   1.512 +								endbuf);
   1.513 +							regexp_h_getwc(c);
   1.514 +						}
   1.515 +#endif	/* REGEXP_H_VI_BACKSLASH */
   1.516 +						while (lc < (c & 0177)) {
   1.517 +							PLACE(lc);
   1.518 +							lc++;
   1.519 +						}
   1.520 +					}
   1.521 +					lc = c;
   1.522 +					if (c <= 0177)
   1.523 +						PLACE(c);
   1.524 +					regexp_h_store(c, eq, endbuf);
   1.525 +					regexp_h_getwc(c);
   1.526 +				} while (c != L']');
   1.527 +				if ((i = eq - &ep[16]) > 255)
   1.528 +					ERROR(50);
   1.529 +				lastep[1] = i;
   1.530 +				ep = eq;
   1.531 +			}
   1.532 +#endif	/* REGEXP_H_WCHARS */
   1.533 +
   1.534 +			continue;
   1.535 +
   1.536 +		case '\\':
   1.537 +			regexp_h_getwc(c);
   1.538 +			switch(c) {
   1.539 +
   1.540 +			case '(':
   1.541 +				if(nbra >= NBRA)
   1.542 +					ERROR(43);
   1.543 +				*bracketp++ = nbra;
   1.544 +				*ep++ = CBRA;
   1.545 +				*ep++ = nbra++;
   1.546 +				continue;
   1.547 +
   1.548 +			case ')':
   1.549 +				if(bracketp <= bracket)
   1.550 +					ERROR(42);
   1.551 +				*ep++ = CKET;
   1.552 +				*ep++ = *--bracketp;
   1.553 +				closed++;
   1.554 +				continue;
   1.555 +
   1.556 +			case '<':
   1.557 +				*ep++ = CBRC|regexp_h_wchars;
   1.558 +				continue;
   1.559 +
   1.560 +			case '>':
   1.561 +				*ep++ = CLET|regexp_h_wchars;
   1.562 +				continue;
   1.563 +
   1.564 +			case '{':
   1.565 +				if(lastep == (char *) (0))
   1.566 +					goto defchar;
   1.567 +				*lastep |= RNGE;
   1.568 +				cflg = 0;
   1.569 +			nlim:
   1.570 +				c = GETC();
   1.571 +				i = 0;
   1.572 +				do {
   1.573 +					if ('0' <= c && c <= '9')
   1.574 +						i = 10 * i + c - '0';
   1.575 +					else
   1.576 +						ERROR(16);
   1.577 +				} while(((c = GETC()) != '\\') && (c != ','));
   1.578 +				if (i > 255)
   1.579 +					ERROR(11);
   1.580 +				*ep++ = i;
   1.581 +				if (c == ',') {
   1.582 +					if(cflg++)
   1.583 +						ERROR(44);
   1.584 +					if((c = GETC()) == '\\') {
   1.585 +						*ep++ = (char)255;
   1.586 +						*lastep |= REGEXP_H_LEAST;
   1.587 +					} else {
   1.588 +						UNGETC(c);
   1.589 +						goto nlim; /* get 2'nd number */
   1.590 +					}
   1.591 +				}
   1.592 +				if(GETC() != '}')
   1.593 +					ERROR(45);
   1.594 +				if(!cflg)	/* one number */
   1.595 +					*ep++ = i;
   1.596 +				else if((ep[-1] & 0377) < (ep[-2] & 0377))
   1.597 +					ERROR(46);
   1.598 +				continue;
   1.599 +
   1.600 +			case '\n':
   1.601 +				ERROR(36);
   1.602 +
   1.603 +			case 'n':
   1.604 +				c = '\n';
   1.605 +				goto defchar;
   1.606 +
   1.607 +			default:
   1.608 +				if(c >= '1' && c <= '9') {
   1.609 +					if((c -= '1') >= closed)
   1.610 +						ERROR(25);
   1.611 +					*ep++ = CBACK;
   1.612 +					*ep++ = c;
   1.613 +					continue;
   1.614 +				}
   1.615 +			}
   1.616 +			/* Drop through to default to use \ to turn off special chars */
   1.617 +
   1.618 +		defchar:
   1.619 +		default:
   1.620 +			lastep = ep;
   1.621 +#ifdef	REGEXP_H_WCHARS
   1.622 +			if (regexp_h_wchars == 0) {
   1.623 +#endif
   1.624 +				*ep++ = CCHR;
   1.625 +				*ep++ = c;
   1.626 +#ifdef	REGEXP_H_WCHARS
   1.627 +			} else {
   1.628 +				char	mbbuf[MB_LEN_MAX];
   1.629 +
   1.630 +				switch (wctomb(mbbuf, c)) {
   1.631 +				case 1: *ep++ = CCH1;
   1.632 +					break;
   1.633 +				case 2:	*ep++ = CCH2;
   1.634 +					break;
   1.635 +				case 3:	*ep++ = CCH3;
   1.636 +					break;
   1.637 +				default:
   1.638 +					*ep++ = CCHR|CMB;
   1.639 +				}
   1.640 +				regexp_h_store(c, ep, endbuf);
   1.641 +			}
   1.642 +#endif	/* REGEXP_H_WCHARS */
   1.643 +		}
   1.644 +	}
   1.645 +}
   1.646 +
   1.647 +int
   1.648 +step(const char *p1, const char *p2)
   1.649 +{
   1.650 +	register int c;
   1.651 +#ifdef	REGEXP_H_WCHARS
   1.652 +	register int d;
   1.653 +#endif	/* REGEXP_H_WCHARS */
   1.654 +
   1.655 +	REGEXP_H_STEP_INIT	/* get circf */
   1.656 +	regexp_h_bol = p1;
   1.657 +#ifdef	REGEXP_H_WCHARS
   1.658 +	regexp_h_firstwc = NULL;
   1.659 +#endif	/* REGEXP_H_WCHARS */
   1.660 +	if (circf) {
   1.661 +		loc1 = (char *)p1;
   1.662 +		return(regexp_h_advance(p1, p2));
   1.663 +	}
   1.664 +	/* fast check for first character */
   1.665 +	if (*p2==CCHR) {
   1.666 +		c = p2[1] & 0377;
   1.667 +		do {
   1.668 +			if ((*p1 & 0377) != c)
   1.669 +				continue;
   1.670 +			if (regexp_h_advance(p1, p2)) {
   1.671 +				loc1 = (char *)p1;
   1.672 +				return(1);
   1.673 +			}
   1.674 +		} while (*p1++);
   1.675 +		return(0);
   1.676 +	}
   1.677 +#ifdef	REGEXP_H_WCHARS
   1.678 +	else if (*p2==CCH1) {
   1.679 +		do {
   1.680 +			if (p1[0] == p2[1] && regexp_h_advance(p1, p2)) {
   1.681 +				loc1 = (char *)p1;
   1.682 +				return(1);
   1.683 +			}
   1.684 +			c = regexp_h_fetch(p1, 1);
   1.685 +		} while (c);
   1.686 +		return(0);
   1.687 +	} else if (*p2==CCH2) {
   1.688 +		do {
   1.689 +			if (p1[0] == p2[1] && p1[1] == p2[2] &&
   1.690 +					regexp_h_advance(p1, p2)) {
   1.691 +				loc1 = (char *)p1;
   1.692 +				return(1);
   1.693 +			}
   1.694 +			c = regexp_h_fetch(p1, 1);
   1.695 +		} while (c);
   1.696 +		return(0);
   1.697 +	} else if (*p2==CCH3) {
   1.698 +		do {
   1.699 +			if (p1[0] == p2[1] && p1[1] == p2[2] && p1[2] == p2[3]&&
   1.700 +					regexp_h_advance(p1, p2)) {
   1.701 +				loc1 = (char *)p1;
   1.702 +				return(1);
   1.703 +			}
   1.704 +			c = regexp_h_fetch(p1, 1);
   1.705 +		} while (c);
   1.706 +		return(0);
   1.707 +	} else if ((*p2&0377)==(CCHR|CMB)) {
   1.708 +		d = regexp_h_fetch(p2, 0);
   1.709 +		do {
   1.710 +			c = regexp_h_fetch(p1, 1);
   1.711 +			if (c == d && regexp_h_advance(p1, p2)) {
   1.712 +				loc1 = (char *)p1;
   1.713 +				return(1);
   1.714 +			}
   1.715 +		} while(c);
   1.716 +		return(0);
   1.717 +	}
   1.718 +		/* regular algorithm */
   1.719 +	if (regexp_h_wchars)
   1.720 +		do {
   1.721 +			if (regexp_h_advance(p1, p2)) {
   1.722 +				loc1 = (char *)p1;
   1.723 +				return(1);
   1.724 +			}
   1.725 +			c = regexp_h_fetch(p1, 1);
   1.726 +		} while (c);
   1.727 +	else
   1.728 +#endif	/* REGEXP_H_WCHARS */
   1.729 +		do {
   1.730 +			if (regexp_h_advance(p1, p2)) {
   1.731 +				loc1 = (char *)p1;
   1.732 +				return(1);
   1.733 +			}
   1.734 +		} while (*p1++);
   1.735 +	return(0);
   1.736 +}
   1.737 +
   1.738 +#ifdef	REGEXP_H_WCHARS
   1.739 +/*
   1.740 + * It is painfully slow to read character-wise backwards in a
   1.741 + * multibyte string (see regexp_h_previous() above). For the star
   1.742 + * algorithm, we therefore keep track of every character as it is
   1.743 + * read in forward direction.
   1.744 + *
   1.745 + * Don't use alloca() for stack blocks since there is no measurable
   1.746 + * speedup and huge amounts of memory are used up for long input
   1.747 + * lines.
   1.748 + */
   1.749 +#ifndef	REGEXP_H_STAKBLOK
   1.750 +#define	REGEXP_H_STAKBLOK	1000
   1.751 +#endif
   1.752 +
   1.753 +struct	regexp_h_stack {
   1.754 +	struct regexp_h_stack	*s_nxt;
   1.755 +	struct regexp_h_stack	*s_prv;
   1.756 +	const char	*s_ptr[REGEXP_H_STAKBLOK];
   1.757 +};
   1.758 +
   1.759 +#define	regexp_h_push(sb, sp, sc, lp)	(regexp_h_wchars ? \
   1.760 +			regexp_h_pushwc(sb, sp, sc, lp) : (void)0)
   1.761 +
   1.762 +static regexp_h_inline void
   1.763 +regexp_h_pushwc(struct regexp_h_stack **sb,
   1.764 +		struct regexp_h_stack **sp,
   1.765 +		const char ***sc, const char *lp)
   1.766 +{
   1.767 +	if (regexp_h_firstwc == NULL || lp < regexp_h_firstwc)
   1.768 +		return;
   1.769 +	if (*sb == NULL) {
   1.770 +		if ((*sb = regexp_h_malloc(sizeof **sb)) == NULL)
   1.771 +			return;
   1.772 +		(*sb)->s_nxt = (*sb)->s_prv = NULL;
   1.773 +		*sp = *sb;
   1.774 +		*sc = &(*sb)->s_ptr[0];
   1.775 +	} else if (*sc >= &(*sp)->s_ptr[REGEXP_H_STAKBLOK]) {
   1.776 +		if ((*sp)->s_nxt == NULL) {
   1.777 +			struct regexp_h_stack	*bq;
   1.778 +
   1.779 +			if ((bq = regexp_h_malloc(sizeof *bq)) == NULL)
   1.780 +				return;
   1.781 +			bq->s_nxt = NULL;
   1.782 +			bq->s_prv = *sp;
   1.783 +			(*sp)->s_nxt = bq;
   1.784 +			*sp = bq;
   1.785 +		} else
   1.786 +			*sp = (*sp)->s_nxt;
   1.787 +		*sc = &(*sp)->s_ptr[0];
   1.788 +	}
   1.789 +	*(*sc)++ = lp;
   1.790 +}
   1.791 +
   1.792 +static regexp_h_inline const char *
   1.793 +regexp_h_pop(struct regexp_h_stack **sb, struct regexp_h_stack **sp,
   1.794 +		const char ***sc, const char *lp)
   1.795 +{
   1.796 +	if (regexp_h_firstwc == NULL || lp <= regexp_h_firstwc)
   1.797 +		return &lp[-1];
   1.798 +	if (*sp == NULL)
   1.799 +		return regexp_h_firstwc;
   1.800 +	if (*sc == &(*sp)->s_ptr[0]) {
   1.801 +		if ((*sp)->s_prv == NULL) {
   1.802 +			regexp_h_free(*sp);
   1.803 +			*sp = NULL;
   1.804 +			*sb = NULL;
   1.805 +			return regexp_h_firstwc;
   1.806 +		}
   1.807 +		*sp = (*sp)->s_prv;
   1.808 +		regexp_h_free((*sp)->s_nxt);
   1.809 +		(*sp)->s_nxt = NULL ;
   1.810 +		*sc = &(*sp)->s_ptr[REGEXP_H_STAKBLOK];
   1.811 +	}
   1.812 +	return *(--(*sc));
   1.813 +}
   1.814 +
   1.815 +static void
   1.816 +regexp_h_zerostak(struct regexp_h_stack **sb, struct regexp_h_stack **sp)
   1.817 +{
   1.818 +	for (*sp = *sb; *sp && (*sp)->s_nxt; *sp = (*sp)->s_nxt)
   1.819 +		if ((*sp)->s_prv)
   1.820 +			regexp_h_free((*sp)->s_prv);
   1.821 +	if (*sp) {
   1.822 +		if ((*sp)->s_prv)
   1.823 +			regexp_h_free((*sp)->s_prv);
   1.824 +		regexp_h_free(*sp);
   1.825 +	}
   1.826 +	*sp = *sb = NULL;
   1.827 +}
   1.828 +#else	/* !REGEXP_H_WCHARS */
   1.829 +#define	regexp_h_push(sb, sp, sc, lp)
   1.830 +#endif	/* !REGEXP_H_WCHARS */
   1.831 +
   1.832 +static int
   1.833 +regexp_h_advance(const char *lp, const char *ep)
   1.834 +{
   1.835 +	register const char *curlp;
   1.836 +	int c, least;
   1.837 +#ifdef	REGEXP_H_WCHARS
   1.838 +	int d;
   1.839 +	struct regexp_h_stack	*sb = NULL, *sp = NULL;
   1.840 +	const char	**sc;
   1.841 +#endif	/* REGEXP_H_WCHARS */
   1.842 +	char *bbeg;
   1.843 +	int ct;
   1.844 +
   1.845 +	for (;;) switch (least = *ep++ & 0377, least & ~REGEXP_H_LEAST) {
   1.846 +
   1.847 +	case CCHR:
   1.848 +#ifdef	REGEXP_H_WCHARS
   1.849 +	case CCH1:
   1.850 +#endif
   1.851 +		if (*ep++ == *lp++)
   1.852 +			continue;
   1.853 +		return(0);
   1.854 +
   1.855 +#ifdef	REGEXP_H_WCHARS
   1.856 +	case CCHR|CMB:
   1.857 +		if (regexp_h_fetch(ep, 0) == regexp_h_fetch(lp, 1))
   1.858 +			continue;
   1.859 +		return(0);
   1.860 +
   1.861 +	case CCH2:
   1.862 +		if (ep[0] == lp[0] && ep[1] == lp[1]) {
   1.863 +			ep += 2, lp += 2;
   1.864 +			continue;
   1.865 +		}
   1.866 +		return(0);
   1.867 +
   1.868 +	case CCH3:
   1.869 +		if (ep[0] == lp[0] && ep[1] == lp[1] && ep[2] == lp[2]) {
   1.870 +			ep += 3, lp += 3;
   1.871 +			continue;
   1.872 +		}
   1.873 +		return(0);
   1.874 +#endif	/* REGEXP_H_WCHARS */
   1.875 +
   1.876 +	case CDOT:
   1.877 +		if (*lp++)
   1.878 +			continue;
   1.879 +		return(0);
   1.880 +#ifdef	REGEXP_H_WCHARS
   1.881 +	case CDOT|CMB:
   1.882 +		if ((c = regexp_h_fetch(lp, 1)) != L'\0' && c != WEOF)
   1.883 +			continue;
   1.884 +		return(0);
   1.885 +#endif	/* REGEXP_H_WCHARS */
   1.886 +
   1.887 +	case CDOL:
   1.888 +		if (*lp==0)
   1.889 +			continue;
   1.890 +		return(0);
   1.891 +
   1.892 +	case CCEOF:
   1.893 +		loc2 = (char *)lp;
   1.894 +		return(1);
   1.895 +
   1.896 +	case CCL:
   1.897 +		c = *lp++ & 0377;
   1.898 +		if(ISTHERE(c)) {
   1.899 +			ep += 32;
   1.900 +			continue;
   1.901 +		}
   1.902 +		return(0);
   1.903 +
   1.904 +#ifdef	REGEXP_H_WCHARS
   1.905 +	case CCL|CMB:
   1.906 +	case CNCL|CMB:
   1.907 +		c = regexp_h_fetch(lp, 1);
   1.908 +		if (regexp_h_cclass(ep, c, (ep[-1] & 0377) == (CCL|CMB))) {
   1.909 +			ep += (*ep & 0377) + 17;
   1.910 +			continue;
   1.911 +		}
   1.912 +		return 0;
   1.913 +#endif	/* REGEXP_H_WCHARS */
   1.914 +
   1.915 +	case CBRA:
   1.916 +		braslist[*ep++ & 0377] = (char *)lp;
   1.917 +		continue;
   1.918 +
   1.919 +	case CKET:
   1.920 +		braelist[*ep++ & 0377] = (char *)lp;
   1.921 +		continue;
   1.922 +
   1.923 +	case CBRC:
   1.924 +		if (lp == regexp_h_bol && locs == NULL)
   1.925 +			continue;
   1.926 +		if ((isdigit(lp[0] & 0377) || regexp_h_uletter(lp[0] & 0377))
   1.927 +				&& !regexp_h_uletter(lp[-1] & 0377)
   1.928 +				&& !isdigit(lp[-1] & 0377))
   1.929 +			continue;
   1.930 +		return(0);
   1.931 +
   1.932 +#ifdef	REGEXP_H_WCHARS
   1.933 +	case CBRC|CMB:
   1.934 +		c = regexp_h_show(lp);
   1.935 +		d = regexp_h_previous(lp);
   1.936 +		if ((iswdigit(c) || regexp_h_wuletter(c))
   1.937 +				&& !regexp_h_wuletter(d)
   1.938 +				&& !iswdigit(d))
   1.939 +			continue;
   1.940 +		return(0);
   1.941 +#endif	/* REGEXP_H_WCHARS */
   1.942 +
   1.943 +	case CLET:
   1.944 +		if (!regexp_h_uletter(lp[0] & 0377) && !isdigit(lp[0] & 0377))
   1.945 +			continue;
   1.946 +		return(0);
   1.947 +
   1.948 +#ifdef	REGEXP_H_WCHARS
   1.949 +	case CLET|CMB:
   1.950 +		c = regexp_h_show(lp);
   1.951 +		if (!regexp_h_wuletter(c) && !iswdigit(c))
   1.952 +			continue;
   1.953 +		return(0);
   1.954 +#endif	/* REGEXP_H_WCHARS */
   1.955 +
   1.956 +	case CCHR|RNGE:
   1.957 +		c = *ep++;
   1.958 +		regexp_h_getrnge(ep, least);
   1.959 +		while(low--)
   1.960 +			if(*lp++ != c)
   1.961 +				return(0);
   1.962 +		curlp = lp;
   1.963 +		while(size--) {
   1.964 +			regexp_h_push(&sb, &sp, &sc, lp);
   1.965 +			if(*lp++ != c)
   1.966 +				break;
   1.967 +		}
   1.968 +		if(size < 0) {
   1.969 +			regexp_h_push(&sb, &sp, &sc, lp);
   1.970 +			lp++;
   1.971 +		}
   1.972 +		ep += 2;
   1.973 +		goto star;
   1.974 +
   1.975 +#ifdef	REGEXP_H_WCHARS
   1.976 +	case CCHR|RNGE|CMB:
   1.977 +	case CCH1|RNGE:
   1.978 +	case CCH2|RNGE:
   1.979 +	case CCH3|RNGE:
   1.980 +		c = regexp_h_fetch(ep, 0);
   1.981 +		regexp_h_getrnge(ep, least);
   1.982 +		while (low--)
   1.983 +			if (regexp_h_fetch(lp, 1) != c)
   1.984 +				return 0;
   1.985 +		curlp = lp;
   1.986 +		while (size--) {
   1.987 +			regexp_h_push(&sb, &sp, &sc, lp);
   1.988 +			if (regexp_h_fetch(lp, 1) != c)
   1.989 +				break;
   1.990 +		}
   1.991 +		if(size < 0) {
   1.992 +			regexp_h_push(&sb, &sp, &sc, lp);
   1.993 +			regexp_h_fetch(lp, 1);
   1.994 +		}
   1.995 +		ep += 2;
   1.996 +		goto star;
   1.997 +#endif	/* REGEXP_H_WCHARS */
   1.998 +
   1.999 +	case CDOT|RNGE:
  1.1000 +		regexp_h_getrnge(ep, least);
  1.1001 +		while(low--)
  1.1002 +			if(*lp++ == '\0')
  1.1003 +				return(0);
  1.1004 +		curlp = lp;
  1.1005 +		while(size--) {
  1.1006 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1007 +			if(*lp++ == '\0')
  1.1008 +				break;
  1.1009 +		}
  1.1010 +		if(size < 0) {
  1.1011 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1012 +			lp++;
  1.1013 +		}
  1.1014 +		ep += 2;
  1.1015 +		goto star;
  1.1016 +
  1.1017 +#ifdef	REGEXP_H_WCHARS
  1.1018 +	case CDOT|RNGE|CMB:
  1.1019 +		regexp_h_getrnge(ep, least);
  1.1020 +		while (low--)
  1.1021 +			if ((c = regexp_h_fetch(lp, 1)) == L'\0' || c == WEOF)
  1.1022 +				return 0;
  1.1023 +		curlp = lp;
  1.1024 +		while (size--) {
  1.1025 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1026 +			if ((c = regexp_h_fetch(lp, 1)) == L'\0' || c == WEOF)
  1.1027 +				break;
  1.1028 +		}
  1.1029 +		if (size < 0) {
  1.1030 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1031 +			regexp_h_fetch(lp, 1);
  1.1032 +		}
  1.1033 +		ep += 2;
  1.1034 +		goto star;
  1.1035 +#endif	/* REGEXP_H_WCHARS */
  1.1036 +
  1.1037 +	case CCL|RNGE:
  1.1038 +		regexp_h_getrnge(ep + 32, least);
  1.1039 +		while(low--) {
  1.1040 +			c = *lp++ & 0377;
  1.1041 +			if(!ISTHERE(c))
  1.1042 +				return(0);
  1.1043 +		}
  1.1044 +		curlp = lp;
  1.1045 +		while(size--) {
  1.1046 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1047 +			c = *lp++ & 0377;
  1.1048 +			if(!ISTHERE(c))
  1.1049 +				break;
  1.1050 +		}
  1.1051 +		if(size < 0) {
  1.1052 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1053 +			lp++;
  1.1054 +		}
  1.1055 +		ep += 34;		/* 32 + 2 */
  1.1056 +		goto star;
  1.1057 +
  1.1058 +#ifdef	REGEXP_H_WCHARS
  1.1059 +	case CCL|RNGE|CMB:
  1.1060 +	case CNCL|RNGE|CMB:
  1.1061 +		regexp_h_getrnge(ep + (*ep & 0377) + 17, least);
  1.1062 +		while (low--) {
  1.1063 +			c = regexp_h_fetch(lp, 1);
  1.1064 +			if (!regexp_h_cclass(ep, c,
  1.1065 +					(ep[-1] & 0377 & ~REGEXP_H_LEAST)
  1.1066 +					== (CCL|RNGE|CMB)))
  1.1067 +				return 0;
  1.1068 +		}
  1.1069 +		curlp = lp;
  1.1070 +		while (size--) {
  1.1071 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1072 +			c = regexp_h_fetch(lp, 1);
  1.1073 +			if (!regexp_h_cclass(ep, c,
  1.1074 +					(ep[-1] & 0377 & ~REGEXP_H_LEAST)
  1.1075 +					== (CCL|RNGE|CMB)))
  1.1076 +				break;
  1.1077 +		}
  1.1078 +		if (size < 0) {
  1.1079 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1080 +			regexp_h_fetch(lp, 1);
  1.1081 +		}
  1.1082 +		ep += (*ep & 0377) + 19;
  1.1083 +		goto star;
  1.1084 +#endif	/* REGEXP_H_WCHARS */
  1.1085 +
  1.1086 +	case CBACK:
  1.1087 +		bbeg = braslist[*ep & 0377];
  1.1088 +		ct = braelist[*ep++ & 0377] - bbeg;
  1.1089 +
  1.1090 +		if(strncmp(bbeg, lp, ct) == 0) {
  1.1091 +			lp += ct;
  1.1092 +			continue;
  1.1093 +		}
  1.1094 +		return(0);
  1.1095 +
  1.1096 +	case CBACK|STAR:
  1.1097 +		bbeg = braslist[*ep & 0377];
  1.1098 +		ct = braelist[*ep++ & 0377] - bbeg;
  1.1099 +		curlp = lp;
  1.1100 +		while(strncmp(bbeg, lp, ct) == 0)
  1.1101 +			lp += ct;
  1.1102 +
  1.1103 +		while(lp >= curlp) {
  1.1104 +			if(regexp_h_advance(lp, ep))	return(1);
  1.1105 +			lp -= ct;
  1.1106 +		}
  1.1107 +		return(0);
  1.1108 +
  1.1109 +
  1.1110 +	case CDOT|STAR:
  1.1111 +		curlp = lp;
  1.1112 +		do
  1.1113 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1114 +		while (*lp++);
  1.1115 +		goto star;
  1.1116 +
  1.1117 +#ifdef	REGEXP_H_WCHARS
  1.1118 +	case CDOT|STAR|CMB:
  1.1119 +		curlp = lp;
  1.1120 +		do
  1.1121 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1122 +		while ((c = regexp_h_fetch(lp, 1)) != L'\0' && c != WEOF);
  1.1123 +		goto star;
  1.1124 +#endif	/* REGEXP_H_WCHARS */
  1.1125 +
  1.1126 +	case CCHR|STAR:
  1.1127 +		curlp = lp;
  1.1128 +		do
  1.1129 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1130 +		while (*lp++ == *ep);
  1.1131 +		ep++;
  1.1132 +		goto star;
  1.1133 +
  1.1134 +#ifdef	REGEXP_H_WCHARS
  1.1135 +	case CCHR|STAR|CMB:
  1.1136 +	case CCH1|STAR:
  1.1137 +	case CCH2|STAR:
  1.1138 +	case CCH3|STAR:
  1.1139 +		curlp = lp;
  1.1140 +		d = regexp_h_fetch(ep, 0);
  1.1141 +		do
  1.1142 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1143 +		while (regexp_h_fetch(lp, 1) == d);
  1.1144 +		goto star;
  1.1145 +#endif	/* REGEXP_H_WCHARS */
  1.1146 +
  1.1147 +	case CCL|STAR:
  1.1148 +		curlp = lp;
  1.1149 +		do {
  1.1150 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1151 +			c = *lp++ & 0377;
  1.1152 +		} while(ISTHERE(c));
  1.1153 +		ep += 32;
  1.1154 +		goto star;
  1.1155 +
  1.1156 +#ifdef	REGEXP_H_WCHARS
  1.1157 +	case CCL|STAR|CMB:
  1.1158 +	case CNCL|STAR|CMB:
  1.1159 +		curlp = lp;
  1.1160 +		do {
  1.1161 +			regexp_h_push(&sb, &sp, &sc, lp);
  1.1162 +			c = regexp_h_fetch(lp, 1);
  1.1163 +		} while (regexp_h_cclass(ep, c, (ep[-1] & 0377)
  1.1164 +					== (CCL|STAR|CMB)));
  1.1165 +		ep += (*ep & 0377) + 17;
  1.1166 +		goto star;
  1.1167 +#endif	/* REGEXP_H_WCHARS */
  1.1168 +
  1.1169 +	star:
  1.1170 +#ifdef	REGEXP_H_WCHARS
  1.1171 +		if (regexp_h_wchars == 0) {
  1.1172 +#endif
  1.1173 +			do {
  1.1174 +				if(--lp == locs)
  1.1175 +					break;
  1.1176 +				if (regexp_h_advance(lp, ep))
  1.1177 +					return(1);
  1.1178 +			} while (lp > curlp);
  1.1179 +#ifdef	REGEXP_H_WCHARS
  1.1180 +		} else {
  1.1181 +			do {
  1.1182 +				lp = regexp_h_pop(&sb, &sp, &sc, lp);
  1.1183 +				if (lp <= locs)
  1.1184 +					break;
  1.1185 +				if (regexp_h_advance(lp, ep)) {
  1.1186 +					regexp_h_zerostak(&sb, &sp);
  1.1187 +					return(1);
  1.1188 +				}
  1.1189 +			} while (lp > curlp);
  1.1190 +			regexp_h_zerostak(&sb, &sp);
  1.1191 +		}
  1.1192 +#endif	/* REGEXP_H_WCHARS */
  1.1193 +		return(0);
  1.1194 +
  1.1195 +	}
  1.1196 +}
  1.1197 +
  1.1198 +static void
  1.1199 +regexp_h_getrnge(register const char *str, int least)
  1.1200 +{
  1.1201 +	low = *str++ & 0377;
  1.1202 +	size = least & REGEXP_H_LEAST ? /*20000*/INT_MAX : (*str & 0377) - low;
  1.1203 +}
  1.1204 +
  1.1205 +int
  1.1206 +advance(const char *lp, const char *ep)
  1.1207 +{
  1.1208 +	REGEXP_H_ADVANCE_INIT	/* skip past circf */
  1.1209 +	regexp_h_bol = lp;
  1.1210 +#ifdef	REGEXP_H_WCHARS
  1.1211 +	regexp_h_firstwc = NULL;
  1.1212 +#endif	/* REGEXP_H_WCHARS */
  1.1213 +	return regexp_h_advance(lp, ep);
  1.1214 +}