/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _REGEXP_H
#define _REGEXP_H
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
static int nodelim;
int circf;
static int low;
static int size;
char *
{
INIT /* Dependent declarations and initializations */
register int c;
char *lastep;
int cclcnt;
int closed;
int neg;
int lc;
int i, cflg;
#ifdef __lint
/* make lint happy */
c = nodelim;
#endif
if (c == '\n') {
UNGETC(c);
nodelim = 1;
}
ERROR(41);
}
if (c == '^')
circf++;
else
UNGETC(c);
for (;;) {
ERROR(50);
c = GETC();
if (c == eof) {
ERROR(42);
}
switch (c) {
case '.':
continue;
case '\n':
if (!sed) {
UNGETC(c);
nodelim = 1;
ERROR(42);
} else ERROR(36);
case '*':
goto defchar;
continue;
case '$':
goto defchar;
continue;
case '[':
ERROR(50);
lc = 0;
for (i = 0; i < 16; i++)
ep[i] = 0;
neg = 0;
if ((c = GETC()) == '^') {
neg = 1;
c = GETC();
}
iflag = 1;
do {
c &= 0377;
if (c == '\0' || c == '\n')
ERROR(49);
if ((c & 0200) && iflag) {
iflag = 0;
ERROR(50);
for (i = 16; i < 32; i++)
ep[i] = 0;
}
if (c == '-' && lc != 0) {
if ((c = GETC()) == ']') {
PLACE('-');
break;
}
if ((c & 0200) && iflag) {
iflag = 0;
ERROR(50);
for (i = 16; i < 32; i++)
ep[i] = 0;
}
while (lc < c) {
lc++;
}
}
lc = c;
PLACE(c);
} while ((c = GETC()) != ']');
if (iflag)
iflag = 16;
else
iflag = 32;
if (neg) {
if (iflag == 32) {
cclcnt++)
ep[0] &= 0376;
} else {
/* make nulls match so test fails */
ep[0] |= 01;
}
}
continue;
case '\\':
switch (c = GETC()) {
case '(':
ERROR(43);
continue;
case ')':
ERROR(42);
closed++;
continue;
case '{':
goto defchar;
cflg = 0;
nlim:
c = GETC();
i = 0;
do {
if ('0' <= c && c <= '9')
i = 10 * i + c - '0';
else
ERROR(16);
if (i >= 255)
ERROR(11);
*ep++ = (char)i;
if (c == ',') {
if (cflg++)
ERROR(44);
if ((c = GETC()) == '\\')
*ep++ = (char)255;
else {
UNGETC(c);
goto nlim;
/* get 2'nd number */
}
}
if (GETC() != '}')
ERROR(45);
if (!cflg) /* one number */
*ep++ = (char)i;
ERROR(46);
continue;
case '\n':
ERROR(36);
case 'n':
c = '\n';
goto defchar;
default:
if (c >= '1' && c <= '9') {
if ((c -= '1') >= closed)
ERROR(25);
*ep++ = (char)c;
continue;
}
}
/* Drop through to default to use \ to turn off special chars */
default:
*ep++ = (char)c;
}
}
/*NOTREACHED*/
}
int
{
char c;
if (circf) {
}
/* fast check for first character */
c = p2[1];
do {
if (*p1 != c)
continue;
return (1);
}
} while (*p1++);
return (0);
}
/* regular algorithm */
do {
return (1);
}
} while (*p1++);
return (0);
}
int
{
const char *curlp;
int c;
char *bbeg;
register char neg;
for (;;) {
neg = 0;
switch (*ep++) {
case CCHR:
continue;
return (0);
/*FALLTHRU*/
case CDOT:
if (*lp++)
continue;
return (0);
/*FALLTHRU*/
case CDOL:
if (*lp == 0)
continue;
return (0);
/*FALLTHRU*/
case CCEOF:
return (1);
/*FALLTHRU*/
case CXCL:
c = (unsigned char)*lp++;
if (ISTHERE(c)) {
ep += 32;
continue;
}
return (0);
/*FALLTHRU*/
case NCCL:
neg = 1;
/*FALLTHRU*/
case CCL:
c = *lp++;
ep += 16;
continue;
}
return (0);
/*FALLTHRU*/
case CBRA:
continue;
/*FALLTHRU*/
case CKET:
continue;
/*FALLTHRU*/
c = *ep++;
while (low--)
if (*lp++ != c)
return (0);
while (size--)
if (*lp++ != c)
break;
if (size < 0)
lp++;
ep += 2;
goto star;
/*FALLTHRU*/
while (low--)
if (*lp++ == '\0')
return (0);
while (size--)
if (*lp++ == '\0')
break;
if (size < 0)
lp++;
ep += 2;
goto star;
/*FALLTHRU*/
while (low--) {
c = (unsigned char)*lp++;
if (!ISTHERE(c))
return (0);
}
while (size--) {
c = (unsigned char)*lp++;
if (!ISTHERE(c))
break;
}
if (size < 0)
lp++;
goto star;
/*FALLTHRU*/
neg = 1;
/*FALLTHRU*/
while (low--) {
c = *lp++;
return (0);
}
while (size--) {
c = *lp++;
break;
}
if (size < 0)
lp++;
goto star;
/*FALLTHRU*/
case CBACK:
continue;
}
return (0);
/*FALLTHRU*/
return (1);
}
return (0);
/*FALLTHRU*/
while (*lp++);
goto star;
/*FALLTHRU*/
ep++;
goto star;
/*FALLTHRU*/
do {
c = (unsigned char)*lp++;
} while (ISTHERE(c));
ep += 32;
goto star;
/*FALLTHRU*/
neg = 1;
/*FALLTHRU*/
do {
c = *lp++;
ep += 16;
goto star;
/*FALLTHRU*/
star:
do {
break;
return (1);
return (0);
}
}
/*NOTREACHED*/
}
static void
{
}
#ifdef __cplusplus
}
#endif
#endif /* _REGEXP_H */