xref: /onnv-gate/usr/src/head/regexp.h (revision 2712:f74a135872bc)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2712Snn35248  * Common Development and Distribution License (the "License").
6*2712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
26*2712Snn35248  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
270Sstevel@tonic-gate  * Use is subject to license terms.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef _REGEXP_H
310Sstevel@tonic-gate #define	_REGEXP_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef	__cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #define	CBRA	2
420Sstevel@tonic-gate #define	CCHR	4
430Sstevel@tonic-gate #define	CDOT	8
440Sstevel@tonic-gate #define	CCL	12
450Sstevel@tonic-gate #define	CXCL	16
460Sstevel@tonic-gate #define	CDOL	20
470Sstevel@tonic-gate #define	CCEOF	22
480Sstevel@tonic-gate #define	CKET	24
490Sstevel@tonic-gate #define	CBACK	36
500Sstevel@tonic-gate #define	NCCL	40
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #define	STAR	01
530Sstevel@tonic-gate #define	RNGE	03
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	NBRA	9
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	PLACE(c)	ep[c >> 3] |= bittab[c & 07]
580Sstevel@tonic-gate #define	ISTHERE(c)	(ep[c >> 3] & bittab[c & 07])
590Sstevel@tonic-gate #define	ecmp(s1, s2, n)	(strncmp(s1, s2, n) == 0)
600Sstevel@tonic-gate 
610Sstevel@tonic-gate static char	*braslist[NBRA];
620Sstevel@tonic-gate static char	*braelist[NBRA];
630Sstevel@tonic-gate int	sed, nbra;
640Sstevel@tonic-gate char	*loc1, *loc2, *locs;
650Sstevel@tonic-gate static int	nodelim;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate int	circf;
680Sstevel@tonic-gate static int	low;
690Sstevel@tonic-gate static int	size;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate static unsigned char	bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #ifdef	__STDC__
740Sstevel@tonic-gate int advance(const char *lp, const char *ep);
750Sstevel@tonic-gate static void getrnge(const char *str);
760Sstevel@tonic-gate #else
770Sstevel@tonic-gate int advance();
780Sstevel@tonic-gate static void getrnge();
790Sstevel@tonic-gate #endif
800Sstevel@tonic-gate 
810Sstevel@tonic-gate char *
820Sstevel@tonic-gate #ifdef	__STDC__
compile(char * instring,char * ep,const char * endbuf,int seof)830Sstevel@tonic-gate compile(char *instring, char *ep, const char *endbuf, int seof)
840Sstevel@tonic-gate #else
850Sstevel@tonic-gate compile(instring, ep, endbuf, seof)
860Sstevel@tonic-gate register char *ep;
870Sstevel@tonic-gate char *instring, *endbuf;
880Sstevel@tonic-gate int seof;
890Sstevel@tonic-gate #endif
900Sstevel@tonic-gate {
910Sstevel@tonic-gate 	INIT	/* Dependent declarations and initializations */
920Sstevel@tonic-gate 	register int c;
930Sstevel@tonic-gate 	register int eof = seof;
940Sstevel@tonic-gate 	char *lastep;
950Sstevel@tonic-gate 	int cclcnt;
960Sstevel@tonic-gate 	char bracket[NBRA], *bracketp;
970Sstevel@tonic-gate 	int closed;
980Sstevel@tonic-gate 	int neg;
990Sstevel@tonic-gate 	int lc;
1000Sstevel@tonic-gate 	int i, cflg;
1010Sstevel@tonic-gate 	int iflag; /* used for non-ascii characters in brackets */
1020Sstevel@tonic-gate 
103*2712Snn35248 #ifdef __lint
104*2712Snn35248 	/* make lint happy */
105*2712Snn35248 	c = nodelim;
106*2712Snn35248 #endif
107*2712Snn35248 
1080Sstevel@tonic-gate 	lastep = NULL;
1090Sstevel@tonic-gate 	if ((c = GETC()) == eof || c == '\n') {
1100Sstevel@tonic-gate 		if (c == '\n') {
1110Sstevel@tonic-gate 			UNGETC(c);
1120Sstevel@tonic-gate 			nodelim = 1;
1130Sstevel@tonic-gate 		}
1140Sstevel@tonic-gate 		if (*ep == 0 && !sed)
1150Sstevel@tonic-gate 			ERROR(41);
1160Sstevel@tonic-gate 		RETURN(ep);
1170Sstevel@tonic-gate 	}
1180Sstevel@tonic-gate 	bracketp = bracket;
1190Sstevel@tonic-gate 	circf = closed = nbra = 0;
1200Sstevel@tonic-gate 	if (c == '^')
1210Sstevel@tonic-gate 		circf++;
1220Sstevel@tonic-gate 	else
1230Sstevel@tonic-gate 		UNGETC(c);
124*2712Snn35248 	for (;;) {
1250Sstevel@tonic-gate 		if (ep >= endbuf)
1260Sstevel@tonic-gate 			ERROR(50);
1270Sstevel@tonic-gate 		c = GETC();
1280Sstevel@tonic-gate 		if (c != '*' && ((c != '\\') || (PEEKC() != '{')))
1290Sstevel@tonic-gate 			lastep = ep;
1300Sstevel@tonic-gate 		if (c == eof) {
1310Sstevel@tonic-gate 			*ep++ = CCEOF;
1320Sstevel@tonic-gate 			if (bracketp != bracket)
1330Sstevel@tonic-gate 				ERROR(42);
1340Sstevel@tonic-gate 			RETURN(ep);
1350Sstevel@tonic-gate 		}
1360Sstevel@tonic-gate 		switch (c) {
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 		case '.':
1390Sstevel@tonic-gate 			*ep++ = CDOT;
1400Sstevel@tonic-gate 			continue;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 		case '\n':
1430Sstevel@tonic-gate 			if (!sed) {
1440Sstevel@tonic-gate 				UNGETC(c);
1450Sstevel@tonic-gate 				*ep++ = CCEOF;
1460Sstevel@tonic-gate 				nodelim = 1;
1470Sstevel@tonic-gate 				if (bracketp != bracket)
1480Sstevel@tonic-gate 					ERROR(42);
1490Sstevel@tonic-gate 				RETURN(ep);
1500Sstevel@tonic-gate 			} else ERROR(36);
1510Sstevel@tonic-gate 		case '*':
1520Sstevel@tonic-gate 			if (lastep == NULL || *lastep == CBRA ||
1530Sstevel@tonic-gate 			    *lastep == CKET)
1540Sstevel@tonic-gate 				goto defchar;
1550Sstevel@tonic-gate 			*lastep |= STAR;
1560Sstevel@tonic-gate 			continue;
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 		case '$':
1590Sstevel@tonic-gate 			if (PEEKC() != eof && PEEKC() != '\n')
1600Sstevel@tonic-gate 				goto defchar;
1610Sstevel@tonic-gate 			*ep++ = CDOL;
1620Sstevel@tonic-gate 			continue;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 		case '[':
1650Sstevel@tonic-gate 			if (&ep[17] >= endbuf)
1660Sstevel@tonic-gate 				ERROR(50);
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 			*ep++ = CCL;
1690Sstevel@tonic-gate 			lc = 0;
1700Sstevel@tonic-gate 			for (i = 0; i < 16; i++)
1710Sstevel@tonic-gate 				ep[i] = 0;
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 			neg = 0;
1740Sstevel@tonic-gate 			if ((c = GETC()) == '^') {
1750Sstevel@tonic-gate 				neg = 1;
1760Sstevel@tonic-gate 				c = GETC();
1770Sstevel@tonic-gate 			}
1780Sstevel@tonic-gate 			iflag = 1;
1790Sstevel@tonic-gate 			do {
1800Sstevel@tonic-gate 				c &= 0377;
1810Sstevel@tonic-gate 				if (c == '\0' || c == '\n')
1820Sstevel@tonic-gate 					ERROR(49);
1830Sstevel@tonic-gate 				if ((c & 0200) && iflag) {
1840Sstevel@tonic-gate 					iflag = 0;
1850Sstevel@tonic-gate 					if (&ep[32] >= endbuf)
1860Sstevel@tonic-gate 						ERROR(50);
1870Sstevel@tonic-gate 					ep[-1] = CXCL;
1880Sstevel@tonic-gate 					for (i = 16; i < 32; i++)
1890Sstevel@tonic-gate 						ep[i] = 0;
1900Sstevel@tonic-gate 				}
1910Sstevel@tonic-gate 				if (c == '-' && lc != 0) {
1920Sstevel@tonic-gate 					if ((c = GETC()) == ']') {
1930Sstevel@tonic-gate 						PLACE('-');
1940Sstevel@tonic-gate 						break;
1950Sstevel@tonic-gate 					}
1960Sstevel@tonic-gate 					if ((c & 0200) && iflag) {
1970Sstevel@tonic-gate 						iflag = 0;
1980Sstevel@tonic-gate 						if (&ep[32] >= endbuf)
1990Sstevel@tonic-gate 							ERROR(50);
2000Sstevel@tonic-gate 						ep[-1] = CXCL;
2010Sstevel@tonic-gate 						for (i = 16; i < 32; i++)
2020Sstevel@tonic-gate 							ep[i] = 0;
2030Sstevel@tonic-gate 					}
2040Sstevel@tonic-gate 					while (lc < c) {
2050Sstevel@tonic-gate 						PLACE(lc);
2060Sstevel@tonic-gate 						lc++;
2070Sstevel@tonic-gate 					}
2080Sstevel@tonic-gate 				}
2090Sstevel@tonic-gate 				lc = c;
2100Sstevel@tonic-gate 				PLACE(c);
2110Sstevel@tonic-gate 			} while ((c = GETC()) != ']');
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 			if (iflag)
2140Sstevel@tonic-gate 				iflag = 16;
2150Sstevel@tonic-gate 			else
2160Sstevel@tonic-gate 				iflag = 32;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 			if (neg) {
2190Sstevel@tonic-gate 				if (iflag == 32) {
2200Sstevel@tonic-gate 					for (cclcnt = 0; cclcnt < iflag;
2210Sstevel@tonic-gate 					    cclcnt++)
2220Sstevel@tonic-gate 						ep[cclcnt] ^= 0377;
2230Sstevel@tonic-gate 					ep[0] &= 0376;
2240Sstevel@tonic-gate 				} else {
2250Sstevel@tonic-gate 					ep[-1] = NCCL;
2260Sstevel@tonic-gate 					/* make nulls match so test fails */
2270Sstevel@tonic-gate 					ep[0] |= 01;
2280Sstevel@tonic-gate 				}
2290Sstevel@tonic-gate 			}
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 			ep += iflag;
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 			continue;
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 		case '\\':
2360Sstevel@tonic-gate 			switch (c = GETC()) {
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 			case '(':
2390Sstevel@tonic-gate 				if (nbra >= NBRA)
2400Sstevel@tonic-gate 					ERROR(43);
2410Sstevel@tonic-gate 				*bracketp++ = (char)nbra;
2420Sstevel@tonic-gate 				*ep++ = CBRA;
2430Sstevel@tonic-gate 				*ep++ = (char)nbra++;
2440Sstevel@tonic-gate 				continue;
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 			case ')':
2470Sstevel@tonic-gate 				if (bracketp <= bracket)
2480Sstevel@tonic-gate 					ERROR(42);
2490Sstevel@tonic-gate 				*ep++ = CKET;
2500Sstevel@tonic-gate 				*ep++ = *--bracketp;
2510Sstevel@tonic-gate 				closed++;
2520Sstevel@tonic-gate 				continue;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 			case '{':
2550Sstevel@tonic-gate 				if (lastep == NULL)
2560Sstevel@tonic-gate 					goto defchar;
2570Sstevel@tonic-gate 				*lastep |= RNGE;
2580Sstevel@tonic-gate 				cflg = 0;
2590Sstevel@tonic-gate 			nlim:
2600Sstevel@tonic-gate 				c = GETC();
2610Sstevel@tonic-gate 				i = 0;
2620Sstevel@tonic-gate 				do {
2630Sstevel@tonic-gate 					if ('0' <= c && c <= '9')
2640Sstevel@tonic-gate 						i = 10 * i + c - '0';
2650Sstevel@tonic-gate 					else
2660Sstevel@tonic-gate 						ERROR(16);
2670Sstevel@tonic-gate 				} while (((c = GETC()) != '\\') && (c != ','));
2680Sstevel@tonic-gate 				if (i >= 255)
2690Sstevel@tonic-gate 					ERROR(11);
2700Sstevel@tonic-gate 				*ep++ = (char)i;
2710Sstevel@tonic-gate 				if (c == ',') {
2720Sstevel@tonic-gate 					if (cflg++)
2730Sstevel@tonic-gate 						ERROR(44);
2740Sstevel@tonic-gate 					if ((c = GETC()) == '\\')
2750Sstevel@tonic-gate 						*ep++ = (char)255;
2760Sstevel@tonic-gate 					else {
2770Sstevel@tonic-gate 						UNGETC(c);
2780Sstevel@tonic-gate 						goto nlim;
2790Sstevel@tonic-gate 						/* get 2'nd number */
2800Sstevel@tonic-gate 					}
2810Sstevel@tonic-gate 				}
2820Sstevel@tonic-gate 				if (GETC() != '}')
2830Sstevel@tonic-gate 					ERROR(45);
2840Sstevel@tonic-gate 				if (!cflg)	/* one number */
2850Sstevel@tonic-gate 					*ep++ = (char)i;
2860Sstevel@tonic-gate 				else if ((ep[-1] & 0377) < (ep[-2] & 0377))
2870Sstevel@tonic-gate 					ERROR(46);
2880Sstevel@tonic-gate 				continue;
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 			case '\n':
2910Sstevel@tonic-gate 				ERROR(36);
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 			case 'n':
2940Sstevel@tonic-gate 				c = '\n';
2950Sstevel@tonic-gate 				goto defchar;
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 			default:
2980Sstevel@tonic-gate 				if (c >= '1' && c <= '9') {
2990Sstevel@tonic-gate 					if ((c -= '1') >= closed)
3000Sstevel@tonic-gate 						ERROR(25);
3010Sstevel@tonic-gate 					*ep++ = CBACK;
3020Sstevel@tonic-gate 					*ep++ = (char)c;
3030Sstevel@tonic-gate 					continue;
3040Sstevel@tonic-gate 				}
3050Sstevel@tonic-gate 			}
3060Sstevel@tonic-gate 	/* Drop through to default to use \ to turn off special chars */
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 		defchar:
3090Sstevel@tonic-gate 		default:
3100Sstevel@tonic-gate 			lastep = ep;
3110Sstevel@tonic-gate 			*ep++ = CCHR;
3120Sstevel@tonic-gate 			*ep++ = (char)c;
3130Sstevel@tonic-gate 		}
3140Sstevel@tonic-gate 	}
315*2712Snn35248 	/*NOTREACHED*/
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate #ifdef	__STDC__
3190Sstevel@tonic-gate int
step(const char * p1,const char * p2)3200Sstevel@tonic-gate step(const char *p1, const char *p2)
3210Sstevel@tonic-gate #else
3220Sstevel@tonic-gate int
3230Sstevel@tonic-gate step(p1, p2)
3240Sstevel@tonic-gate register char *p1, *p2;
3250Sstevel@tonic-gate #endif
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate 	char c;
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	if (circf) {
3310Sstevel@tonic-gate 		loc1 = (char *)p1;
3320Sstevel@tonic-gate 		return (advance(p1, p2));
3330Sstevel@tonic-gate 	}
3340Sstevel@tonic-gate 	/* fast check for first character */
3350Sstevel@tonic-gate 	if (*p2 == CCHR) {
3360Sstevel@tonic-gate 		c = p2[1];
3370Sstevel@tonic-gate 		do {
3380Sstevel@tonic-gate 			if (*p1 != c)
3390Sstevel@tonic-gate 				continue;
3400Sstevel@tonic-gate 			if (advance(p1, p2)) {
3410Sstevel@tonic-gate 				loc1 = (char *)p1;
3420Sstevel@tonic-gate 				return (1);
3430Sstevel@tonic-gate 			}
3440Sstevel@tonic-gate 		} while (*p1++);
3450Sstevel@tonic-gate 		return (0);
3460Sstevel@tonic-gate 	}
3470Sstevel@tonic-gate 		/* regular algorithm */
3480Sstevel@tonic-gate 	do {
3490Sstevel@tonic-gate 		if (advance(p1, p2)) {
3500Sstevel@tonic-gate 			loc1 = (char *)p1;
3510Sstevel@tonic-gate 			return (1);
3520Sstevel@tonic-gate 		}
3530Sstevel@tonic-gate 	} while (*p1++);
3540Sstevel@tonic-gate 	return (0);
3550Sstevel@tonic-gate }
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate int
3580Sstevel@tonic-gate #ifdef	__STDC__
advance(const char * lp,const char * ep)3590Sstevel@tonic-gate advance(const char *lp, const char *ep)
3600Sstevel@tonic-gate #else
3610Sstevel@tonic-gate advance(lp, ep)
3620Sstevel@tonic-gate register char *lp, *ep;
3630Sstevel@tonic-gate #endif
3640Sstevel@tonic-gate {
3650Sstevel@tonic-gate #ifdef	__STDC__
3660Sstevel@tonic-gate 	const char *curlp;
3670Sstevel@tonic-gate #else
3680Sstevel@tonic-gate 	register char *curlp;
3690Sstevel@tonic-gate #endif
3700Sstevel@tonic-gate 	int c;
3710Sstevel@tonic-gate 	char *bbeg;
3720Sstevel@tonic-gate 	register char neg;
3730Sstevel@tonic-gate 	size_t ct;
3740Sstevel@tonic-gate 
375*2712Snn35248 	for (;;) {
3760Sstevel@tonic-gate 		neg = 0;
3770Sstevel@tonic-gate 		switch (*ep++) {
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 		case CCHR:
3800Sstevel@tonic-gate 			if (*ep++ == *lp++)
3810Sstevel@tonic-gate 				continue;
3820Sstevel@tonic-gate 			return (0);
3830Sstevel@tonic-gate 			/*FALLTHRU*/
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 		case CDOT:
3860Sstevel@tonic-gate 			if (*lp++)
3870Sstevel@tonic-gate 				continue;
3880Sstevel@tonic-gate 			return (0);
3890Sstevel@tonic-gate 			/*FALLTHRU*/
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 		case CDOL:
3920Sstevel@tonic-gate 			if (*lp == 0)
3930Sstevel@tonic-gate 				continue;
3940Sstevel@tonic-gate 			return (0);
3950Sstevel@tonic-gate 			/*FALLTHRU*/
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 		case CCEOF:
3980Sstevel@tonic-gate 			loc2 = (char *)lp;
3990Sstevel@tonic-gate 			return (1);
4000Sstevel@tonic-gate 			/*FALLTHRU*/
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 		case CXCL:
4030Sstevel@tonic-gate 			c = (unsigned char)*lp++;
4040Sstevel@tonic-gate 			if (ISTHERE(c)) {
4050Sstevel@tonic-gate 				ep += 32;
4060Sstevel@tonic-gate 				continue;
4070Sstevel@tonic-gate 			}
4080Sstevel@tonic-gate 			return (0);
4090Sstevel@tonic-gate 			/*FALLTHRU*/
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 		case NCCL:
4120Sstevel@tonic-gate 			neg = 1;
4130Sstevel@tonic-gate 			/*FALLTHRU*/
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate 		case CCL:
4160Sstevel@tonic-gate 			c = *lp++;
4170Sstevel@tonic-gate 			if (((c & 0200) == 0 && ISTHERE(c)) ^ neg) {
4180Sstevel@tonic-gate 				ep += 16;
4190Sstevel@tonic-gate 				continue;
4200Sstevel@tonic-gate 			}
4210Sstevel@tonic-gate 			return (0);
4220Sstevel@tonic-gate 			/*FALLTHRU*/
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate 		case CBRA:
4250Sstevel@tonic-gate 			braslist[*ep++] = (char *)lp;
4260Sstevel@tonic-gate 			continue;
4270Sstevel@tonic-gate 			/*FALLTHRU*/
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate 		case CKET:
4300Sstevel@tonic-gate 			braelist[*ep++] = (char *)lp;
4310Sstevel@tonic-gate 			continue;
4320Sstevel@tonic-gate 			/*FALLTHRU*/
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 		case CCHR | RNGE:
4350Sstevel@tonic-gate 			c = *ep++;
4360Sstevel@tonic-gate 			getrnge(ep);
4370Sstevel@tonic-gate 			while (low--)
4380Sstevel@tonic-gate 				if (*lp++ != c)
4390Sstevel@tonic-gate 					return (0);
4400Sstevel@tonic-gate 			curlp = lp;
4410Sstevel@tonic-gate 			while (size--)
4420Sstevel@tonic-gate 				if (*lp++ != c)
4430Sstevel@tonic-gate 					break;
4440Sstevel@tonic-gate 			if (size < 0)
4450Sstevel@tonic-gate 				lp++;
4460Sstevel@tonic-gate 			ep += 2;
4470Sstevel@tonic-gate 			goto star;
4480Sstevel@tonic-gate 			/*FALLTHRU*/
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 		case CDOT | RNGE:
4510Sstevel@tonic-gate 			getrnge(ep);
4520Sstevel@tonic-gate 			while (low--)
4530Sstevel@tonic-gate 				if (*lp++ == '\0')
4540Sstevel@tonic-gate 					return (0);
4550Sstevel@tonic-gate 			curlp = lp;
4560Sstevel@tonic-gate 			while (size--)
4570Sstevel@tonic-gate 				if (*lp++ == '\0')
4580Sstevel@tonic-gate 					break;
4590Sstevel@tonic-gate 			if (size < 0)
4600Sstevel@tonic-gate 				lp++;
4610Sstevel@tonic-gate 			ep += 2;
4620Sstevel@tonic-gate 			goto star;
4630Sstevel@tonic-gate 			/*FALLTHRU*/
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 		case CXCL | RNGE:
4660Sstevel@tonic-gate 			getrnge(ep + 32);
4670Sstevel@tonic-gate 			while (low--) {
4680Sstevel@tonic-gate 				c = (unsigned char)*lp++;
4690Sstevel@tonic-gate 				if (!ISTHERE(c))
4700Sstevel@tonic-gate 					return (0);
4710Sstevel@tonic-gate 			}
4720Sstevel@tonic-gate 			curlp = lp;
4730Sstevel@tonic-gate 			while (size--) {
4740Sstevel@tonic-gate 				c = (unsigned char)*lp++;
4750Sstevel@tonic-gate 				if (!ISTHERE(c))
4760Sstevel@tonic-gate 					break;
4770Sstevel@tonic-gate 			}
4780Sstevel@tonic-gate 			if (size < 0)
4790Sstevel@tonic-gate 				lp++;
4800Sstevel@tonic-gate 			ep += 34;		/* 32 + 2 */
4810Sstevel@tonic-gate 			goto star;
4820Sstevel@tonic-gate 			/*FALLTHRU*/
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 		case NCCL | RNGE:
4850Sstevel@tonic-gate 			neg = 1;
4860Sstevel@tonic-gate 			/*FALLTHRU*/
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate 		case CCL | RNGE:
4890Sstevel@tonic-gate 			getrnge(ep + 16);
4900Sstevel@tonic-gate 			while (low--) {
4910Sstevel@tonic-gate 				c = *lp++;
4920Sstevel@tonic-gate 				if (((c & 0200) || !ISTHERE(c)) ^ neg)
4930Sstevel@tonic-gate 					return (0);
4940Sstevel@tonic-gate 			}
4950Sstevel@tonic-gate 			curlp = lp;
4960Sstevel@tonic-gate 			while (size--) {
4970Sstevel@tonic-gate 				c = *lp++;
4980Sstevel@tonic-gate 				if (((c & 0200) || !ISTHERE(c)) ^ neg)
4990Sstevel@tonic-gate 					break;
5000Sstevel@tonic-gate 			}
5010Sstevel@tonic-gate 			if (size < 0)
5020Sstevel@tonic-gate 				lp++;
5030Sstevel@tonic-gate 			ep += 18; 		/* 16 + 2 */
5040Sstevel@tonic-gate 			goto star;
5050Sstevel@tonic-gate 			/*FALLTHRU*/
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate 		case CBACK:
5080Sstevel@tonic-gate 			bbeg = braslist[*ep];
5090Sstevel@tonic-gate 			ct = braelist[*ep++] - bbeg;
5100Sstevel@tonic-gate 
5110Sstevel@tonic-gate 			if (ecmp(bbeg, lp, ct)) {
5120Sstevel@tonic-gate 				lp += ct;
5130Sstevel@tonic-gate 				continue;
5140Sstevel@tonic-gate 			}
5150Sstevel@tonic-gate 			return (0);
5160Sstevel@tonic-gate 			/*FALLTHRU*/
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 		case CBACK | STAR:
5190Sstevel@tonic-gate 			bbeg = braslist[*ep];
5200Sstevel@tonic-gate 			ct = braelist[*ep++] - bbeg;
5210Sstevel@tonic-gate 			curlp = lp;
5220Sstevel@tonic-gate 			while (ecmp(bbeg, lp, ct))
5230Sstevel@tonic-gate 				lp += ct;
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate 			while (lp >= curlp) {
5260Sstevel@tonic-gate 				if (advance(lp, ep))
5270Sstevel@tonic-gate 					return (1);
5280Sstevel@tonic-gate 				lp -= ct;
5290Sstevel@tonic-gate 			}
5300Sstevel@tonic-gate 			return (0);
5310Sstevel@tonic-gate 			/*FALLTHRU*/
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 		case CDOT | STAR:
5340Sstevel@tonic-gate 			curlp = lp;
5350Sstevel@tonic-gate 			while (*lp++);
5360Sstevel@tonic-gate 			goto star;
5370Sstevel@tonic-gate 			/*FALLTHRU*/
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate 		case CCHR | STAR:
5400Sstevel@tonic-gate 			curlp = lp;
5410Sstevel@tonic-gate 			while (*lp++ == *ep);
5420Sstevel@tonic-gate 			ep++;
5430Sstevel@tonic-gate 			goto star;
5440Sstevel@tonic-gate 			/*FALLTHRU*/
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate 		case CXCL | STAR:
5470Sstevel@tonic-gate 			curlp = lp;
5480Sstevel@tonic-gate 			do {
5490Sstevel@tonic-gate 				c = (unsigned char)*lp++;
5500Sstevel@tonic-gate 			} while (ISTHERE(c));
5510Sstevel@tonic-gate 			ep += 32;
5520Sstevel@tonic-gate 			goto star;
5530Sstevel@tonic-gate 			/*FALLTHRU*/
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate 		case NCCL | STAR:
5560Sstevel@tonic-gate 			neg = 1;
5570Sstevel@tonic-gate 			/*FALLTHRU*/
5580Sstevel@tonic-gate 
5590Sstevel@tonic-gate 		case CCL | STAR:
5600Sstevel@tonic-gate 			curlp = lp;
5610Sstevel@tonic-gate 			do {
5620Sstevel@tonic-gate 				c = *lp++;
5630Sstevel@tonic-gate 			} while (((c & 0200) == 0 && ISTHERE(c)) ^ neg);
5640Sstevel@tonic-gate 			ep += 16;
5650Sstevel@tonic-gate 			goto star;
5660Sstevel@tonic-gate 			/*FALLTHRU*/
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 		star:
5690Sstevel@tonic-gate 			do {
5700Sstevel@tonic-gate 				if (--lp == locs)
5710Sstevel@tonic-gate 					break;
5720Sstevel@tonic-gate 				if (advance(lp, ep))
5730Sstevel@tonic-gate 					return (1);
5740Sstevel@tonic-gate 			} while (lp > curlp);
5750Sstevel@tonic-gate 			return (0);
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate 		}
5780Sstevel@tonic-gate 	}
579*2712Snn35248 	/*NOTREACHED*/
5800Sstevel@tonic-gate }
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate static void
5830Sstevel@tonic-gate #ifdef	__STDC__
getrnge(const char * str)5840Sstevel@tonic-gate getrnge(const char *str)
5850Sstevel@tonic-gate #else
5860Sstevel@tonic-gate getrnge(str)
5870Sstevel@tonic-gate register char *str;
5880Sstevel@tonic-gate #endif
5890Sstevel@tonic-gate {
5900Sstevel@tonic-gate 	low = *str++ & 0377;
5910Sstevel@tonic-gate 	size = ((*str & 0377) == 255)? 20000: (*str &0377) - low;
5920Sstevel@tonic-gate }
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate #ifdef	__cplusplus
5950Sstevel@tonic-gate }
5960Sstevel@tonic-gate #endif
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate #endif	/* _REGEXP_H */
599