1*47840Sbostic /*- 2*47840Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*47840Sbostic * All rights reserved. 4*47840Sbostic * 5*47840Sbostic * %sccs.include.redist.c% 6*47840Sbostic */ 7*47840Sbostic 81177Sbill /* Yacc productions for "expr" command: */ 943665Sbostic %{ 1043665Sbostic typedef char *yystype; 1143665Sbostic #define YYSTYPE yystype 1243665Sbostic %} 131177Sbill 141177Sbill %token OR AND ADD SUBT MULT DIV REM EQ GT GEQ LT LEQ NEQ 151177Sbill %token A_STRING SUBSTR LENGTH INDEX NOARG MATCH 161177Sbill 171177Sbill /* operators listed below in increasing precedence: */ 181177Sbill %left OR 191177Sbill %left AND 201177Sbill %left EQ LT GT GEQ LEQ NEQ 211177Sbill %left ADD SUBT 221177Sbill %left MULT DIV REM 231177Sbill %left MCH 241177Sbill %left MATCH 251177Sbill %left SUBSTR 261177Sbill %left LENGTH INDEX 271177Sbill %% 281177Sbill 291177Sbill /* a single `expression' is evaluated and printed: */ 301177Sbill 311177Sbill expression: expr NOARG = { 321177Sbill printf("%s\n", $1); 331177Sbill exit((!strcmp($1,"0")||!strcmp($1,"\0"))? 1: 0); 341177Sbill } 351177Sbill ; 361177Sbill 371177Sbill 381177Sbill expr: '(' expr ')' = { $$ = $2; } 391177Sbill | expr OR expr = { $$ = conj(OR, $1, $3); } 401177Sbill | expr AND expr = { $$ = conj(AND, $1, $3); } 411177Sbill | expr EQ expr = { $$ = rel(EQ, $1, $3); } 421177Sbill | expr GT expr = { $$ = rel(GT, $1, $3); } 431177Sbill | expr GEQ expr = { $$ = rel(GEQ, $1, $3); } 441177Sbill | expr LT expr = { $$ = rel(LT, $1, $3); } 451177Sbill | expr LEQ expr = { $$ = rel(LEQ, $1, $3); } 461177Sbill | expr NEQ expr = { $$ = rel(NEQ, $1, $3); } 471177Sbill | expr ADD expr = { $$ = arith(ADD, $1, $3); } 481177Sbill | expr SUBT expr = { $$ = arith(SUBT, $1, $3); } 491177Sbill | expr MULT expr = { $$ = arith(MULT, $1, $3); } 501177Sbill | expr DIV expr = { $$ = arith(DIV, $1, $3); } 511177Sbill | expr REM expr = { $$ = arith(REM, $1, $3); } 521177Sbill | expr MCH expr = { $$ = match($1, $3); } 531177Sbill | MATCH expr expr = { $$ = match($2, $3); } 541177Sbill | SUBSTR expr expr expr = { $$ = substr($2, $3, $4); } 551177Sbill | LENGTH expr = { $$ = length($2); } 561177Sbill | INDEX expr expr = { $$ = index($2, $3); } 571177Sbill | A_STRING 581177Sbill ; 591177Sbill %% 601177Sbill /* expression command */ 61*47840Sbostic 62*47840Sbostic #ifndef lint 63*47840Sbostic char copyright[] = 64*47840Sbostic "@(#) Copyright (c) 1991 The Regents of the University of California.\n\ 65*47840Sbostic All rights reserved.\n"; 66*47840Sbostic #endif /* not lint */ 67*47840Sbostic 68*47840Sbostic #ifndef lint 69*47840Sbostic static char sccsid[] = "@(#)expr.y 5.1 (Berkeley) 04/08/91"; 70*47840Sbostic #endif /* not lint */ 71*47840Sbostic 721177Sbill #include <stdio.h> 731177Sbill #define ESIZE 256 741177Sbill #define error(c) errxx(c) 751177Sbill #define EQL(x,y) !strcmp(x,y) 761177Sbill long atol(); 771177Sbill char **Av; 781177Sbill int Ac; 791177Sbill int Argi; 801177Sbill 811177Sbill char Mstring[1][128]; 821177Sbill char *malloc(); 831177Sbill extern int nbra; 841177Sbill 851177Sbill main(argc, argv) char **argv; { 861177Sbill Ac = argc; 871177Sbill Argi = 1; 881177Sbill Av = argv; 891177Sbill yyparse(); 901177Sbill } 911177Sbill 921177Sbill char *operators[] = { "|", "&", "+", "-", "*", "/", "%", ":", 931177Sbill "=", "==", "<", "<=", ">", ">=", "!=", 941177Sbill "match", "substr", "length", "index", "\0" }; 951177Sbill int op[] = { OR, AND, ADD, SUBT, MULT, DIV, REM, MCH, 961177Sbill EQ, EQ, LT, LEQ, GT, GEQ, NEQ, 971177Sbill MATCH, SUBSTR, LENGTH, INDEX }; 981177Sbill yylex() { 991177Sbill register char *p; 1001177Sbill register i; 1011177Sbill 1021177Sbill if(Argi >= Ac) return NOARG; 1031177Sbill 1041177Sbill p = Av[Argi++]; 1051177Sbill 1061177Sbill if(*p == '(' || *p == ')') 1071177Sbill return (int)*p; 1081177Sbill for(i = 0; *operators[i]; ++i) 1091177Sbill if(EQL(operators[i], p)) 1101177Sbill return op[i]; 1111177Sbill 1121177Sbill yylval = p; 1131177Sbill return A_STRING; 1141177Sbill } 1151177Sbill 1161177Sbill char *rel(op, r1, r2) register char *r1, *r2; { 11713483Ssam register long i; 1181177Sbill 1191177Sbill if(ematch(r1, "-*[0-9]*$") && ematch(r2, "[0-9]*$")) 1201177Sbill i = atol(r1) - atol(r2); 1211177Sbill else 1221177Sbill i = strcmp(r1, r2); 1231177Sbill switch(op) { 1241177Sbill case EQ: i = i==0; break; 1251177Sbill case GT: i = i>0; break; 1261177Sbill case GEQ: i = i>=0; break; 1271177Sbill case LT: i = i<0; break; 1283175Swnj case LEQ: i = i<=0; break; 1291177Sbill case NEQ: i = i!=0; break; 1301177Sbill } 1311177Sbill return i? "1": "0"; 1321177Sbill } 1331177Sbill 1341177Sbill char *arith(op, r1, r2) char *r1, *r2; { 1351177Sbill long i1, i2; 1361177Sbill register char *rv; 1371177Sbill 13832132Sbostic if(!((ematch(r1, "[0-9]*$") || ematch(r1, "-[0-9]*$")) && 13932132Sbostic (ematch(r2, "[0-9]*$") || ematch(r2, "-[0-9]*$")))) 1401177Sbill yyerror("non-numeric argument"); 1411177Sbill i1 = atol(r1); 1421177Sbill i2 = atol(r2); 1431177Sbill 1441177Sbill switch(op) { 1451177Sbill case ADD: i1 = i1 + i2; break; 1461177Sbill case SUBT: i1 = i1 - i2; break; 1471177Sbill case MULT: i1 = i1 * i2; break; 1481177Sbill case DIV: i1 = i1 / i2; break; 1491177Sbill case REM: i1 = i1 % i2; break; 1501177Sbill } 1511177Sbill rv = malloc(16); 15232411Sbostic (void)sprintf(rv, "%ld", i1); 1531177Sbill return rv; 1541177Sbill } 1551177Sbill char *conj(op, r1, r2) char *r1, *r2; { 1561177Sbill register char *rv; 1571177Sbill 1581177Sbill switch(op) { 1591177Sbill 1601177Sbill case OR: 1611177Sbill if(EQL(r1, "0") 1621177Sbill || EQL(r1, "")) 1631177Sbill if(EQL(r2, "0") 1641177Sbill || EQL(r2, "")) 1651177Sbill rv = "0"; 1661177Sbill else 1671177Sbill rv = r2; 1681177Sbill else 1691177Sbill rv = r1; 1701177Sbill break; 1711177Sbill case AND: 1721177Sbill if(EQL(r1, "0") 1731177Sbill || EQL(r1, "")) 1741177Sbill rv = "0"; 1751177Sbill else if(EQL(r2, "0") 1761177Sbill || EQL(r2, "")) 1771177Sbill rv = "0"; 1781177Sbill else 1791177Sbill rv = r1; 1801177Sbill break; 1811177Sbill } 1821177Sbill return rv; 1831177Sbill } 1841177Sbill 1851177Sbill char *substr(v, s, w) char *v, *s, *w; { 1861177Sbill register si, wi; 1871177Sbill register char *res; 1881177Sbill 1891177Sbill si = atol(s); 1901177Sbill wi = atol(w); 1911177Sbill while(--si) if(*v) ++v; 1921177Sbill 1931177Sbill res = v; 1941177Sbill 1951177Sbill while(wi--) if(*v) ++v; 1961177Sbill 1971177Sbill *v = '\0'; 1981177Sbill return res; 1991177Sbill } 2001177Sbill 2011177Sbill char *length(s) register char *s; { 2021177Sbill register i = 0; 2031177Sbill register char *rv; 2041177Sbill 2051177Sbill while(*s++) ++i; 2061177Sbill 2071177Sbill rv = malloc(8); 20832411Sbostic (void)sprintf(rv, "%d", i); 2091177Sbill return rv; 2101177Sbill } 2111177Sbill 2121177Sbill char *index(s, t) char *s, *t; { 2131177Sbill register i, j; 2141177Sbill register char *rv; 2151177Sbill 2161177Sbill for(i = 0; s[i] ; ++i) 2171177Sbill for(j = 0; t[j] ; ++j) 2181177Sbill if(s[i]==t[j]) { 21932411Sbostic (void)sprintf(rv = malloc(8), "%d", ++i); 2201177Sbill return rv; 2211177Sbill } 2221177Sbill return "0"; 2231177Sbill } 2241177Sbill 2251177Sbill char *match(s, p) 2261177Sbill { 2271177Sbill register char *rv; 2281177Sbill 22932411Sbostic (void)sprintf(rv = malloc(8), "%d", ematch(s, p)); 2301177Sbill if(nbra) { 2311177Sbill rv = malloc(strlen(Mstring[0])+1); 2321177Sbill strcpy(rv, Mstring[0]); 2331177Sbill } 2341177Sbill return rv; 2351177Sbill } 2361177Sbill 2371177Sbill #define INIT register char *sp = instring; 2381177Sbill #define GETC() (*sp++) 2391177Sbill #define PEEKC() (*sp) 2401177Sbill #define UNGETC(c) (--sp) 2411177Sbill #define RETURN(c) return 2421177Sbill #define ERROR(c) errxx(c) 2431177Sbill 2441177Sbill 2451177Sbill ematch(s, p) 2461177Sbill char *s; 2471177Sbill register char *p; 2481177Sbill { 2491177Sbill static char expbuf[ESIZE]; 2501177Sbill char *compile(); 2511177Sbill register num; 2521177Sbill extern char *braslist[], *braelist[], *loc2; 2531177Sbill 25416513Sralph compile(p, expbuf, &expbuf[ESIZE], 0); 2551177Sbill if(nbra > 1) 2561177Sbill yyerror("Too many '\\('s"); 2571177Sbill if(advance(s, expbuf)) { 2581177Sbill if(nbra == 1) { 2591177Sbill p = braslist[0]; 2601177Sbill num = braelist[0] - p; 2611177Sbill strncpy(Mstring[0], p, num); 2621177Sbill Mstring[0][num] = '\0'; 2631177Sbill } 2641177Sbill return(loc2-s); 2651177Sbill } 2661177Sbill return(0); 2671177Sbill } 2681177Sbill 2691177Sbill errxx(c) 2701177Sbill { 2711177Sbill yyerror("RE error"); 2721177Sbill } 2731177Sbill 2741177Sbill #define CBRA 2 2751177Sbill #define CCHR 4 2761177Sbill #define CDOT 8 2771177Sbill #define CCL 12 2781177Sbill #define CDOL 20 2791177Sbill #define CEOF 22 2801177Sbill #define CKET 24 2811177Sbill #define CBACK 36 2821177Sbill 2831177Sbill #define STAR 01 2841177Sbill #define RNGE 03 2851177Sbill 2861177Sbill #define NBRA 9 2871177Sbill 2881177Sbill #define PLACE(c) ep[c >> 3] |= bittab[c & 07] 2891177Sbill #define ISTHERE(c) (ep[c >> 3] & bittab[c & 07]) 2901177Sbill 2911177Sbill char *braslist[NBRA]; 2921177Sbill char *braelist[NBRA]; 2931177Sbill int nbra; 2941177Sbill char *loc1, *loc2, *locs; 2951177Sbill int sed; 2961177Sbill 2971177Sbill int circf; 2981177Sbill int low; 2991177Sbill int size; 3001177Sbill 3011177Sbill char bittab[] = { 3021177Sbill 1, 3031177Sbill 2, 3041177Sbill 4, 3051177Sbill 8, 3061177Sbill 16, 3071177Sbill 32, 3081177Sbill 64, 3091177Sbill 128 3101177Sbill }; 3111177Sbill 3121177Sbill char * 3131177Sbill compile(instring, ep, endbuf, seof) 3141177Sbill register char *ep; 3151177Sbill char *instring, *endbuf; 3161177Sbill { 3171177Sbill INIT /* Dependent declarations and initializations */ 3181177Sbill register c; 3191177Sbill register eof = seof; 3201177Sbill char *lastep = instring; 3211177Sbill int cclcnt; 3221177Sbill char bracket[NBRA], *bracketp; 3231177Sbill int closed; 3241177Sbill char neg; 3251177Sbill int lc; 3261177Sbill int i, cflg; 3271177Sbill 3281177Sbill lastep = 0; 3291177Sbill if((c = GETC()) == eof) { 3301177Sbill if(*ep == 0 && !sed) 3311177Sbill ERROR(41); 3321177Sbill RETURN(ep); 3331177Sbill } 3341177Sbill bracketp = bracket; 3351177Sbill circf = closed = nbra = 0; 3361177Sbill if (c == '^') 3371177Sbill circf++; 3381177Sbill else 3391177Sbill UNGETC(c); 3401177Sbill for (;;) { 3411177Sbill if (ep >= endbuf) 3421177Sbill ERROR(50); 3431177Sbill if((c = GETC()) != '*' && ((c != '\\') || (PEEKC() != '{'))) 3441177Sbill lastep = ep; 3451177Sbill if (c == eof) { 3461177Sbill *ep++ = CEOF; 3471177Sbill RETURN(ep); 3481177Sbill } 3491177Sbill switch (c) { 3501177Sbill 3511177Sbill case '.': 3521177Sbill *ep++ = CDOT; 3531177Sbill continue; 3541177Sbill 3551177Sbill case '\n': 3561177Sbill ERROR(36); 3571177Sbill case '*': 3581177Sbill if (lastep==0 || *lastep==CBRA || *lastep==CKET) 3591177Sbill goto defchar; 3601177Sbill *lastep |= STAR; 3611177Sbill continue; 3621177Sbill 3631177Sbill case '$': 3641177Sbill if(PEEKC() != eof) 3651177Sbill goto defchar; 3661177Sbill *ep++ = CDOL; 3671177Sbill continue; 3681177Sbill 3691177Sbill case '[': 3701177Sbill if(&ep[17] >= endbuf) 3711177Sbill ERROR(50); 3721177Sbill 3731177Sbill *ep++ = CCL; 3741177Sbill lc = 0; 3751177Sbill for(i = 0; i < 16; i++) 3761177Sbill ep[i] = 0; 3771177Sbill 3781177Sbill neg = 0; 3791177Sbill if((c = GETC()) == '^') { 3801177Sbill neg = 1; 3811177Sbill c = GETC(); 3821177Sbill } 3831177Sbill 3841177Sbill do { 3851177Sbill if(c == '\0' || c == '\n') 3861177Sbill ERROR(49); 3871177Sbill if(c == '-' && lc != 0) { 3881177Sbill if ((c = GETC()) == ']') { 3891177Sbill PLACE('-'); 3901177Sbill break; 3911177Sbill } 3921177Sbill while(lc < c) { 3931177Sbill PLACE(lc); 3941177Sbill lc++; 3951177Sbill } 3961177Sbill } 3971177Sbill lc = c; 3981177Sbill PLACE(c); 3991177Sbill } while((c = GETC()) != ']'); 4001177Sbill if(neg) { 4011177Sbill for(cclcnt = 0; cclcnt < 16; cclcnt++) 4021177Sbill ep[cclcnt] ^= -1; 4031177Sbill ep[0] &= 0376; 4041177Sbill } 4051177Sbill 4061177Sbill ep += 16; 4071177Sbill 4081177Sbill continue; 4091177Sbill 4101177Sbill case '\\': 4111177Sbill switch(c = GETC()) { 4121177Sbill 4131177Sbill case '(': 4141177Sbill if(nbra >= NBRA) 4151177Sbill ERROR(43); 4161177Sbill *bracketp++ = nbra; 4171177Sbill *ep++ = CBRA; 4181177Sbill *ep++ = nbra++; 4191177Sbill continue; 4201177Sbill 4211177Sbill case ')': 4221177Sbill if(bracketp <= bracket) 4231177Sbill ERROR(42); 4241177Sbill *ep++ = CKET; 4251177Sbill *ep++ = *--bracketp; 4261177Sbill closed++; 4271177Sbill continue; 4281177Sbill 4291177Sbill case '{': 4301177Sbill if(lastep == (char *) (0)) 4311177Sbill goto defchar; 4321177Sbill *lastep |= RNGE; 4331177Sbill cflg = 0; 4341177Sbill nlim: 4351177Sbill c = GETC(); 4361177Sbill i = 0; 4371177Sbill do { 4381177Sbill if ('0' <= c && c <= '9') 4391177Sbill i = 10 * i + c - '0'; 4401177Sbill else 4411177Sbill ERROR(16); 4421177Sbill } while(((c = GETC()) != '\\') && (c != ',')); 4431177Sbill if (i > 255) 4441177Sbill ERROR(11); 4451177Sbill *ep++ = i; 4461177Sbill if (c == ',') { 4471177Sbill if(cflg++) 4481177Sbill ERROR(44); 4491177Sbill if((c = GETC()) == '\\') 4501177Sbill *ep++ = 255; 4511177Sbill else { 4521177Sbill UNGETC(c); 4531177Sbill goto nlim; /* get 2'nd number */ 4541177Sbill } 4551177Sbill } 4561177Sbill if(GETC() != '}') 4571177Sbill ERROR(45); 4581177Sbill if(!cflg) /* one number */ 4591177Sbill *ep++ = i; 4601177Sbill else if((ep[-1] & 0377) < (ep[-2] & 0377)) 4611177Sbill ERROR(46); 4621177Sbill continue; 4631177Sbill 4641177Sbill case '\n': 4651177Sbill ERROR(36); 4661177Sbill 4671177Sbill case 'n': 4681177Sbill c = '\n'; 4691177Sbill goto defchar; 4701177Sbill 4711177Sbill default: 4721177Sbill if(c >= '1' && c <= '9') { 4731177Sbill if((c -= '1') >= closed) 4741177Sbill ERROR(25); 4751177Sbill *ep++ = CBACK; 4761177Sbill *ep++ = c; 4771177Sbill continue; 4781177Sbill } 4791177Sbill } 4801177Sbill /* Drop through to default to use \ to turn off special chars */ 4811177Sbill 4821177Sbill defchar: 4831177Sbill default: 4841177Sbill lastep = ep; 4851177Sbill *ep++ = CCHR; 4861177Sbill *ep++ = c; 4871177Sbill } 4881177Sbill } 4891177Sbill } 4901177Sbill 4911177Sbill step(p1, p2) 4921177Sbill register char *p1, *p2; 4931177Sbill { 4941177Sbill register c; 4951177Sbill 4961177Sbill if (circf) { 4971177Sbill loc1 = p1; 4981177Sbill return(advance(p1, p2)); 4991177Sbill } 5001177Sbill /* fast check for first character */ 5011177Sbill if (*p2==CCHR) { 5021177Sbill c = p2[1]; 5031177Sbill do { 5041177Sbill if (*p1 != c) 5051177Sbill continue; 5061177Sbill if (advance(p1, p2)) { 5071177Sbill loc1 = p1; 5081177Sbill return(1); 5091177Sbill } 5101177Sbill } while (*p1++); 5111177Sbill return(0); 5121177Sbill } 5131177Sbill /* regular algorithm */ 5141177Sbill do { 5151177Sbill if (advance(p1, p2)) { 5161177Sbill loc1 = p1; 5171177Sbill return(1); 5181177Sbill } 5191177Sbill } while (*p1++); 5201177Sbill return(0); 5211177Sbill } 5221177Sbill 5231177Sbill advance(lp, ep) 5241177Sbill register char *lp, *ep; 5251177Sbill { 5261177Sbill register char *curlp; 5271177Sbill char c; 5281177Sbill char *bbeg; 5291177Sbill int ct; 5301177Sbill 5311177Sbill for (;;) switch (*ep++) { 5321177Sbill 5331177Sbill case CCHR: 5341177Sbill if (*ep++ == *lp++) 5351177Sbill continue; 5361177Sbill return(0); 5371177Sbill 5381177Sbill case CDOT: 5391177Sbill if (*lp++) 5401177Sbill continue; 5411177Sbill return(0); 5421177Sbill 5431177Sbill case CDOL: 5441177Sbill if (*lp==0) 5451177Sbill continue; 5461177Sbill return(0); 5471177Sbill 5481177Sbill case CEOF: 5491177Sbill loc2 = lp; 5501177Sbill return(1); 5511177Sbill 5521177Sbill case CCL: 5531177Sbill c = *lp++ & 0177; 5541177Sbill if(ISTHERE(c)) { 5551177Sbill ep += 16; 5561177Sbill continue; 5571177Sbill } 5581177Sbill return(0); 5591177Sbill case CBRA: 5601177Sbill braslist[*ep++] = lp; 5611177Sbill continue; 5621177Sbill 5631177Sbill case CKET: 5641177Sbill braelist[*ep++] = lp; 5651177Sbill continue; 5661177Sbill 5671177Sbill case CCHR|RNGE: 5681177Sbill c = *ep++; 5691177Sbill getrnge(ep); 5701177Sbill while(low--) 5711177Sbill if(*lp++ != c) 5721177Sbill return(0); 5731177Sbill curlp = lp; 5741177Sbill while(size--) 5751177Sbill if(*lp++ != c) 5761177Sbill break; 5771177Sbill if(size < 0) 5781177Sbill lp++; 5791177Sbill ep += 2; 5801177Sbill goto star; 5811177Sbill 5821177Sbill case CDOT|RNGE: 5831177Sbill getrnge(ep); 5841177Sbill while(low--) 5851177Sbill if(*lp++ == '\0') 5861177Sbill return(0); 5871177Sbill curlp = lp; 5881177Sbill while(size--) 5891177Sbill if(*lp++ == '\0') 5901177Sbill break; 5911177Sbill if(size < 0) 5921177Sbill lp++; 5931177Sbill ep += 2; 5941177Sbill goto star; 5951177Sbill 5961177Sbill case CCL|RNGE: 5971177Sbill getrnge(ep + 16); 5981177Sbill while(low--) { 5991177Sbill c = *lp++ & 0177; 6001177Sbill if(!ISTHERE(c)) 6011177Sbill return(0); 6021177Sbill } 6031177Sbill curlp = lp; 6041177Sbill while(size--) { 6051177Sbill c = *lp++ & 0177; 6061177Sbill if(!ISTHERE(c)) 6071177Sbill break; 6081177Sbill } 6091177Sbill if(size < 0) 6101177Sbill lp++; 6111177Sbill ep += 18; /* 16 + 2 */ 6121177Sbill goto star; 6131177Sbill 6141177Sbill case CBACK: 6151177Sbill bbeg = braslist[*ep]; 6161177Sbill ct = braelist[*ep++] - bbeg; 6171177Sbill 6181177Sbill if(ecmp(bbeg, lp, ct)) { 6191177Sbill lp += ct; 6201177Sbill continue; 6211177Sbill } 6221177Sbill return(0); 6231177Sbill 6241177Sbill case CBACK|STAR: 6251177Sbill bbeg = braslist[*ep]; 6261177Sbill ct = braelist[*ep++] - bbeg; 6271177Sbill curlp = lp; 6281177Sbill while(ecmp(bbeg, lp, ct)) 6291177Sbill lp += ct; 6301177Sbill 6311177Sbill while(lp >= curlp) { 6321177Sbill if(advance(lp, ep)) return(1); 6331177Sbill lp -= ct; 6341177Sbill } 6351177Sbill return(0); 6361177Sbill 6371177Sbill 6381177Sbill case CDOT|STAR: 6391177Sbill curlp = lp; 6401177Sbill while (*lp++); 6411177Sbill goto star; 6421177Sbill 6431177Sbill case CCHR|STAR: 6441177Sbill curlp = lp; 6451177Sbill while (*lp++ == *ep); 6461177Sbill ep++; 6471177Sbill goto star; 6481177Sbill 6491177Sbill case CCL|STAR: 6501177Sbill curlp = lp; 6511177Sbill do { 6521177Sbill c = *lp++ & 0177; 6531177Sbill } while(ISTHERE(c)); 6541177Sbill ep += 16; 6551177Sbill goto star; 6561177Sbill 6571177Sbill star: 6581177Sbill do { 6591177Sbill if(--lp == locs) 6601177Sbill break; 6611177Sbill if (advance(lp, ep)) 6621177Sbill return(1); 6631177Sbill } while (lp > curlp); 6641177Sbill return(0); 6651177Sbill 6661177Sbill } 6671177Sbill } 6681177Sbill 6691177Sbill getrnge(str) 6701177Sbill register char *str; 6711177Sbill { 6721177Sbill low = *str++ & 0377; 67334081Sbostic size = (*str & 0377) == 255 ? 20000 : (*str & 0377) - low; 6741177Sbill } 6751177Sbill 6761177Sbill ecmp(a, b, count) 6771177Sbill register char *a, *b; 6781177Sbill register count; 6791177Sbill { 6801177Sbill if(a == b) /* should have been caught in compile() */ 6811177Sbill error(51); 6821177Sbill while(count--) 6831177Sbill if(*a++ != *b++) return(0); 6841177Sbill return(1); 6851177Sbill } 6861177Sbill 6871177Sbill yyerror(s) 6881177Sbill 6891177Sbill { 6901177Sbill fprintf(stderr, "%s\n", s); 6911177Sbill exit(2); 6921177Sbill } 693