xref: /titanic_52/usr/src/head/regexp.h (revision ba3594ba9b5dd4c846c472a8d657edcb7c8109ac)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*
25*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
26*ba3594baSGarrett D'Amore  *
279acbbeafSnn35248  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _REGEXP_H
327c478bd9Sstevel@tonic-gate #define	_REGEXP_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	CBRA	2
417c478bd9Sstevel@tonic-gate #define	CCHR	4
427c478bd9Sstevel@tonic-gate #define	CDOT	8
437c478bd9Sstevel@tonic-gate #define	CCL	12
447c478bd9Sstevel@tonic-gate #define	CXCL	16
457c478bd9Sstevel@tonic-gate #define	CDOL	20
467c478bd9Sstevel@tonic-gate #define	CCEOF	22
477c478bd9Sstevel@tonic-gate #define	CKET	24
487c478bd9Sstevel@tonic-gate #define	CBACK	36
497c478bd9Sstevel@tonic-gate #define	NCCL	40
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	STAR	01
527c478bd9Sstevel@tonic-gate #define	RNGE	03
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #define	NBRA	9
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	PLACE(c)	ep[c >> 3] |= bittab[c & 07]
577c478bd9Sstevel@tonic-gate #define	ISTHERE(c)	(ep[c >> 3] & bittab[c & 07])
587c478bd9Sstevel@tonic-gate #define	ecmp(s1, s2, n)	(strncmp(s1, s2, n) == 0)
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate static char	*braslist[NBRA];
617c478bd9Sstevel@tonic-gate static char	*braelist[NBRA];
627c478bd9Sstevel@tonic-gate int	sed, nbra;
637c478bd9Sstevel@tonic-gate char	*loc1, *loc2, *locs;
647c478bd9Sstevel@tonic-gate static int	nodelim;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate int	circf;
677c478bd9Sstevel@tonic-gate static int	low;
687c478bd9Sstevel@tonic-gate static int	size;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate static unsigned char	bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate int advance(const char *lp, const char *ep);
737c478bd9Sstevel@tonic-gate static void getrnge(const char *str);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate char *
767c478bd9Sstevel@tonic-gate compile(char *instring, char *ep, const char *endbuf, int seof)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate 	INIT	/* Dependent declarations and initializations */
797c478bd9Sstevel@tonic-gate 	register int c;
807c478bd9Sstevel@tonic-gate 	register int eof = seof;
817c478bd9Sstevel@tonic-gate 	char *lastep;
827c478bd9Sstevel@tonic-gate 	int cclcnt;
837c478bd9Sstevel@tonic-gate 	char bracket[NBRA], *bracketp;
847c478bd9Sstevel@tonic-gate 	int closed;
857c478bd9Sstevel@tonic-gate 	int neg;
867c478bd9Sstevel@tonic-gate 	int lc;
877c478bd9Sstevel@tonic-gate 	int i, cflg;
887c478bd9Sstevel@tonic-gate 	int iflag; /* used for non-ascii characters in brackets */
897c478bd9Sstevel@tonic-gate 
909acbbeafSnn35248 #ifdef __lint
919acbbeafSnn35248 	/* make lint happy */
929acbbeafSnn35248 	c = nodelim;
939acbbeafSnn35248 #endif
949acbbeafSnn35248 
957c478bd9Sstevel@tonic-gate 	lastep = NULL;
967c478bd9Sstevel@tonic-gate 	if ((c = GETC()) == eof || c == '\n') {
977c478bd9Sstevel@tonic-gate 		if (c == '\n') {
987c478bd9Sstevel@tonic-gate 			UNGETC(c);
997c478bd9Sstevel@tonic-gate 			nodelim = 1;
1007c478bd9Sstevel@tonic-gate 		}
1017c478bd9Sstevel@tonic-gate 		if (*ep == 0 && !sed)
1027c478bd9Sstevel@tonic-gate 			ERROR(41);
1037c478bd9Sstevel@tonic-gate 		RETURN(ep);
1047c478bd9Sstevel@tonic-gate 	}
1057c478bd9Sstevel@tonic-gate 	bracketp = bracket;
1067c478bd9Sstevel@tonic-gate 	circf = closed = nbra = 0;
1077c478bd9Sstevel@tonic-gate 	if (c == '^')
1087c478bd9Sstevel@tonic-gate 		circf++;
1097c478bd9Sstevel@tonic-gate 	else
1107c478bd9Sstevel@tonic-gate 		UNGETC(c);
1119acbbeafSnn35248 	for (;;) {
1127c478bd9Sstevel@tonic-gate 		if (ep >= endbuf)
1137c478bd9Sstevel@tonic-gate 			ERROR(50);
1147c478bd9Sstevel@tonic-gate 		c = GETC();
1157c478bd9Sstevel@tonic-gate 		if (c != '*' && ((c != '\\') || (PEEKC() != '{')))
1167c478bd9Sstevel@tonic-gate 			lastep = ep;
1177c478bd9Sstevel@tonic-gate 		if (c == eof) {
1187c478bd9Sstevel@tonic-gate 			*ep++ = CCEOF;
1197c478bd9Sstevel@tonic-gate 			if (bracketp != bracket)
1207c478bd9Sstevel@tonic-gate 				ERROR(42);
1217c478bd9Sstevel@tonic-gate 			RETURN(ep);
1227c478bd9Sstevel@tonic-gate 		}
1237c478bd9Sstevel@tonic-gate 		switch (c) {
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 		case '.':
1267c478bd9Sstevel@tonic-gate 			*ep++ = CDOT;
1277c478bd9Sstevel@tonic-gate 			continue;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 		case '\n':
1307c478bd9Sstevel@tonic-gate 			if (!sed) {
1317c478bd9Sstevel@tonic-gate 				UNGETC(c);
1327c478bd9Sstevel@tonic-gate 				*ep++ = CCEOF;
1337c478bd9Sstevel@tonic-gate 				nodelim = 1;
1347c478bd9Sstevel@tonic-gate 				if (bracketp != bracket)
1357c478bd9Sstevel@tonic-gate 					ERROR(42);
1367c478bd9Sstevel@tonic-gate 				RETURN(ep);
1377c478bd9Sstevel@tonic-gate 			} else ERROR(36);
1387c478bd9Sstevel@tonic-gate 		case '*':
1397c478bd9Sstevel@tonic-gate 			if (lastep == NULL || *lastep == CBRA ||
1407c478bd9Sstevel@tonic-gate 			    *lastep == CKET)
1417c478bd9Sstevel@tonic-gate 				goto defchar;
1427c478bd9Sstevel@tonic-gate 			*lastep |= STAR;
1437c478bd9Sstevel@tonic-gate 			continue;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 		case '$':
1467c478bd9Sstevel@tonic-gate 			if (PEEKC() != eof && PEEKC() != '\n')
1477c478bd9Sstevel@tonic-gate 				goto defchar;
1487c478bd9Sstevel@tonic-gate 			*ep++ = CDOL;
1497c478bd9Sstevel@tonic-gate 			continue;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 		case '[':
1527c478bd9Sstevel@tonic-gate 			if (&ep[17] >= endbuf)
1537c478bd9Sstevel@tonic-gate 				ERROR(50);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 			*ep++ = CCL;
1567c478bd9Sstevel@tonic-gate 			lc = 0;
1577c478bd9Sstevel@tonic-gate 			for (i = 0; i < 16; i++)
1587c478bd9Sstevel@tonic-gate 				ep[i] = 0;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 			neg = 0;
1617c478bd9Sstevel@tonic-gate 			if ((c = GETC()) == '^') {
1627c478bd9Sstevel@tonic-gate 				neg = 1;
1637c478bd9Sstevel@tonic-gate 				c = GETC();
1647c478bd9Sstevel@tonic-gate 			}
1657c478bd9Sstevel@tonic-gate 			iflag = 1;
1667c478bd9Sstevel@tonic-gate 			do {
1677c478bd9Sstevel@tonic-gate 				c &= 0377;
1687c478bd9Sstevel@tonic-gate 				if (c == '\0' || c == '\n')
1697c478bd9Sstevel@tonic-gate 					ERROR(49);
1707c478bd9Sstevel@tonic-gate 				if ((c & 0200) && iflag) {
1717c478bd9Sstevel@tonic-gate 					iflag = 0;
1727c478bd9Sstevel@tonic-gate 					if (&ep[32] >= endbuf)
1737c478bd9Sstevel@tonic-gate 						ERROR(50);
1747c478bd9Sstevel@tonic-gate 					ep[-1] = CXCL;
1757c478bd9Sstevel@tonic-gate 					for (i = 16; i < 32; i++)
1767c478bd9Sstevel@tonic-gate 						ep[i] = 0;
1777c478bd9Sstevel@tonic-gate 				}
1787c478bd9Sstevel@tonic-gate 				if (c == '-' && lc != 0) {
1797c478bd9Sstevel@tonic-gate 					if ((c = GETC()) == ']') {
1807c478bd9Sstevel@tonic-gate 						PLACE('-');
1817c478bd9Sstevel@tonic-gate 						break;
1827c478bd9Sstevel@tonic-gate 					}
1837c478bd9Sstevel@tonic-gate 					if ((c & 0200) && iflag) {
1847c478bd9Sstevel@tonic-gate 						iflag = 0;
1857c478bd9Sstevel@tonic-gate 						if (&ep[32] >= endbuf)
1867c478bd9Sstevel@tonic-gate 							ERROR(50);
1877c478bd9Sstevel@tonic-gate 						ep[-1] = CXCL;
1887c478bd9Sstevel@tonic-gate 						for (i = 16; i < 32; i++)
1897c478bd9Sstevel@tonic-gate 							ep[i] = 0;
1907c478bd9Sstevel@tonic-gate 					}
1917c478bd9Sstevel@tonic-gate 					while (lc < c) {
1927c478bd9Sstevel@tonic-gate 						PLACE(lc);
1937c478bd9Sstevel@tonic-gate 						lc++;
1947c478bd9Sstevel@tonic-gate 					}
1957c478bd9Sstevel@tonic-gate 				}
1967c478bd9Sstevel@tonic-gate 				lc = c;
1977c478bd9Sstevel@tonic-gate 				PLACE(c);
1987c478bd9Sstevel@tonic-gate 			} while ((c = GETC()) != ']');
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 			if (iflag)
2017c478bd9Sstevel@tonic-gate 				iflag = 16;
2027c478bd9Sstevel@tonic-gate 			else
2037c478bd9Sstevel@tonic-gate 				iflag = 32;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 			if (neg) {
2067c478bd9Sstevel@tonic-gate 				if (iflag == 32) {
2077c478bd9Sstevel@tonic-gate 					for (cclcnt = 0; cclcnt < iflag;
2087c478bd9Sstevel@tonic-gate 					    cclcnt++)
2097c478bd9Sstevel@tonic-gate 						ep[cclcnt] ^= 0377;
2107c478bd9Sstevel@tonic-gate 					ep[0] &= 0376;
2117c478bd9Sstevel@tonic-gate 				} else {
2127c478bd9Sstevel@tonic-gate 					ep[-1] = NCCL;
2137c478bd9Sstevel@tonic-gate 					/* make nulls match so test fails */
2147c478bd9Sstevel@tonic-gate 					ep[0] |= 01;
2157c478bd9Sstevel@tonic-gate 				}
2167c478bd9Sstevel@tonic-gate 			}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 			ep += iflag;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 			continue;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 		case '\\':
2237c478bd9Sstevel@tonic-gate 			switch (c = GETC()) {
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 			case '(':
2267c478bd9Sstevel@tonic-gate 				if (nbra >= NBRA)
2277c478bd9Sstevel@tonic-gate 					ERROR(43);
2287c478bd9Sstevel@tonic-gate 				*bracketp++ = (char)nbra;
2297c478bd9Sstevel@tonic-gate 				*ep++ = CBRA;
2307c478bd9Sstevel@tonic-gate 				*ep++ = (char)nbra++;
2317c478bd9Sstevel@tonic-gate 				continue;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 			case ')':
2347c478bd9Sstevel@tonic-gate 				if (bracketp <= bracket)
2357c478bd9Sstevel@tonic-gate 					ERROR(42);
2367c478bd9Sstevel@tonic-gate 				*ep++ = CKET;
2377c478bd9Sstevel@tonic-gate 				*ep++ = *--bracketp;
2387c478bd9Sstevel@tonic-gate 				closed++;
2397c478bd9Sstevel@tonic-gate 				continue;
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 			case '{':
2427c478bd9Sstevel@tonic-gate 				if (lastep == NULL)
2437c478bd9Sstevel@tonic-gate 					goto defchar;
2447c478bd9Sstevel@tonic-gate 				*lastep |= RNGE;
2457c478bd9Sstevel@tonic-gate 				cflg = 0;
2467c478bd9Sstevel@tonic-gate 			nlim:
2477c478bd9Sstevel@tonic-gate 				c = GETC();
2487c478bd9Sstevel@tonic-gate 				i = 0;
2497c478bd9Sstevel@tonic-gate 				do {
2507c478bd9Sstevel@tonic-gate 					if ('0' <= c && c <= '9')
2517c478bd9Sstevel@tonic-gate 						i = 10 * i + c - '0';
2527c478bd9Sstevel@tonic-gate 					else
2537c478bd9Sstevel@tonic-gate 						ERROR(16);
2547c478bd9Sstevel@tonic-gate 				} while (((c = GETC()) != '\\') && (c != ','));
2557c478bd9Sstevel@tonic-gate 				if (i >= 255)
2567c478bd9Sstevel@tonic-gate 					ERROR(11);
2577c478bd9Sstevel@tonic-gate 				*ep++ = (char)i;
2587c478bd9Sstevel@tonic-gate 				if (c == ',') {
2597c478bd9Sstevel@tonic-gate 					if (cflg++)
2607c478bd9Sstevel@tonic-gate 						ERROR(44);
2617c478bd9Sstevel@tonic-gate 					if ((c = GETC()) == '\\')
2627c478bd9Sstevel@tonic-gate 						*ep++ = (char)255;
2637c478bd9Sstevel@tonic-gate 					else {
2647c478bd9Sstevel@tonic-gate 						UNGETC(c);
2657c478bd9Sstevel@tonic-gate 						goto nlim;
2667c478bd9Sstevel@tonic-gate 						/* get 2'nd number */
2677c478bd9Sstevel@tonic-gate 					}
2687c478bd9Sstevel@tonic-gate 				}
2697c478bd9Sstevel@tonic-gate 				if (GETC() != '}')
2707c478bd9Sstevel@tonic-gate 					ERROR(45);
2717c478bd9Sstevel@tonic-gate 				if (!cflg)	/* one number */
2727c478bd9Sstevel@tonic-gate 					*ep++ = (char)i;
2737c478bd9Sstevel@tonic-gate 				else if ((ep[-1] & 0377) < (ep[-2] & 0377))
2747c478bd9Sstevel@tonic-gate 					ERROR(46);
2757c478bd9Sstevel@tonic-gate 				continue;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 			case '\n':
2787c478bd9Sstevel@tonic-gate 				ERROR(36);
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 			case 'n':
2817c478bd9Sstevel@tonic-gate 				c = '\n';
2827c478bd9Sstevel@tonic-gate 				goto defchar;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 			default:
2857c478bd9Sstevel@tonic-gate 				if (c >= '1' && c <= '9') {
2867c478bd9Sstevel@tonic-gate 					if ((c -= '1') >= closed)
2877c478bd9Sstevel@tonic-gate 						ERROR(25);
2887c478bd9Sstevel@tonic-gate 					*ep++ = CBACK;
2897c478bd9Sstevel@tonic-gate 					*ep++ = (char)c;
2907c478bd9Sstevel@tonic-gate 					continue;
2917c478bd9Sstevel@tonic-gate 				}
2927c478bd9Sstevel@tonic-gate 			}
2937c478bd9Sstevel@tonic-gate 	/* Drop through to default to use \ to turn off special chars */
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 		defchar:
2967c478bd9Sstevel@tonic-gate 		default:
2977c478bd9Sstevel@tonic-gate 			lastep = ep;
2987c478bd9Sstevel@tonic-gate 			*ep++ = CCHR;
2997c478bd9Sstevel@tonic-gate 			*ep++ = (char)c;
3007c478bd9Sstevel@tonic-gate 		}
3017c478bd9Sstevel@tonic-gate 	}
3029acbbeafSnn35248 	/*NOTREACHED*/
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate int
3067c478bd9Sstevel@tonic-gate step(const char *p1, const char *p2)
3077c478bd9Sstevel@tonic-gate {
3087c478bd9Sstevel@tonic-gate 	char c;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	if (circf) {
3127c478bd9Sstevel@tonic-gate 		loc1 = (char *)p1;
3137c478bd9Sstevel@tonic-gate 		return (advance(p1, p2));
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 	/* fast check for first character */
3167c478bd9Sstevel@tonic-gate 	if (*p2 == CCHR) {
3177c478bd9Sstevel@tonic-gate 		c = p2[1];
3187c478bd9Sstevel@tonic-gate 		do {
3197c478bd9Sstevel@tonic-gate 			if (*p1 != c)
3207c478bd9Sstevel@tonic-gate 				continue;
3217c478bd9Sstevel@tonic-gate 			if (advance(p1, p2)) {
3227c478bd9Sstevel@tonic-gate 				loc1 = (char *)p1;
3237c478bd9Sstevel@tonic-gate 				return (1);
3247c478bd9Sstevel@tonic-gate 			}
3257c478bd9Sstevel@tonic-gate 		} while (*p1++);
3267c478bd9Sstevel@tonic-gate 		return (0);
3277c478bd9Sstevel@tonic-gate 	}
3287c478bd9Sstevel@tonic-gate 		/* regular algorithm */
3297c478bd9Sstevel@tonic-gate 	do {
3307c478bd9Sstevel@tonic-gate 		if (advance(p1, p2)) {
3317c478bd9Sstevel@tonic-gate 			loc1 = (char *)p1;
3327c478bd9Sstevel@tonic-gate 			return (1);
3337c478bd9Sstevel@tonic-gate 		}
3347c478bd9Sstevel@tonic-gate 	} while (*p1++);
3357c478bd9Sstevel@tonic-gate 	return (0);
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate int
3397c478bd9Sstevel@tonic-gate advance(const char *lp, const char *ep)
3407c478bd9Sstevel@tonic-gate {
3417c478bd9Sstevel@tonic-gate 	const char *curlp;
3427c478bd9Sstevel@tonic-gate 	int c;
3437c478bd9Sstevel@tonic-gate 	char *bbeg;
3447c478bd9Sstevel@tonic-gate 	register char neg;
3457c478bd9Sstevel@tonic-gate 	size_t ct;
3467c478bd9Sstevel@tonic-gate 
3479acbbeafSnn35248 	for (;;) {
3487c478bd9Sstevel@tonic-gate 		neg = 0;
3497c478bd9Sstevel@tonic-gate 		switch (*ep++) {
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 		case CCHR:
3527c478bd9Sstevel@tonic-gate 			if (*ep++ == *lp++)
3537c478bd9Sstevel@tonic-gate 				continue;
3547c478bd9Sstevel@tonic-gate 			return (0);
3557c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 		case CDOT:
3587c478bd9Sstevel@tonic-gate 			if (*lp++)
3597c478bd9Sstevel@tonic-gate 				continue;
3607c478bd9Sstevel@tonic-gate 			return (0);
3617c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 		case CDOL:
3647c478bd9Sstevel@tonic-gate 			if (*lp == 0)
3657c478bd9Sstevel@tonic-gate 				continue;
3667c478bd9Sstevel@tonic-gate 			return (0);
3677c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		case CCEOF:
3707c478bd9Sstevel@tonic-gate 			loc2 = (char *)lp;
3717c478bd9Sstevel@tonic-gate 			return (1);
3727c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 		case CXCL:
3757c478bd9Sstevel@tonic-gate 			c = (unsigned char)*lp++;
3767c478bd9Sstevel@tonic-gate 			if (ISTHERE(c)) {
3777c478bd9Sstevel@tonic-gate 				ep += 32;
3787c478bd9Sstevel@tonic-gate 				continue;
3797c478bd9Sstevel@tonic-gate 			}
3807c478bd9Sstevel@tonic-gate 			return (0);
3817c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 		case NCCL:
3847c478bd9Sstevel@tonic-gate 			neg = 1;
3857c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 		case CCL:
3887c478bd9Sstevel@tonic-gate 			c = *lp++;
3897c478bd9Sstevel@tonic-gate 			if (((c & 0200) == 0 && ISTHERE(c)) ^ neg) {
3907c478bd9Sstevel@tonic-gate 				ep += 16;
3917c478bd9Sstevel@tonic-gate 				continue;
3927c478bd9Sstevel@tonic-gate 			}
3937c478bd9Sstevel@tonic-gate 			return (0);
3947c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 		case CBRA:
3977c478bd9Sstevel@tonic-gate 			braslist[*ep++] = (char *)lp;
3987c478bd9Sstevel@tonic-gate 			continue;
3997c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 		case CKET:
4027c478bd9Sstevel@tonic-gate 			braelist[*ep++] = (char *)lp;
4037c478bd9Sstevel@tonic-gate 			continue;
4047c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 		case CCHR | RNGE:
4077c478bd9Sstevel@tonic-gate 			c = *ep++;
4087c478bd9Sstevel@tonic-gate 			getrnge(ep);
4097c478bd9Sstevel@tonic-gate 			while (low--)
4107c478bd9Sstevel@tonic-gate 				if (*lp++ != c)
4117c478bd9Sstevel@tonic-gate 					return (0);
4127c478bd9Sstevel@tonic-gate 			curlp = lp;
4137c478bd9Sstevel@tonic-gate 			while (size--)
4147c478bd9Sstevel@tonic-gate 				if (*lp++ != c)
4157c478bd9Sstevel@tonic-gate 					break;
4167c478bd9Sstevel@tonic-gate 			if (size < 0)
4177c478bd9Sstevel@tonic-gate 				lp++;
4187c478bd9Sstevel@tonic-gate 			ep += 2;
4197c478bd9Sstevel@tonic-gate 			goto star;
4207c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 		case CDOT | RNGE:
4237c478bd9Sstevel@tonic-gate 			getrnge(ep);
4247c478bd9Sstevel@tonic-gate 			while (low--)
4257c478bd9Sstevel@tonic-gate 				if (*lp++ == '\0')
4267c478bd9Sstevel@tonic-gate 					return (0);
4277c478bd9Sstevel@tonic-gate 			curlp = lp;
4287c478bd9Sstevel@tonic-gate 			while (size--)
4297c478bd9Sstevel@tonic-gate 				if (*lp++ == '\0')
4307c478bd9Sstevel@tonic-gate 					break;
4317c478bd9Sstevel@tonic-gate 			if (size < 0)
4327c478bd9Sstevel@tonic-gate 				lp++;
4337c478bd9Sstevel@tonic-gate 			ep += 2;
4347c478bd9Sstevel@tonic-gate 			goto star;
4357c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 		case CXCL | RNGE:
4387c478bd9Sstevel@tonic-gate 			getrnge(ep + 32);
4397c478bd9Sstevel@tonic-gate 			while (low--) {
4407c478bd9Sstevel@tonic-gate 				c = (unsigned char)*lp++;
4417c478bd9Sstevel@tonic-gate 				if (!ISTHERE(c))
4427c478bd9Sstevel@tonic-gate 					return (0);
4437c478bd9Sstevel@tonic-gate 			}
4447c478bd9Sstevel@tonic-gate 			curlp = lp;
4457c478bd9Sstevel@tonic-gate 			while (size--) {
4467c478bd9Sstevel@tonic-gate 				c = (unsigned char)*lp++;
4477c478bd9Sstevel@tonic-gate 				if (!ISTHERE(c))
4487c478bd9Sstevel@tonic-gate 					break;
4497c478bd9Sstevel@tonic-gate 			}
4507c478bd9Sstevel@tonic-gate 			if (size < 0)
4517c478bd9Sstevel@tonic-gate 				lp++;
4527c478bd9Sstevel@tonic-gate 			ep += 34;		/* 32 + 2 */
4537c478bd9Sstevel@tonic-gate 			goto star;
4547c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 		case NCCL | RNGE:
4577c478bd9Sstevel@tonic-gate 			neg = 1;
4587c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 		case CCL | RNGE:
4617c478bd9Sstevel@tonic-gate 			getrnge(ep + 16);
4627c478bd9Sstevel@tonic-gate 			while (low--) {
4637c478bd9Sstevel@tonic-gate 				c = *lp++;
4647c478bd9Sstevel@tonic-gate 				if (((c & 0200) || !ISTHERE(c)) ^ neg)
4657c478bd9Sstevel@tonic-gate 					return (0);
4667c478bd9Sstevel@tonic-gate 			}
4677c478bd9Sstevel@tonic-gate 			curlp = lp;
4687c478bd9Sstevel@tonic-gate 			while (size--) {
4697c478bd9Sstevel@tonic-gate 				c = *lp++;
4707c478bd9Sstevel@tonic-gate 				if (((c & 0200) || !ISTHERE(c)) ^ neg)
4717c478bd9Sstevel@tonic-gate 					break;
4727c478bd9Sstevel@tonic-gate 			}
4737c478bd9Sstevel@tonic-gate 			if (size < 0)
4747c478bd9Sstevel@tonic-gate 				lp++;
4757c478bd9Sstevel@tonic-gate 			ep += 18; 		/* 16 + 2 */
4767c478bd9Sstevel@tonic-gate 			goto star;
4777c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 		case CBACK:
4807c478bd9Sstevel@tonic-gate 			bbeg = braslist[*ep];
4817c478bd9Sstevel@tonic-gate 			ct = braelist[*ep++] - bbeg;
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 			if (ecmp(bbeg, lp, ct)) {
4847c478bd9Sstevel@tonic-gate 				lp += ct;
4857c478bd9Sstevel@tonic-gate 				continue;
4867c478bd9Sstevel@tonic-gate 			}
4877c478bd9Sstevel@tonic-gate 			return (0);
4887c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 		case CBACK | STAR:
4917c478bd9Sstevel@tonic-gate 			bbeg = braslist[*ep];
4927c478bd9Sstevel@tonic-gate 			ct = braelist[*ep++] - bbeg;
4937c478bd9Sstevel@tonic-gate 			curlp = lp;
4947c478bd9Sstevel@tonic-gate 			while (ecmp(bbeg, lp, ct))
4957c478bd9Sstevel@tonic-gate 				lp += ct;
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 			while (lp >= curlp) {
4987c478bd9Sstevel@tonic-gate 				if (advance(lp, ep))
4997c478bd9Sstevel@tonic-gate 					return (1);
5007c478bd9Sstevel@tonic-gate 				lp -= ct;
5017c478bd9Sstevel@tonic-gate 			}
5027c478bd9Sstevel@tonic-gate 			return (0);
5037c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 		case CDOT | STAR:
5067c478bd9Sstevel@tonic-gate 			curlp = lp;
5077c478bd9Sstevel@tonic-gate 			while (*lp++);
5087c478bd9Sstevel@tonic-gate 			goto star;
5097c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 		case CCHR | STAR:
5127c478bd9Sstevel@tonic-gate 			curlp = lp;
5137c478bd9Sstevel@tonic-gate 			while (*lp++ == *ep);
5147c478bd9Sstevel@tonic-gate 			ep++;
5157c478bd9Sstevel@tonic-gate 			goto star;
5167c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 		case CXCL | STAR:
5197c478bd9Sstevel@tonic-gate 			curlp = lp;
5207c478bd9Sstevel@tonic-gate 			do {
5217c478bd9Sstevel@tonic-gate 				c = (unsigned char)*lp++;
5227c478bd9Sstevel@tonic-gate 			} while (ISTHERE(c));
5237c478bd9Sstevel@tonic-gate 			ep += 32;
5247c478bd9Sstevel@tonic-gate 			goto star;
5257c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 		case NCCL | STAR:
5287c478bd9Sstevel@tonic-gate 			neg = 1;
5297c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 		case CCL | STAR:
5327c478bd9Sstevel@tonic-gate 			curlp = lp;
5337c478bd9Sstevel@tonic-gate 			do {
5347c478bd9Sstevel@tonic-gate 				c = *lp++;
5357c478bd9Sstevel@tonic-gate 			} while (((c & 0200) == 0 && ISTHERE(c)) ^ neg);
5367c478bd9Sstevel@tonic-gate 			ep += 16;
5377c478bd9Sstevel@tonic-gate 			goto star;
5387c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 		star:
5417c478bd9Sstevel@tonic-gate 			do {
5427c478bd9Sstevel@tonic-gate 				if (--lp == locs)
5437c478bd9Sstevel@tonic-gate 					break;
5447c478bd9Sstevel@tonic-gate 				if (advance(lp, ep))
5457c478bd9Sstevel@tonic-gate 					return (1);
5467c478bd9Sstevel@tonic-gate 			} while (lp > curlp);
5477c478bd9Sstevel@tonic-gate 			return (0);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 		}
5507c478bd9Sstevel@tonic-gate 	}
5519acbbeafSnn35248 	/*NOTREACHED*/
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate static void
5557c478bd9Sstevel@tonic-gate getrnge(const char *str)
5567c478bd9Sstevel@tonic-gate {
5577c478bd9Sstevel@tonic-gate 	low = *str++ & 0377;
5587c478bd9Sstevel@tonic-gate 	size = ((*str & 0377) == 255)? 20000: (*str &0377) - low;
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5627c478bd9Sstevel@tonic-gate }
5637c478bd9Sstevel@tonic-gate #endif
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate #endif	/* _REGEXP_H */
566