#define yyerror_gettext(x) yyerror(gettext(x)) # line 2 "egrep.y" /* * 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 * or http://www.opensolaris.org/os/licensing. * 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 */ # define CHAR 257 # define MCHAR 258 # define DOT 259 # define MDOT 260 # define CCL 261 # define NCCL 262 # define MCCL 263 # define NMCCL 264 # define OR 265 # define CAT 266 # define STAR 267 # define PLUS 268 # define QUEST 269 # line 54 "egrep.y" #include #include #include #include #include #include #include #include #include #define STDIN_FILENAME gettext("(standard input)") #define BLKSIZE 512 /* size of reported disk blocks */ #define EBUFSIZ 8192 #define MAXLIN 350 #define NCHARS 256 #define MAXPOS 4000 #define NSTATES 64 #define FINAL -1 #define RIGHT '\n' /* serves as record separator and as $ */ #define LEFT '\n' /* beginning of line */ int gotofn[NSTATES][NCHARS]; int state[NSTATES]; int out[NSTATES]; int line = 1; int *name; int *left; int *right; int *parent; int *foll; int *positions; char *chars; wchar_t *lower; wchar_t *upper; int maxlin, maxclin, maxwclin, maxpos; 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; wchar_t lyylval; wchar_t nextch(); wchar_t maxmin(); 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; FILE *expfile; #include #ifdef __STDC__ #include #include #define YYCONST const #else #include #include #define YYCONST #endif #include #if defined(__cplusplus) || defined(__STDC__) #if defined(__cplusplus) && defined(__EXTERN_C__) extern "C" { #endif #ifndef yyerror #if defined(__cplusplus) void yyerror(YYCONST char *); #endif #endif #ifndef yylex int yylex(void); #endif int yyparse(void); #if defined(__cplusplus) && defined(__EXTERN_C__) } #endif #endif #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern int yyerrflag; #ifndef YYSTYPE #define YYSTYPE int #endif YYSTYPE yylval; YYSTYPE yyval; typedef int yytabelem; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #if YYMAXDEPTH > 0 int yy_yys[YYMAXDEPTH], *yys = yy_yys; YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv; #else /* user does initial allocation */ int *yys; YYSTYPE *yyv; #endif static int yymaxdepth = YYMAXDEPTH; # define YYERRCODE 256 # line 196 "egrep.y" void add(int *, int); void clearg(void); void execute(char *); void follow(int); int mgetc(void); void synerror(void); void yyerror(char *s) { fprintf(stderr, "egrep: %s\n", s); exit(2); } int yylex(void) { extern int yylval; int cclcnt, x, ccount, oldccount; wchar_t c, lc; c = nextch(); switch(c) { case '^': yylval = LEFT; 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 RIGHT: return (OR); case '[': x = (multibyte ? MCCL : CCL); cclcnt = 0; count = nxtchar++; if ((c = nextch()) == '^') { x = (multibyte ? NMCCL : NCCL); c = nextch(); } lc = 0; do { if (iflag && iswalpha(c)) c = towlower(c); if (c == '\0') synerror(); if (c == '-' && cclcnt > 0 && lc != 0) { if ((c = nextch()) != 0) { if(c == ']') { chars[nxtchar++] = '-'; cclcnt++; break; } if (iflag && iswalpha(c)) c = towlower(c); if (!multibyte || (c & WCHAR_CSMASK) == (lc & WCHAR_CSMASK) && lc < c && !iswcntrl(c) && !iswcntrl(lc)) { if (nxtchar >= maxclin) if (allocchars() == 0) overflo(); chars[nxtchar++] = '-'; cclcnt++; } } } ccount = oldccount = nxtchar; if(ccount + MB_LEN_MAX >= maxclin) if(allocchars() == 0) overflo(); ccount += wctomb(&chars[ccount], c); cclcnt += ccount - oldccount; nxtchar += ccount - oldccount; lc = c; } while ((c = nextch()) != ']'); chars[count] = cclcnt; return(x); case '\\': if ((c = nextch()) == '\0') synerror(); defchar: default: if (c <= 0177) { yylval = c; return (CHAR); } else { lyylval = c; return (MCHAR); } } } wchar_t nextch(void) { wchar_t lc; char multic[MB_LEN_MAX]; int length, d; if (fflag) { if ((length = _mbftowc(multic, &lc, mgetc, &d)) < 0) synerror(); if(length == 0) lc = '\0'; } else { if((length = mbtowc(&lc, input, MB_LEN_MAX)) == -1) synerror(); if(length == 0) return(0); input += length; } return(lc); } int mgetc(void) { return(getc(expfile)); } void synerror(void) { fprintf(stderr, gettext("egrep: syntax error\n")); exit(2); } int enter(int x) { if(line >= maxlin) if(alloctree() == 0) overflo(); name[line] = x; left[line] = 0; right[line] = 0; return(line++); } int cclenter(int x) { int linno; linno = enter(x); right[linno] = count; return (linno); } int node(int x, int l, int r) { if(line >= maxlin) if(alloctree() == 0) overflo(); name[line] = x; left[line] = l; right[line] = r; parent[l] = line; parent[r] = line; return(line++); } int unary(int x, int d) { if(line >= maxlin) if(alloctree() == 0) overflo(); name[line] = x; left[line] = d; right[line] = 0; parent[d] = line; return(line++); } int allocchars(void) { maxclin += MAXLIN; if((chars = realloc(chars, maxclin)) == (char *)0) return 0; return 1; } int alloctree(void) { maxlin += MAXLIN; if((name = (int *)realloc(name, maxlin*sizeof(int))) == (int *)0) return 0; if((left = (int *)realloc(left, maxlin*sizeof(int))) == (int *)0) return 0; if((right = (int *)realloc(right, maxlin*sizeof(int))) == (int *)0) return 0; if((parent = (int *)realloc(parent, maxlin*sizeof(int))) == (int *)0) return 0; if((foll = (int *)realloc(foll, maxlin*sizeof(int))) == (int *)0) return 0; if((tmpstat = (int *)realloc(tmpstat, maxlin*sizeof(int))) == (int *)0) return 0; if((initstat = (int *)realloc(initstat, maxlin*sizeof(int))) == (int *)0) return 0; return 1; } void overflo(void) { fprintf(stderr, gettext("egrep: regular expression too long\n")); exit(2); } void cfoll(int v) { int i; if (left[v] == 0) { count = 0; for (i=1; i<=line; i++) tmpstat[i] = 0; follow(v); add(foll, v); } else if (right[v] == 0) cfoll(left[v]); else { cfoll(left[v]); cfoll(right[v]); } } void cgotofn(void) { int i; count = 0; inxtpos = nxtpos; for (i=3; i<=line; i++) tmpstat[i] = 0; if (cstate(line-1)==0) { tmpstat[line] = 1; count++; out[1] = 1; } for (i=3; i<=line; i++) initstat[i] = tmpstat[i]; count--; /*leave out position 1 */ icount = count; tmpstat[1] = 0; add(state, 1); istat = nxtst(1, LEFT); } int nxtst(int s, int c) { int i, num, k; int pos, curpos, number, newpos; num = positions[state[s]]; count = icount; for (i=3; i<=line; i++) tmpstat[i] = initstat[i]; pos = state[s] + 1; for (i=0; i= 0) if ( (k == c) || (k == DOT && dot(c)) || (k == MDOT && mdot(c)) || (k == CCL && dot(c) && member(c, right[curpos], 1)) || (k == NCCL && dot(c) && member(c, right[curpos], 0)) || (k == MCCL && mdot(c) && member(c, right[curpos], 1)) ) { number = positions[foll[curpos]]; newpos = foll[curpos] + 1; for (k=0; k= NSTATES) { for (i=1; i= 0200 && (!iscntrl(c) || c == SS2 && eucw2 || c == SS3 && eucw3)) return(0); if(c == RIGHT || c == LEFT) return(0); return(1); } int mdot(int c) { if(c >= 0200 && !iscntrl(c)) return(1); return(0); } int member(int symb, int set, int torf) { int i, num, pos, c, lc; if(symb == RIGHT || symb == LEFT) return(0); num = chars[set]; pos = set + 1; lc = 0; if(iflag) symb = tolower(symb); for (i=0; i= maxpos) { maxpos += MAXPOS + count; if((positions = (int *)realloc(positions, maxpos *sizeof(int))) == (int *)0) overflo(); } array[n] = nxtpos; positions[nxtpos++] = count; for (i=3; i <= line; i++) { if (tmpstat[i] == 1) { positions[nxtpos++] = i; } } } void follow(int v) { int p; if (v == line) return; p = parent[v]; switch(name[p]) { case STAR: case PLUS: cstate(v); follow(p); return; case OR: case QUEST: follow(p); return; case CAT: if (v == left[p]) { if (cstate(right[p]) == 0) { follow(p); return; } } else follow(p); return; case FINAL: if (tmpstat[line] != 1) { tmpstat[line] = 1; count++; } return; } } #define USAGE "[ -bchHilnsqv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ..." int main(int argc, char **argv) { char c; char nl = '\n'; int errflag = 0; (void)setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't. */ #endif (void) textdomain(TEXT_DOMAIN); while((c = getopt(argc, argv, "ybcie:f:Hhlnvsq")) != -1) switch(c) { case 'b': bflag++; continue; case 'c': cflag++; continue; case 'e': eflag++; input = optarg; continue; case 'f': fflag++; expfile = fopen(optarg, "r"); if(expfile == NULL) { fprintf(stderr, gettext("egrep: can't open %s\n"), optarg); 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++; } if (errflag || ((argc <= 0) && !fflag && !eflag)) { fprintf(stderr, gettext("usage: egrep %s\n"), gettext(USAGE)); exit(2); } if(!eflag && !fflag) { input = argv[optind]; optind++; } argc -= optind; argv = &argv[optind]; /* allocate initial space for arrays */ if((name = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((left = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((right = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((parent = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((foll = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((tmpstat = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((initstat = (int *)malloc(MAXLIN*sizeof(int))) == (int *)0) overflo(); if((chars = (char *)malloc(MAXLIN)) == (char *)0) overflo(); if((lower = (wchar_t *)malloc(MAXLIN*sizeof(wchar_t))) == (wchar_t *)0) overflo(); if((upper = (wchar_t *)malloc(MAXLIN*sizeof(wchar_t))) == (wchar_t *)0) overflo(); if((positions = (int *)malloc(MAXPOS*sizeof(int))) == (int *)0) overflo(); maxlin = MAXLIN; maxclin = MAXLIN; maxwclin = MAXLIN; maxpos = MAXPOS; yyparse(); cfoll(line-1); cgotofn(); nfile = argc; if (argc<=0) { execute(0); } else while (--argc >= 0) { if (reinit == 1) clearg(); execute(*argv++); } return (badbotch ? 2 : nsucc==0); } void execute(char *file) { char *p; int cstat; wchar_t c; int t; long count; long count1, count2; long nchars; int succ; char *ptr, *ptrend, *lastptr; char *buf; long lBufSiz; FILE *f; int nlflag; lBufSiz = EBUFSIZ; if ((buf = malloc (lBufSiz + EBUFSIZ)) == NULL) { exit (2); /* out of memory - BAIL */ } if (file) { if ((f = fopen(file, "r")) == NULL) { fprintf(stderr, gettext("egrep: can't open %s\n"), file); badbotch=1; return; } } else { f = stdin; file = STDIN_FILENAME; } lnum = 1; tln = 0; if((count = read(fileno(f), buf, EBUFSIZ)) <= 0) { fclose(f); if (cflag && !qflag) { if (Hflag || (nfile > 1 && !hflag)) fprintf(stdout, "%s:", file); fprintf(stdout, "%lld\n", tln); } return; } blkno = count; ptr = buf; for(;;) { if((ptrend = memchr(ptr, '\n', buf + count - ptr)) == NULL) { /* move the unused partial record to the head of the buffer */ if (ptr > buf) { count = buf + count - ptr; memmove (buf, ptr, count); ptr = buf; } /* Get a bigger buffer if this one is full */ if(count > lBufSiz) { /* expand the buffer */ lBufSiz += EBUFSIZ; if ((buf = realloc (buf, lBufSiz + EBUFSIZ)) == NULL) { exit (2); /* out of memory - BAIL */ } ptr = buf; } p = buf + count; if((count1 = read(fileno(f), p, EBUFSIZ)) > 0) { count += count1; blkno += count1; continue; } ptrend = ptr + count; nlflag = 0; } else nlflag = 1; *ptrend = '\n'; p = ptr; lastptr = ptr; cstat = istat; succ = 0; for(;;) { if(out[cstat]) { if(multibyte && p > ptr) { wchar_t wchar; int length; char *endptr = p; p = lastptr; while(p < endptr) { length = mbtowc(&wchar, p, MB_LEN_MAX); if(length <= 1) p++; else p += length; } if(p == endptr) { succ = !vflag; break; } cstat = 1; length = mbtowc(&wchar, lastptr, MB_LEN_MAX); if(length <= 1) lastptr++; else lastptr += length; p = lastptr; continue; } succ = !vflag; break; } c = (unsigned char)*p++; if ((t = gotofn[cstat][c]) == 0) cstat = nxtst(cstat, c); else cstat = t; if(c == RIGHT) { if(out[cstat]) { succ = !vflag; break; } succ = vflag; break; } } if (succ) { nsucc = 1; if (lflag || qflag) { if (!qflag) (void) printf("%s\n", file); fclose(f); return; } if (cflag) { tln++; } else { if (Hflag || (nfile > 1 && !hflag)) printf("%s:", file); if (bflag) { nchars = blkno - (buf + count - ptrend) - 2; if(nlflag) nchars++; printf("%lld:", nchars/BLKSIZE); } if (nflag) printf("%lld:", lnum); if(nlflag) nchars = ptrend - ptr + 1; else nchars = ptrend - ptr; fwrite(ptr, (size_t)1, (size_t)nchars, stdout); } } if(!nlflag) break; ptr = ptrend + 1; if(ptr >= buf + count) { ptr = buf; if((count = read(fileno(f), buf, EBUFSIZ)) <= 0) break; blkno += count; } lnum++; if (reinit == 1) clearg(); } fclose(f); if (cflag && !qflag) { if (Hflag || (nfile > 1 && !hflag)) printf("%s:", file); printf("%lld\n", tln); } } 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 0) /* single byte part of character class */ x2 = cclenter(type); else if(type == NCCL) /* all single byte characters match */ x2 = enter(DOT); while(current <= last) { if(upper[current] == lower[current]) x1 = mchar(lower[current]); else { length = wctomb(multic1, lower[current]); wctomb(multic2, upper[current]); x1 = range((unsigned char *)multic1, (unsigned char *)multic2, length); } if(x2) x2 = node(OR, x2, x1); else x2 = x1; current++; } return x2; } int range(unsigned char *p1, unsigned char *p2, int length) { char multic[MB_LEN_MAX+1]; char *p; int i, x1, x2; if(length == 1) return(classenter(*p1, *p2)); if(p1[0] == p2[0]) return(node(CAT, enter(p1[0]), range(p1+1, p2+1, length - 1))); p = multic; for(i = 1; i < length; i++) *p++ = 0377; x1 = node(CAT, enter(p1[0]), range(p1+1, (unsigned char *)multic, length - 1)); if((unsigned char)(p1[0] + 1) < p2[0]) { x2 = classenter(p1[0] + 1, p2[0] - 1); for(i = 1; i < length; i++) x2 = node(CAT, x2, enter(MDOT)); x1 = node(OR, x1, x2); } p = multic; for(i = 1; i < length; i++) *p++ = 0200; x2 = node(CAT, enter(p2[0]), range((unsigned char *)multic, p2+1, length - 1)); return node(OR, x1, x2); } int classenter(int x1, int x2) { static int max, min; 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(x1 <= min && x2 >= max) return enter(MDOT); if(nxtchar + 4 >= maxclin) if(allocchars() == 0) overflo(); count = nxtchar++; chars[nxtchar++] = x1; chars[nxtchar++] = '-'; chars[nxtchar++] = x2; chars[count] = 3; return cclenter(MCCL); } int genrange(int type) { char *p, *endp; int current, nel, i, last, length; wchar_t c, lc; current = 0; p = &chars[count+1]; endp = &chars[count+1] + chars[count]; lc = 0; /* convert character class into union of ranges */ while(p < endp) { length = mbtowc(&c, p, MB_LEN_MAX); p += length; if(c == '-' && lc != 0) { length = mbtowc(&c, p, MB_LEN_MAX); upper[current-1] = c; p += length; } else { lower[current] = c; upper[current++] = c; } lc = c; } nel = current; /* sort lower and upper bounds of ranges */ qsort((char *)lower, nel, sizeof(wchar_t), compare); qsort((char *)upper, nel, sizeof(wchar_t), compare); last = current - 1; current = 0; /* combine overlapping or adjacent ranges */ for(i = 0; i < last; i++) if(upper[i] >= lower[i+1] - 1) upper[current] = upper[i+1]; else { lower[++current] = lower[i+1]; upper[current] = upper[i+1]; } if(type == NCCL) { /* find complement of character class */ int j, next; i = 0; while(i <= current && isascii(c=lower[i]) || c <= 0377 && iscntrl(c)) i++; if(i > current) { /* match all multibyte characters */ if(eucw2) { lower[i] = maxmin(WCHAR_CS2, 0); upper[i++] = maxmin(WCHAR_CS2, 1); } if(eucw3) { lower[i] = maxmin(WCHAR_CS3, 0); upper[i++] = maxmin(WCHAR_CS3, 1); } lower[i] = maxmin(WCHAR_CS1, 0); upper[i++] = maxmin(WCHAR_CS1, 1); return i - 1; } next = current + 1; if(next + current + 2 >= maxwclin) { maxwclin += MAXLIN + next + current + 2; if((lower = (wchar_t *)realloc(lower, maxwclin *sizeof(wchar_t))) == (wchar_t *)0 || (upper = (wchar_t *)realloc(upper, maxwclin * sizeof(wchar_t))) == (wchar_t *)0) overflo(); } if(eucw2 && lower[i] > maxmin(WCHAR_CS2, 0)) { lower[next] = maxmin(WCHAR_CS2, 0); if((lower[i] & WCHAR_CSMASK) != WCHAR_CS2) { upper[next++] = maxmin(WCHAR_CS2, 1); if((lower[i] & WCHAR_CSMASK) == WCHAR_CS1 && eucw3) { lower[next] = maxmin(WCHAR_CS3, 0); upper[next++] = maxmin(WCHAR_CS3, 1); } if(lower[i] > maxmin(lower[i] & WCHAR_CSMASK, 0)) { lower[next] = maxmin(lower[i] & WCHAR_CSMASK, 0); upper[next++] = lower[i] - 1; } } else upper[next++] = lower[i] - 1; } else if(lower[i] > maxmin(lower[i] & WCHAR_CSMASK, 0)) { lower[next] = maxmin(lower[i] & WCHAR_CSMASK, 0); upper[next++] = lower[i] - 1; } for(j = i; j < current; j++) { if(upper[j] < maxmin(upper[j] & WCHAR_CSMASK, 1)) { lower[next] = upper[j] + 1; if((upper[j] & WCHAR_CSMASK) != (lower[j+1] & WCHAR_CSMASK)) { upper[next++] = maxmin(upper[j] & WCHAR_CSMASK, 1); if(eucw3 && (upper[j] & WCHAR_CSMASK) == WCHAR_CS2 && (lower[j+1] & WCHAR_CSMASK) == WCHAR_CS1) { lower[next] = maxmin(WCHAR_CS3, 0); upper[next++] = maxmin(WCHAR_CS3, 1); } if(lower[j+1] > maxmin(lower[j+1] & WCHAR_CSMASK, 0)) { lower[next] = maxmin(lower[j+1] & WCHAR_CSMASK, 0); upper[next++] = lower[j+1] - 1; } } else upper[next++] = lower[j+1] - 1; } else if(lower[j+1] > maxmin(lower[j+1], 0)) { lower[next] = maxmin(lower[j+1], 0); upper[next++] = lower[j+1] - 1; } } if(upper[current] < maxmin(upper[current] & WCHAR_CSMASK, 1)) { lower[next] = upper[current] + 1; upper[next++] = maxmin(upper[current] & WCHAR_CSMASK, 1); } if((upper[current] & WCHAR_CSMASK) != WCHAR_CS1) { if((upper[current] & WCHAR_CSMASK) == WCHAR_CS2 && eucw3) { lower[next] = maxmin(WCHAR_CS3, 0); upper[next++] = maxmin(WCHAR_CS3, 1); } lower[next] = maxmin(WCHAR_CS1, 0); upper[next++] = maxmin(WCHAR_CS1, 1); } for(j = current + 1; j < next; j++) { lower[i] = lower[j]; upper[i++] = upper[j]; } current = i - 1; } return(current); } int compare(wchar_t *c, wchar_t *d) { if(*c < *d) return -1; if(*c == *d) return 0; return 1; } wchar_t maxmin(wchar_t c, int flag) { static wchar_t minmax1[2], minmax2[2], minmax3[2]; if(!minmax1[0]) { /* compute min and max process codes for all code sets */ int length, i; char multic[MB_LEN_MAX], minmax[2]; 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--) multic[length] = minmax[i]; mbtowc(&minmax1[i], multic, MB_LEN_MAX); if(eucw2) { multic[0] = SS2; mbtowc(&minmax2[i], multic, MB_LEN_MAX); } if(eucw3) { multic[0] = SS3; mbtowc(&minmax3[i], multic, MB_LEN_MAX); } } } switch(c) { case WCHAR_CS1: return minmax1[flag]; case WCHAR_CS2: return minmax2[flag]; case WCHAR_CS3: return minmax3[flag]; } /* NOTREACHED */ return (0); } static YYCONST yytabelem yyexca[] ={ -1, 1, 0, -1, -2, 0, -1, 5, 0, 2, -2, 0, -1, 16, 0, 5, -2, 0, -1, 17, 0, 15, 257, 15, 258, 15, 259, 15, 261, 15, 262, 15, 263, 15, 264, 15, 265, 15, 40, 15, 41, 15, -2, 0, -1, 22, 0, 4, -2, 0, -1, 23, 0, 14, 265, 14, 41, 14, -2, 0, -1, 26, 0, 3, -2, 0, }; # define YYNPROD 21 # define YYLAST 281 static YYCONST yytabelem yyact[]={ 13, 25, 4, 3, 14, 17, 2, 1, 15, 5, 0, 0, 0, 0, 13, 18, 19, 20, 0, 21, 0, 22, 23, 0, 0, 0, 0, 0, 13, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 6, 7, 8, 0, 9, 10, 11, 12, 24, 0, 18, 19, 20, 14, 6, 7, 8, 0, 9, 10, 11, 12, 26, 0, 18, 19, 20, 14, 6, 7, 8, 0, 9, 10, 11, 12, 16, 0, 18, 19, 20, 14, 6, 7, 8, 0, 9, 10, 11, 12, 0, 0, 18, 19, 20, 14, 6, 7, 8, 0, 9, 10, 11, 12 }; static YYCONST yytabelem yypact[]={ -263,-10000000,-10000000, 16,-10000000, -12,-10000000,-10000000,-10000000,-10000000, -10000000,-10000000,-10000000, 16,-10000000, 16, 16, -252,-10000000,-10000000, -10000000, -40, -26, 2, 16,-10000000, 16 }; static YYCONST yytabelem yypgo[]={ 0, 7, 6, 3, 5 }; static YYCONST yytabelem yyr1[]={ 0, 1, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; static YYCONST yytabelem yyr2[]={ 0, 3, 5, 9, 7, 7, 1, 3, 3, 3, 3, 3, 3, 3, 7, 5, 5, 5, 5, 7, 2 }; static YYCONST yytabelem yychk[]={ -10000000, -1, -2, -3, 265, -4, 257, 258, 259, 261, 262, 263, 264, 40, 256, -3, 265, -4, 267, 268, 269, -4, -4, -4, 265, 41, 265 }; static YYCONST yytabelem yydef[]={ 6, -2, 1, 0, 6, -2, 7, 8, 9, 10, 11, 12, 13, 0, 20, 0, -2, -2, 16, 17, 18, 0, -2, -2, 0, 19, -2 }; typedef struct #ifdef __cplusplus yytoktype #endif { #ifdef __cplusplus const #endif char *t_name; int t_val; } yytoktype; #ifndef YYDEBUG # define YYDEBUG 0 /* don't allow debugging */ #endif #if YYDEBUG yytoktype yytoks[] = { "CHAR", 257, "MCHAR", 258, "DOT", 259, "MDOT", 260, "CCL", 261, "NCCL", 262, "MCCL", 263, "NMCCL", 264, "OR", 265, "CAT", 266, "STAR", 267, "PLUS", 268, "QUEST", 269, "(", 40, "-unknown-", -1 /* ends search */ }; #ifdef __cplusplus const #endif char * yyreds[] = { "-no such reduction-", "s : t", "t : b r", "t : OR b r OR", "t : OR b r", "t : b r OR", "b : /* empty */", "r : CHAR", "r : MCHAR", "r : DOT", "r : CCL", "r : NCCL", "r : MCCL", "r : NMCCL", "r : r OR r", "r : r r", "r : r STAR", "r : r PLUS", "r : r QUEST", "r : '(' r ')'", "r : error", }; #endif /* YYDEBUG */ # line 1 "/usr/share/lib/ccs/yaccpar" /* * 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 * or http://www.opensolaris.org/os/licensing. * 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 1993 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ #pragma ident "%Z%%M% %I% %E% SMI" /* ** Skeleton parser driver for yacc output */ /* ** yacc user known macros and defines */ #define YYERROR goto yyerrlab #define YYACCEPT return(0) #define YYABORT return(1) #define YYBACKUP( newtoken, newvalue )\ {\ if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\ {\ yyerror_gettext( "syntax error - cannot backup" );\ goto yyerrlab;\ }\ yychar = newtoken;\ yystate = *yyps;\ yylval = newvalue;\ goto yynewstate;\ } #define YYRECOVERING() (!!yyerrflag) #define YYNEW(type) malloc(sizeof(type) * yynewmax) #define YYCOPY(to, from, type) \ (type *) memcpy(to, (char *) from, yymaxdepth * sizeof (type)) #define YYENLARGE( from, type) \ (type *) realloc((char *) from, yynewmax * sizeof(type)) #ifndef YYDEBUG # define YYDEBUG 1 /* make debugging available */ #endif /* ** user known globals */ int yydebug; /* set to 1 to get debugging */ /* ** driver internal defines */ #define YYFLAG (-10000000) /* ** global variables used by the parser */ YYSTYPE *yypv; /* top of value stack */ int *yyps; /* top of state stack */ int yystate; /* current state */ int yytmp; /* extra var (lasts between blocks) */ int yynerrs; /* number of errors */ int yyerrflag; /* error recovery flag */ int yychar; /* current input token number */ #ifdef YYNMBCHARS #define YYLEX() yycvtok(yylex()) /* ** yycvtok - return a token if i is a wchar_t value that exceeds 255. ** If i<255, i itself is the token. If i>255 but the neither ** of the 30th or 31st bit is on, i is already a token. */ #if defined(__STDC__) || defined(__cplusplus) int yycvtok(int i) #else int yycvtok(i) int i; #endif { int first = 0; int last = YYNMBCHARS - 1; int mid; wchar_t j; if(i&0x60000000){/*Must convert to a token. */ if( yymbchars[last].character < i ){ return i;/*Giving up*/ } while ((last>=first)&&(first>=0)) {/*Binary search loop*/ mid = (first+last)/2; j = yymbchars[mid].character; if( j==i ){/*Found*/ return yymbchars[mid].tvalue; }else if( j= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( ++yy_ps >= &yys[ yymaxdepth ] ) /* room on stack? */ { /* ** reallocate and recover. Note that pointers ** have to be reset, or bad things will happen */ long yyps_index = (yy_ps - yys); long yypv_index = (yy_pv - yyv); long yypvt_index = (yypvt - yyv); int yynewmax; #ifdef YYEXPAND yynewmax = YYEXPAND(yymaxdepth); #else yynewmax = 2 * yymaxdepth; /* double table size */ if (yymaxdepth == YYMAXDEPTH) /* first time growth */ { char *newyys = (char *)YYNEW(int); char *newyyv = (char *)YYNEW(YYSTYPE); if (newyys != 0 && newyyv != 0) { yys = YYCOPY(newyys, yys, int); yyv = YYCOPY(newyyv, yyv, YYSTYPE); } else yynewmax = 0; /* failed */ } else /* not first time */ { yys = YYENLARGE(yys, int); yyv = YYENLARGE(yyv, YYSTYPE); if (yys == 0 || yyv == 0) yynewmax = 0; /* failed */ } #endif if (yynewmax <= yymaxdepth) /* tables not expanded */ { yyerror( "yacc stack overflow" ); YYABORT; } yymaxdepth = yynewmax; yy_ps = yys + yyps_index; yy_pv = yyv + yypv_index; yypvt = yyv + yypvt_index; } *yy_ps = yy_state; *++yy_pv = yyval; /* ** we have a new state - find out what to do */ yy_newstate: if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG ) goto yydefault; /* simple state */ #if YYDEBUG /* ** if debugging, need to mark whether new token grabbed */ yytmp = yychar < 0; #endif if ( ( yychar < 0 ) && ( ( yychar = YYLEX() ) < 0 ) ) yychar = 0; /* reached EOF */ #if YYDEBUG if ( yydebug && yytmp ) { register int yy_i; printf( "Received token " ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) ) goto yydefault; if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar ) /*valid shift*/ { yychar = -1; yyval = yylval; yy_state = yy_n; if ( yyerrflag > 0 ) yyerrflag--; goto yy_stack; } yydefault: if ( ( yy_n = yydef[ yy_state ] ) == -2 ) { #if YYDEBUG yytmp = yychar < 0; #endif if ( ( yychar < 0 ) && ( ( yychar = YYLEX() ) < 0 ) ) yychar = 0; /* reached EOF */ #if YYDEBUG if ( yydebug && yytmp ) { register int yy_i; printf( "Received token " ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) { break; } } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ /* ** look through exception table */ { register YYCONST int *yyxi = yyexca; while ( ( *yyxi != -1 ) || ( yyxi[1] != yy_state ) ) { yyxi += 2; } while ( ( *(yyxi += 2) >= 0 ) && ( *yyxi != yychar ) ) ; if ( ( yy_n = yyxi[1] ) < 0 ) YYACCEPT; } } /* ** check for syntax error */ if ( yy_n == 0 ) /* have an error */ { /* no worry about speed here! */ switch ( yyerrflag ) { case 0: /* new error */ yyerror_gettext( "syntax error" ); goto skip_init; yyerrlab: /* ** get globals into registers. ** we have a user generated syntax type error */ yy_pv = yypv; yy_ps = yyps; yy_state = yystate; skip_init: yynerrs++; /* FALLTHRU */ case 1: case 2: /* incompletely recovered error */ /* try again... */ yyerrflag = 3; /* ** find state where "error" is a legal ** shift action */ while ( yy_ps >= yys ) { yy_n = yypact[ *yy_ps ] + YYERRCODE; if ( yy_n >= 0 && yy_n < YYLAST && yychk[yyact[yy_n]] == YYERRCODE) { /* ** simulate shift of "error" */ yy_state = yyact[ yy_n ]; goto yy_stack; } /* ** current state has no shift on ** "error", pop stack */ #if YYDEBUG # define _POP_ "Error recovery pops state %d, uncovers state %d\n" if ( yydebug ) printf( _POP_, *yy_ps, yy_ps[-1] ); # undef _POP_ #endif yy_ps--; yy_pv--; } /* ** there is no state on stack with "error" as ** a valid shift. give up. */ YYABORT; case 3: /* no shift yet; eat a token */ #if YYDEBUG /* ** if debugging, look up token in list of ** pairs. 0 and negative shouldn't occur, ** but since timing doesn't matter when ** debugging, it doesn't hurt to leave the ** tests here. */ if ( yydebug ) { register int yy_i; printf( "Error recovery discards " ); if ( yychar == 0 ) printf( "token end-of-file\n" ); else if ( yychar < 0 ) printf( "token -none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) { break; } } printf( "token %s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( yychar == 0 ) /* reached EOF. quit */ YYABORT; yychar = -1; goto yy_newstate; } }/* end if ( yy_n == 0 ) */ /* ** reduction by production yy_n ** put stack tops, etc. so things right after switch */ #if YYDEBUG /* ** if debugging, print the string that is the user's ** specification of the reduction which is just about ** to be done. */ if ( yydebug ) printf( "Reduce by (%d) \"%s\"\n", yy_n, yyreds[ yy_n ] ); #endif yytmp = yy_n; /* value to switch over */ yypvt = yy_pv; /* $vars top of value stack */ /* ** Look in goto table for next state ** Sorry about using yy_state here as temporary ** register variable, but why not, if it works... ** If yyr2[ yy_n ] doesn't have the low order bit ** set, then there is no action to be done for ** this reduction. So, no saving & unsaving of ** registers done. The only difference between the ** code just after the if and the body of the if is ** the goto yy_stack in the body. This way the test ** can be made before the choice of what to do is needed. */ { /* length of production doubled with extra bit */ register int yy_len = yyr2[ yy_n ]; if ( !( yy_len & 01 ) ) { yy_len >>= 1; yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + *( yy_ps -= yy_len ) + 1; if ( yy_state >= YYLAST || yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) { yy_state = yyact[ yypgo[ yy_n ] ]; } goto yy_stack; } yy_len >>= 1; yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + *( yy_ps -= yy_len ) + 1; if ( yy_state >= YYLAST || yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) { yy_state = yyact[ yypgo[ yy_n ] ]; } } /* save until reenter driver code */ yystate = yy_state; yyps = yy_ps; yypv = yy_pv; } /* ** code supplied by user is placed in this switch */ switch( yytmp ) { case 1: # line 136 "egrep.y" { unary(FINAL, yypvt[-0]); line--; } break; case 2: # line 142 "egrep.y" { yyval = node(CAT, yypvt[-1], yypvt[-0]); } break; case 3: # line 144 "egrep.y" { yyval = node(CAT, yypvt[-2], yypvt[-1]); } break; case 4: # line 146 "egrep.y" { yyval = node(CAT, yypvt[-1], yypvt[-0]); } break; case 5: # line 148 "egrep.y" { yyval = node(CAT, yypvt[-2], yypvt[-1]); } break; case 6: # line 151 "egrep.y" { /* if(multibyte) $$ = mdotenter(); else */ yyval = enter(DOT); yyval = unary(STAR, yyval); } break; case 7: # line 159 "egrep.y" { yyval = iflag && isalpha(yypvt[-0]) ? node(OR, enter(tolower(yypvt[-0])), enter(toupper(yypvt[-0]))) : enter(yypvt[-0]); } break; case 8: # line 162 "egrep.y" { yyval = (iflag && iswalpha(lyylval)) ? node(OR, mchar(towlower(lyylval)), mchar(towupper(lyylval))) : mchar(lyylval); } break; case 9: # line 166 "egrep.y" { if(multibyte) yyval = mdotenter(); else yyval = enter(DOT); } break; case 10: # line 172 "egrep.y" { yyval = cclenter(CCL); } break; case 11: # line 174 "egrep.y" { yyval = cclenter(NCCL); } break; case 12: # line 176 "egrep.y" { yyval = ccl(CCL); } break; case 13: # line 178 "egrep.y" { yyval = ccl(NCCL); } break; case 14: # line 182 "egrep.y" { yyval = node(OR, yypvt[-2], yypvt[-0]); } break; case 15: # line 184 "egrep.y" { yyval = node(CAT, yypvt[-1], yypvt[-0]); } break; case 16: # line 186 "egrep.y" { yyval = unary(STAR, yypvt[-1]); } break; case 17: # line 188 "egrep.y" { yyval = unary(PLUS, yypvt[-1]); } break; case 18: # line 190 "egrep.y" { yyval = unary(QUEST, yypvt[-1]); } break; case 19: # line 192 "egrep.y" { yyval = yypvt[-1]; } break; # line 556 "/usr/share/lib/ccs/yaccpar" } goto yystack; /* reset registers in driver code */ }