xref: /illumos-gate/usr/src/head/regexp.h (revision 7f24fc96)
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
59acbbeafSnn  * Common Development and Distribution License (the "License").
69acbbeafSnn  * 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	*/
226e270ca8SMarcel Telka /*	  All Rights Reserved	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*
25ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
26ba3594baSGarrett D'Amore  *
279acbbeafSnn  * 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 *
compile(char * instring,char * ep,const char * endbuf,int seof)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 
909acbbeafSnn #ifdef __lint
919acbbeafSnn 	/* make lint happy */
929acbbeafSnn 	c = nodelim;
939acbbeafSnn #endif
949acbbeafSnn 
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);
1119acbbeafSnn 	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 				}
292*7f24fc96SToomas Soome 				/* FALLTHROUGH */
2937c478bd9Sstevel@tonic-gate 			}
294*7f24fc96SToomas Soome 			/* FALLTHROUGH */
2957c478bd9Sstevel@tonic-gate 	/* Drop through to default to use \ to turn off special chars */
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 		defchar:
2987c478bd9Sstevel@tonic-gate 		default:
2997c478bd9Sstevel@tonic-gate 			lastep = ep;
3007c478bd9Sstevel@tonic-gate 			*ep++ = CCHR;
3017c478bd9Sstevel@tonic-gate 			*ep++ = (char)c;
3027c478bd9Sstevel@tonic-gate 		}
3037c478bd9Sstevel@tonic-gate 	}
3049acbbeafSnn 	/*NOTREACHED*/
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate int
step(const char * p1,const char * p2)3087c478bd9Sstevel@tonic-gate step(const char *p1, const char *p2)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate 	char c;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	if (circf) {
3147c478bd9Sstevel@tonic-gate 		loc1 = (char *)p1;
3157c478bd9Sstevel@tonic-gate 		return (advance(p1, p2));
3167c478bd9Sstevel@tonic-gate 	}
3177c478bd9Sstevel@tonic-gate 	/* fast check for first character */
3187c478bd9Sstevel@tonic-gate 	if (*p2 == CCHR) {
3197c478bd9Sstevel@tonic-gate 		c = p2[1];
3207c478bd9Sstevel@tonic-gate 		do {
3217c478bd9Sstevel@tonic-gate 			if (*p1 != c)
3227c478bd9Sstevel@tonic-gate 				continue;
3237c478bd9Sstevel@tonic-gate 			if (advance(p1, p2)) {
3247c478bd9Sstevel@tonic-gate 				loc1 = (char *)p1;
3257c478bd9Sstevel@tonic-gate 				return (1);
3267c478bd9Sstevel@tonic-gate 			}
3277c478bd9Sstevel@tonic-gate 		} while (*p1++);
3287c478bd9Sstevel@tonic-gate 		return (0);
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 		/* regular algorithm */
3317c478bd9Sstevel@tonic-gate 	do {
3327c478bd9Sstevel@tonic-gate 		if (advance(p1, p2)) {
3337c478bd9Sstevel@tonic-gate 			loc1 = (char *)p1;
3347c478bd9Sstevel@tonic-gate 			return (1);
3357c478bd9Sstevel@tonic-gate 		}
3367c478bd9Sstevel@tonic-gate 	} while (*p1++);
3377c478bd9Sstevel@tonic-gate 	return (0);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate int
advance(const char * lp,const char * ep)3417c478bd9Sstevel@tonic-gate advance(const char *lp, const char *ep)
3427c478bd9Sstevel@tonic-gate {
3437c478bd9Sstevel@tonic-gate 	const char *curlp;
3447c478bd9Sstevel@tonic-gate 	int c;
3457c478bd9Sstevel@tonic-gate 	char *bbeg;
3467c478bd9Sstevel@tonic-gate 	register char neg;
3477c478bd9Sstevel@tonic-gate 	size_t ct;
3487c478bd9Sstevel@tonic-gate 
3499acbbeafSnn 	for (;;) {
3507c478bd9Sstevel@tonic-gate 		neg = 0;
3517c478bd9Sstevel@tonic-gate 		switch (*ep++) {
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 		case CCHR:
3547c478bd9Sstevel@tonic-gate 			if (*ep++ == *lp++)
3557c478bd9Sstevel@tonic-gate 				continue;
3567c478bd9Sstevel@tonic-gate 			return (0);
3577c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 		case CDOT:
3607c478bd9Sstevel@tonic-gate 			if (*lp++)
3617c478bd9Sstevel@tonic-gate 				continue;
3627c478bd9Sstevel@tonic-gate 			return (0);
3637c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 		case CDOL:
3667c478bd9Sstevel@tonic-gate 			if (*lp == 0)
3677c478bd9Sstevel@tonic-gate 				continue;
3687c478bd9Sstevel@tonic-gate 			return (0);
3697c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 		case CCEOF:
3727c478bd9Sstevel@tonic-gate 			loc2 = (char *)lp;
3737c478bd9Sstevel@tonic-gate 			return (1);
3747c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 		case CXCL:
3777c478bd9Sstevel@tonic-gate 			c = (unsigned char)*lp++;
3787c478bd9Sstevel@tonic-gate 			if (ISTHERE(c)) {
3797c478bd9Sstevel@tonic-gate 				ep += 32;
3807c478bd9Sstevel@tonic-gate 				continue;
3817c478bd9Sstevel@tonic-gate 			}
3827c478bd9Sstevel@tonic-gate 			return (0);
3837c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 		case NCCL:
3867c478bd9Sstevel@tonic-gate 			neg = 1;
3877c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 		case CCL:
3907c478bd9Sstevel@tonic-gate 			c = *lp++;
3917c478bd9Sstevel@tonic-gate 			if (((c & 0200) == 0 && ISTHERE(c)) ^ neg) {
3927c478bd9Sstevel@tonic-gate 				ep += 16;
3937c478bd9Sstevel@tonic-gate 				continue;
3947c478bd9Sstevel@tonic-gate 			}
3957c478bd9Sstevel@tonic-gate 			return (0);
3967c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 		case CBRA:
3997c478bd9Sstevel@tonic-gate 			braslist[*ep++] = (char *)lp;
4007c478bd9Sstevel@tonic-gate 			continue;
4017c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 		case CKET:
4047c478bd9Sstevel@tonic-gate 			braelist[*ep++] = (char *)lp;
4057c478bd9Sstevel@tonic-gate 			continue;
4067c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 		case CCHR | RNGE:
4097c478bd9Sstevel@tonic-gate 			c = *ep++;
4107c478bd9Sstevel@tonic-gate 			getrnge(ep);
4117c478bd9Sstevel@tonic-gate 			while (low--)
4127c478bd9Sstevel@tonic-gate 				if (*lp++ != c)
4137c478bd9Sstevel@tonic-gate 					return (0);
4147c478bd9Sstevel@tonic-gate 			curlp = lp;
4157c478bd9Sstevel@tonic-gate 			while (size--)
4167c478bd9Sstevel@tonic-gate 				if (*lp++ != c)
4177c478bd9Sstevel@tonic-gate 					break;
4187c478bd9Sstevel@tonic-gate 			if (size < 0)
4197c478bd9Sstevel@tonic-gate 				lp++;
4207c478bd9Sstevel@tonic-gate 			ep += 2;
4217c478bd9Sstevel@tonic-gate 			goto star;
4227c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 		case CDOT | RNGE:
4257c478bd9Sstevel@tonic-gate 			getrnge(ep);
4267c478bd9Sstevel@tonic-gate 			while (low--)
4277c478bd9Sstevel@tonic-gate 				if (*lp++ == '\0')
4287c478bd9Sstevel@tonic-gate 					return (0);
4297c478bd9Sstevel@tonic-gate 			curlp = lp;
4307c478bd9Sstevel@tonic-gate 			while (size--)
4317c478bd9Sstevel@tonic-gate 				if (*lp++ == '\0')
4327c478bd9Sstevel@tonic-gate 					break;
4337c478bd9Sstevel@tonic-gate 			if (size < 0)
4347c478bd9Sstevel@tonic-gate 				lp++;
4357c478bd9Sstevel@tonic-gate 			ep += 2;
4367c478bd9Sstevel@tonic-gate 			goto star;
4377c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 		case CXCL | RNGE:
4407c478bd9Sstevel@tonic-gate 			getrnge(ep + 32);
4417c478bd9Sstevel@tonic-gate 			while (low--) {
4427c478bd9Sstevel@tonic-gate 				c = (unsigned char)*lp++;
4437c478bd9Sstevel@tonic-gate 				if (!ISTHERE(c))
4447c478bd9Sstevel@tonic-gate 					return (0);
4457c478bd9Sstevel@tonic-gate 			}
4467c478bd9Sstevel@tonic-gate 			curlp = lp;
4477c478bd9Sstevel@tonic-gate 			while (size--) {
4487c478bd9Sstevel@tonic-gate 				c = (unsigned char)*lp++;
4497c478bd9Sstevel@tonic-gate 				if (!ISTHERE(c))
4507c478bd9Sstevel@tonic-gate 					break;
4517c478bd9Sstevel@tonic-gate 			}
4527c478bd9Sstevel@tonic-gate 			if (size < 0)
4537c478bd9Sstevel@tonic-gate 				lp++;
4547c478bd9Sstevel@tonic-gate 			ep += 34;		/* 32 + 2 */
4557c478bd9Sstevel@tonic-gate 			goto star;
4567c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 		case NCCL | RNGE:
4597c478bd9Sstevel@tonic-gate 			neg = 1;
4607c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 		case CCL | RNGE:
4637c478bd9Sstevel@tonic-gate 			getrnge(ep + 16);
4647c478bd9Sstevel@tonic-gate 			while (low--) {
4657c478bd9Sstevel@tonic-gate 				c = *lp++;
4667c478bd9Sstevel@tonic-gate 				if (((c & 0200) || !ISTHERE(c)) ^ neg)
4677c478bd9Sstevel@tonic-gate 					return (0);
4687c478bd9Sstevel@tonic-gate 			}
4697c478bd9Sstevel@tonic-gate 			curlp = lp;
4707c478bd9Sstevel@tonic-gate 			while (size--) {
4717c478bd9Sstevel@tonic-gate 				c = *lp++;
4727c478bd9Sstevel@tonic-gate 				if (((c & 0200) || !ISTHERE(c)) ^ neg)
4737c478bd9Sstevel@tonic-gate 					break;
4747c478bd9Sstevel@tonic-gate 			}
4757c478bd9Sstevel@tonic-gate 			if (size < 0)
4767c478bd9Sstevel@tonic-gate 				lp++;
4776e270ca8SMarcel Telka 			ep += 18;		/* 16 + 2 */
4787c478bd9Sstevel@tonic-gate 			goto star;
4797c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 		case CBACK:
4827c478bd9Sstevel@tonic-gate 			bbeg = braslist[*ep];
4837c478bd9Sstevel@tonic-gate 			ct = braelist[*ep++] - bbeg;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 			if (ecmp(bbeg, lp, ct)) {
4867c478bd9Sstevel@tonic-gate 				lp += ct;
4877c478bd9Sstevel@tonic-gate 				continue;
4887c478bd9Sstevel@tonic-gate 			}
4897c478bd9Sstevel@tonic-gate 			return (0);
4907c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 		case CBACK | STAR:
4937c478bd9Sstevel@tonic-gate 			bbeg = braslist[*ep];
4947c478bd9Sstevel@tonic-gate 			ct = braelist[*ep++] - bbeg;
4957c478bd9Sstevel@tonic-gate 			curlp = lp;
4967c478bd9Sstevel@tonic-gate 			while (ecmp(bbeg, lp, ct))
4977c478bd9Sstevel@tonic-gate 				lp += ct;
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 			while (lp >= curlp) {
5007c478bd9Sstevel@tonic-gate 				if (advance(lp, ep))
5017c478bd9Sstevel@tonic-gate 					return (1);
5027c478bd9Sstevel@tonic-gate 				lp -= ct;
5037c478bd9Sstevel@tonic-gate 			}
5047c478bd9Sstevel@tonic-gate 			return (0);
5057c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 		case CDOT | STAR:
5087c478bd9Sstevel@tonic-gate 			curlp = lp;
5096e270ca8SMarcel Telka 			while (*lp++)
5106e270ca8SMarcel Telka 				;
5117c478bd9Sstevel@tonic-gate 			goto star;
5127c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 		case CCHR | STAR:
5157c478bd9Sstevel@tonic-gate 			curlp = lp;
5166e270ca8SMarcel Telka 			while (*lp++ == *ep)
5176e270ca8SMarcel Telka 				;
5187c478bd9Sstevel@tonic-gate 			ep++;
5197c478bd9Sstevel@tonic-gate 			goto star;
5207c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 		case CXCL | STAR:
5237c478bd9Sstevel@tonic-gate 			curlp = lp;
5247c478bd9Sstevel@tonic-gate 			do {
5257c478bd9Sstevel@tonic-gate 				c = (unsigned char)*lp++;
5267c478bd9Sstevel@tonic-gate 			} while (ISTHERE(c));
5277c478bd9Sstevel@tonic-gate 			ep += 32;
5287c478bd9Sstevel@tonic-gate 			goto star;
5297c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 		case NCCL | STAR:
5327c478bd9Sstevel@tonic-gate 			neg = 1;
5337c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 		case CCL | STAR:
5367c478bd9Sstevel@tonic-gate 			curlp = lp;
5377c478bd9Sstevel@tonic-gate 			do {
5387c478bd9Sstevel@tonic-gate 				c = *lp++;
5397c478bd9Sstevel@tonic-gate 			} while (((c & 0200) == 0 && ISTHERE(c)) ^ neg);
5407c478bd9Sstevel@tonic-gate 			ep += 16;
5417c478bd9Sstevel@tonic-gate 			goto star;
5427c478bd9Sstevel@tonic-gate 			/*FALLTHRU*/
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 		star:
5457c478bd9Sstevel@tonic-gate 			do {
5467c478bd9Sstevel@tonic-gate 				if (--lp == locs)
5477c478bd9Sstevel@tonic-gate 					break;
5487c478bd9Sstevel@tonic-gate 				if (advance(lp, ep))
5497c478bd9Sstevel@tonic-gate 					return (1);
5507c478bd9Sstevel@tonic-gate 			} while (lp > curlp);
5517c478bd9Sstevel@tonic-gate 			return (0);
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 		}
5547c478bd9Sstevel@tonic-gate 	}
5559acbbeafSnn 	/*NOTREACHED*/
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate static void
getrnge(const char * str)5597c478bd9Sstevel@tonic-gate getrnge(const char *str)
5607c478bd9Sstevel@tonic-gate {
5617c478bd9Sstevel@tonic-gate 	low = *str++ & 0377;
5627c478bd9Sstevel@tonic-gate 	size = ((*str & 0377) == 255)? 20000: (*str &0377) - low;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5667c478bd9Sstevel@tonic-gate }
5677c478bd9Sstevel@tonic-gate #endif
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate #endif	/* _REGEXP_H */
570