%{
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
/*
* Copyright 2013 Damian Bogel. All rights reserved.
*/
/*
* egrep -- print lines containing (or not containing) a regular expression
*
* status returns:
* 0 - ok, and some matches
* 1 - ok, but no matches
* 2 - some error; matches irrelevant
*/
%{
#include <stdio.h>
#include <ctype.h>
#include <memory.h>
#include <wchar.h>
#include <wctype.h>
#include <widec.h>
#include <stdlib.h>
#include <limits.h>
#include <locale.h>
#define EBUFSIZ 8192
#define MAXLIN 350
#define NCHARS 256
#define MAXPOS 4000
#define NSTATES 64
#define FINAL -1
int line = 1;
int *name;
int *left;
int *right;
int *parent;
int *foll;
int *positions;
char *chars;
int nxtpos = 0;
int inxtpos;
int nxtchar = 0;
int *tmpstat;
int *initstat;
int istat;
int nstate = 1;
int xstate;
int count;
int icount;
char *input;
int compare();
void overflo();
char reinit = 0;
long long lnum;
int bflag;
int cflag;
int eflag;
int fflag;
int Hflag;
int hflag;
int iflag;
int lflag;
int nflag;
int qflag;
int vflag;
int nfile;
long long blkno;
long long tln;
int nsucc;
int badbotch;
extern char *optarg;
extern int optind;
int f;
%}
%%
s: t
{
line--;
}
;
t: b r
| OR b r
| b r OR
;
b:
{ /* if(multibyte)
$$ = mdotenter();
else */
}
;
r: CHAR
| MCHAR
| DOT
{ if(multibyte)
$$ = mdotenter();
else
}
| CCL
| NCCL
| MCCL
| NMCCL
;
r: r OR r
| r STAR
| r PLUS
| r QUEST
| '(' r ')'
{ $$ = $2; }
| error
;
%%
void add(int *, int);
void clearg(void);
void execute(char *);
void follow(int);
int mgetc(void);
void synerror(void);
void
yyerror(char *s)
{
exit(2);
}
int
yylex(void)
{
extern int yylval;
c = nextch();
switch(c) {
case '^':
return(CHAR);
case '$':
c = RIGHT;
goto defchar;
case '|': return (OR);
case '*': return (STAR);
case '+': return (PLUS);
case '?': return (QUEST);
case '(': return (c);
case ')': return (c);
case '.': return(DOT);
case '\0': return (0);
case '[':
cclcnt = 0;
if ((c = nextch()) == '^') {
c = nextch();
}
lc = 0;
do {
c = towlower(c);
if (c == '\0') synerror();
if ((c = nextch()) != 0) {
if(c == ']') {
cclcnt++;
break;
}
c = towlower(c);
if (!multibyte ||
lc < c &&
if (allocchars() == 0)
overflo();
cclcnt++;
}
}
}
if(allocchars() == 0)
overflo();
lc = c;
} while ((c = nextch()) != ']');
return(x);
case '\\':
default:
if (c <= 0177) {
yylval = c;
return (CHAR);
} else {
lyylval = c;
return (MCHAR);
}
}
}
nextch(void)
{
char multic[MB_LEN_MAX];
int length, d;
if (fflag) {
synerror();
if(length == 0)
lc = '\0';
}
else {
synerror();
if(length == 0)
return(0);
}
return(lc);
}
int
mgetc(void)
{
}
void
synerror(void)
{
exit(2);
}
int
enter(int x)
{
if(alloctree() == 0)
overflo();
return(line++);
}
int
cclenter(int x)
{
int linno;
return (linno);
}
int
node(int x, int l, int r)
{
if(alloctree() == 0)
overflo();
return(line++);
}
int
unary(int x, int d)
{
if(alloctree() == 0)
overflo();
return(line++);
}
int
allocchars(void)
{
return 0;
return 1;
}
int
alloctree(void)
{
return 0;
return 0;
return 0;
return 0;
return 0;
return 0;
return 0;
return 1;
}
void
overflo(void)
{
exit(2);
}
void
cfoll(int v)
{
int i;
if (left[v] == 0) {
count = 0;
follow(v);
}
else {
}
}
void
cgotofn(void)
{
int i;
count = 0;
count++;
}
count--; /*leave out position 1 */
tmpstat[1] = 0;
}
int
nxtst(int s, int c)
{
int i, num, k;
for (i=0; i<num; i++) {
if (k >= 0)
if (
(k == c)
) {
for (k=0; k<number; k++) {
count++;
}
newpos++;
}
}
pos++;
}
for (i=1; i<NSTATES; i++)
out[i] = 0;
for (i=1; i<NSTATES; i++)
for (k=0; k<NCHARS; k++)
gotofn[i][k] = 0;
nstate = 1;
reinit = 1;
return nstate;
}
return nstate;
}
else {
return xstate;
}
}
int
cstate(int v)
{
int b;
if (left[v] == 0) {
if (tmpstat[v] != 1) {
tmpstat[v] = 1;
count++;
}
return(1);
}
else if (right[v] == 0) {
else return (0);
}
else return (1);
}
else { /* name[v] == OR */
else return (1);
}
}
int
dot(int c)
{
return(0);
return(0);
return(1);
}
int
mdot(int c)
{
if(c >= 0200 && !iscntrl(c))
return(1);
return(0);
}
int
{
return(0);
lc = 0;
if(iflag)
for (i=0; i<num; i++) {
return(torf);
}
if (symb == c)
return (torf);
lc = c;
}
return(!torf);
}
int
notin(int n)
{
int i, j, pos;
for (i=1; i<=n; i++) {
for (j=0; j < count; j++)
xstate = i;
return (0);
}
nxt: ;
}
return (1);
}
void
{
int i;
overflo();
}
for (i=3; i <= line; i++) {
if (tmpstat[i] == 1) {
}
}
}
void
follow(int v)
{
int p;
if (v == line) return;
p = parent[v];
switch(name[p]) {
case STAR:
follow(p);
return;
case OR:
return;
follow(p);
return;
}
}
else follow(p);
return;
count++;
}
return;
}
}
#define USAGE "[ -bchHilnsqv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ..."
int
{
char c;
char nl = '\n';
int errflag = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch(c) {
case 'b':
bflag++;
continue;
case 'c':
cflag++;
continue;
case 'e':
eflag++;
continue;
case 'f':
fflag++;
exit(2);
}
continue;
case 'H':
if (!lflag) /* H is excluded by l as in GNU grep */
Hflag++;
hflag = 0; /* H excludes h */
continue;
case 'h':
hflag++;
Hflag = 0; /* h excludes H */
continue;
case 'y':
case 'i':
iflag++;
continue;
case 'l':
lflag++;
Hflag = 0; /* l excludes H */
continue;
case 'n':
nflag++;
continue;
case 'q':
case 's': /* Solaris: legacy option */
qflag++;
continue;
case 'v':
vflag++;
continue;
case '?':
errflag++;
}
exit(2);
}
optind++;
}
/* allocate initial space for arrays */
overflo();
overflo();
overflo();
overflo();
overflo();
overflo();
overflo();
overflo();
overflo();
overflo();
overflo();
yyparse();
cgotofn();
if (argc<=0) {
execute(0);
}
else while (--argc >= 0) {
}
}
void
{
char *p;
int cstat;
wchar_t c;
int t;
long count;
long nchars;
int succ;
char *buf;
long lBufSiz;
FILE *f;
int nlflag;
}
if (file) {
badbotch=1;
return;
}
} else {
f = stdin;
}
lnum = 1;
tln = 0;
fclose(f);
}
return;
}
for(;;) {
/*
move the unused partial record to the head of the buffer
*/
}
/*
Get a bigger buffer if this one is full
*/
/*
expand the buffer
*/
}
}
continue;
}
nlflag = 0;
} else
nlflag = 1;
*ptrend = '\n';
p = ptr;
succ = 0;
for(;;) {
int length;
char *endptr = p;
p = lastptr;
while(p < endptr) {
if(length <= 1)
p++;
else
p += length;
}
if(p == endptr) {
break;
}
cstat = 1;
if(length <= 1)
lastptr++;
else
p = lastptr;
continue;
}
break;
}
c = (unsigned char)*p++;
else
cstat = t;
if(c == RIGHT) {
break;
}
break;
}
}
if (succ) {
nsucc = 1;
if (!qflag)
fclose(f);
return;
}
if (cflag) {
tln++;
} else {
if (bflag) {
if(nlflag)
nchars++;
}
if (nflag)
if(nlflag)
else
}
}
if(!nlflag)
break;
break;
}
lnum++;
if (reinit == 1)
clearg();
}
fclose(f);
}
}
void
clearg(void)
{
int i, k;
for (i=1; i<=nstate; i++)
out[i] = 0;
for (i=1; i<=nstate; i++)
for (k=0; k<NCHARS; k++)
gotofn[i][k] = 0;
nstate = 1;
reinit = 0;
count = 0;
count++;
}
count--; /*leave out position 1 */
tmpstat[1] = 0;
}
int
mdotenter(void)
{
for(i = 1; i < (int) eucw1; i++)
if(eucw2) {
for(i = 1; i <= (int) eucw2; i++)
}
if(eucw3) {
for(i = 1; i <= (int) eucw3; i++)
}
return(x1);
}
int
{
char *p;
p = multichar;
*(p + length) = '\0';
while(lc = (unsigned char)*p++)
return(x1);
}
int
{
char multic1[MB_LEN_MAX];
char multic2[MB_LEN_MAX];
x2 = 0;
current = 0;
cclcnt = 0;
/* create usual character class for single byte characters */
cclcnt++;
cclcnt += 2;
}
current++;
}
if(cclcnt)
else
if(current > 0)
/* single byte part of character class */
/* all single byte characters match */
else {
}
if(x2)
else
current++;
}
return x2;
}
int
{
char *p;
if(length == 1)
p = multic;
for(i = 1; i < length; i++)
*p++ = 0377;
for(i = 1; i < length; i++)
}
p = multic;
for(i = 1; i < length; i++)
*p++ = 0200;
}
int
{
if(!max) {
int i;
for(i = 0200; i <= 0377; i++)
if(!iscntrl(i))
break;
min = i;
for(i = 0377; i >= 0200; i--)
if(!iscntrl(i))
break;
max = i;
}
if(allocchars() == 0)
overflo();
}
int
{
char *p, *endp;
current = 0;
lc = 0;
/* convert character class into union of ranges */
while(p < endp) {
p += length;
if(c == '-' && lc != 0) {
p += length;
} else {
}
lc = c;
}
/* sort lower and upper bounds of ranges */
current = 0;
/* combine overlapping or adjacent ranges */
for(i = 0; i < last; i++)
else {
}
/* find complement of character class */
int j, next;
i = 0;
i++;
if(i > current) {
/* match all multibyte characters */
if(eucw2) {
}
if(eucw3) {
}
return i - 1;
}
overflo();
}
}
}
} else
}
for(j = i; j < current; j++) {
}
}
} else
}
}
}
}
}
}
current = i - 1;
}
return(current);
}
int
{
if(*c < *d)
return -1;
if(*c == *d)
return 0;
return 1;
}
{
if(!minmax1[0]) {
/* compute min and max process codes for all code sets */
int length, i;
for(i = 0377; i >= 0200; i--)
if(!iscntrl(i))
break;
minmax[1] = i;
for(i = 0240; i <= 0377; i++)
if(!iscntrl(i))
break;
minmax[0] = i;
for(i = 0; i <= 1; i++) {
length = MB_LEN_MAX;
while(length--)
if(eucw2) {
}
if(eucw3) {
}
}
}
switch(c) {
}
/* NOTREACHED */
return (0);
}