1*7c478bd9Sstevel@tonic-gate %{ 2*7c478bd9Sstevel@tonic-gate /* 3*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate * with the License. 9*7c478bd9Sstevel@tonic-gate * 10*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate * and limitations under the License. 14*7c478bd9Sstevel@tonic-gate * 15*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate */ 23*7c478bd9Sstevel@tonic-gate %} 24*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 25*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate %{ 28*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 29*7c478bd9Sstevel@tonic-gate %} 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate /* Yacc productions for "expr" command: */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate %{ 34*7c478bd9Sstevel@tonic-gate typedef char *yystype; 35*7c478bd9Sstevel@tonic-gate #define YYSTYPE yystype 36*7c478bd9Sstevel@tonic-gate %} 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate %token OR AND ADD SUBT MULT DIV REM EQ GT GEQ LT LEQ NEQ 39*7c478bd9Sstevel@tonic-gate %token A_STRING SUBSTR LENGTH INDEX NOARG MATCH 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* operators listed below in increasing precedence: */ 42*7c478bd9Sstevel@tonic-gate %left OR 43*7c478bd9Sstevel@tonic-gate %left AND 44*7c478bd9Sstevel@tonic-gate %left EQ LT GT GEQ LEQ NEQ 45*7c478bd9Sstevel@tonic-gate %left ADD SUBT 46*7c478bd9Sstevel@tonic-gate %left MULT DIV REM 47*7c478bd9Sstevel@tonic-gate %left MCH 48*7c478bd9Sstevel@tonic-gate %left MATCH 49*7c478bd9Sstevel@tonic-gate %left SUBSTR 50*7c478bd9Sstevel@tonic-gate %left LENGTH INDEX 51*7c478bd9Sstevel@tonic-gate %% 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* a single `expression' is evaluated and printed: */ 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate expression: expr NOARG = { 56*7c478bd9Sstevel@tonic-gate printf("%s\n", $1); 57*7c478bd9Sstevel@tonic-gate exit((!strcmp($1,"0")||!strcmp($1,"\0"))? 1: 0); 58*7c478bd9Sstevel@tonic-gate } 59*7c478bd9Sstevel@tonic-gate ; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate expr: '(' expr ')' = { $$ = $2; } 63*7c478bd9Sstevel@tonic-gate | expr OR expr = { $$ = conj(OR, $1, $3); } 64*7c478bd9Sstevel@tonic-gate | expr AND expr = { $$ = conj(AND, $1, $3); } 65*7c478bd9Sstevel@tonic-gate | expr EQ expr = { $$ = rel(EQ, $1, $3); } 66*7c478bd9Sstevel@tonic-gate | expr GT expr = { $$ = rel(GT, $1, $3); } 67*7c478bd9Sstevel@tonic-gate | expr GEQ expr = { $$ = rel(GEQ, $1, $3); } 68*7c478bd9Sstevel@tonic-gate | expr LT expr = { $$ = rel(LT, $1, $3); } 69*7c478bd9Sstevel@tonic-gate | expr LEQ expr = { $$ = rel(LEQ, $1, $3); } 70*7c478bd9Sstevel@tonic-gate | expr NEQ expr = { $$ = rel(NEQ, $1, $3); } 71*7c478bd9Sstevel@tonic-gate | expr ADD expr = { $$ = arith(ADD, $1, $3); } 72*7c478bd9Sstevel@tonic-gate | expr SUBT expr = { $$ = arith(SUBT, $1, $3); } 73*7c478bd9Sstevel@tonic-gate | expr MULT expr = { $$ = arith(MULT, $1, $3); } 74*7c478bd9Sstevel@tonic-gate | expr DIV expr = { $$ = arith(DIV, $1, $3); } 75*7c478bd9Sstevel@tonic-gate | expr REM expr = { $$ = arith(REM, $1, $3); } 76*7c478bd9Sstevel@tonic-gate | expr MCH expr = { $$ = match($1, $3); } 77*7c478bd9Sstevel@tonic-gate | MATCH expr expr = { $$ = match($2, $3); } 78*7c478bd9Sstevel@tonic-gate | SUBSTR expr expr expr = { $$ = substr($2, $3, $4); } 79*7c478bd9Sstevel@tonic-gate | LENGTH expr = { $$ = length($2); } 80*7c478bd9Sstevel@tonic-gate | INDEX expr expr = { $$ = index($2, $3); } 81*7c478bd9Sstevel@tonic-gate | A_STRING 82*7c478bd9Sstevel@tonic-gate ; 83*7c478bd9Sstevel@tonic-gate %% 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #define ESIZE 256 86*7c478bd9Sstevel@tonic-gate #define EQL(x,y) !strcmp(x,y) 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate #define INIT register char *sp = instring; 89*7c478bd9Sstevel@tonic-gate #define GETC() (*sp++) 90*7c478bd9Sstevel@tonic-gate #define PEEKC() (*sp) 91*7c478bd9Sstevel@tonic-gate #define UNGETC(c) (--sp) 92*7c478bd9Sstevel@tonic-gate #define RETURN(c) return 93*7c478bd9Sstevel@tonic-gate #define ERROR(c) errxx(c) 94*7c478bd9Sstevel@tonic-gate #include <regexp.h> 95*7c478bd9Sstevel@tonic-gate #include <malloc.h> 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate long atol(); 98*7c478bd9Sstevel@tonic-gate char *ltoa(), *strcpy(), *strncpy(); 99*7c478bd9Sstevel@tonic-gate void exit(); 100*7c478bd9Sstevel@tonic-gate char **Av; 101*7c478bd9Sstevel@tonic-gate int Ac; 102*7c478bd9Sstevel@tonic-gate int Argi; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate char Mstring[1][128]; 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate char *operator[] = { 108*7c478bd9Sstevel@tonic-gate "|", "&", "+", "-", "*", "/", "%", ":", 109*7c478bd9Sstevel@tonic-gate "=", "==", "<", "<=", ">", ">=", "!=", 110*7c478bd9Sstevel@tonic-gate "match", "substr", "length", "index", "\0" }; 111*7c478bd9Sstevel@tonic-gate int op[] = { 112*7c478bd9Sstevel@tonic-gate OR, AND, ADD, SUBT, MULT, DIV, REM, MCH, 113*7c478bd9Sstevel@tonic-gate EQ, EQ, LT, LEQ, GT, GEQ, NEQ, 114*7c478bd9Sstevel@tonic-gate MATCH, SUBSTR, LENGTH, INDEX }; 115*7c478bd9Sstevel@tonic-gate yylex() { 116*7c478bd9Sstevel@tonic-gate register char *p; 117*7c478bd9Sstevel@tonic-gate register i; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate if(Argi >= Ac) return NOARG; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate p = Av[Argi++]; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate if((*p == '(' || *p == ')') && p[1] == '\0' ) 124*7c478bd9Sstevel@tonic-gate return (int)*p; 125*7c478bd9Sstevel@tonic-gate for(i = 0; *operator[i]; ++i) 126*7c478bd9Sstevel@tonic-gate if(EQL(operator[i], p)) 127*7c478bd9Sstevel@tonic-gate return op[i]; 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate yylval = p; 130*7c478bd9Sstevel@tonic-gate return A_STRING; 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate char *rel(oper, r1, r2) register char *r1, *r2; 134*7c478bd9Sstevel@tonic-gate { 135*7c478bd9Sstevel@tonic-gate register long i; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate if(ematch(r1, "-\\{0,1\\}[0-9]*$") && ematch(r2, "-\\{0,1\\}[0-9]*$")) 138*7c478bd9Sstevel@tonic-gate i = atol(r1) - atol(r2); 139*7c478bd9Sstevel@tonic-gate else 140*7c478bd9Sstevel@tonic-gate i = strcmp(r1, r2); 141*7c478bd9Sstevel@tonic-gate switch(oper) { 142*7c478bd9Sstevel@tonic-gate case EQ: 143*7c478bd9Sstevel@tonic-gate i = i==0; 144*7c478bd9Sstevel@tonic-gate break; 145*7c478bd9Sstevel@tonic-gate case GT: 146*7c478bd9Sstevel@tonic-gate i = i>0; 147*7c478bd9Sstevel@tonic-gate break; 148*7c478bd9Sstevel@tonic-gate case GEQ: 149*7c478bd9Sstevel@tonic-gate i = i>=0; 150*7c478bd9Sstevel@tonic-gate break; 151*7c478bd9Sstevel@tonic-gate case LT: 152*7c478bd9Sstevel@tonic-gate i = i<0; 153*7c478bd9Sstevel@tonic-gate break; 154*7c478bd9Sstevel@tonic-gate case LEQ: 155*7c478bd9Sstevel@tonic-gate i = i<=0; 156*7c478bd9Sstevel@tonic-gate break; 157*7c478bd9Sstevel@tonic-gate case NEQ: 158*7c478bd9Sstevel@tonic-gate i = i!=0; 159*7c478bd9Sstevel@tonic-gate break; 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate return i? "1": "0"; 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate char *arith(oper, r1, r2) char *r1, *r2; 165*7c478bd9Sstevel@tonic-gate { 166*7c478bd9Sstevel@tonic-gate long i1, i2; 167*7c478bd9Sstevel@tonic-gate register char *rv; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate if(!(ematch(r1, "-\\{0,1\\}[0-9]*$") && ematch(r2, "-\\{0,1\\}[0-9]*$"))) 170*7c478bd9Sstevel@tonic-gate yyerror("non-numeric argument"); 171*7c478bd9Sstevel@tonic-gate i1 = atol(r1); 172*7c478bd9Sstevel@tonic-gate i2 = atol(r2); 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate switch(oper) { 175*7c478bd9Sstevel@tonic-gate case ADD: 176*7c478bd9Sstevel@tonic-gate i1 = i1 + i2; 177*7c478bd9Sstevel@tonic-gate break; 178*7c478bd9Sstevel@tonic-gate case SUBT: 179*7c478bd9Sstevel@tonic-gate i1 = i1 - i2; 180*7c478bd9Sstevel@tonic-gate break; 181*7c478bd9Sstevel@tonic-gate case MULT: 182*7c478bd9Sstevel@tonic-gate i1 = i1 * i2; 183*7c478bd9Sstevel@tonic-gate break; 184*7c478bd9Sstevel@tonic-gate case DIV: 185*7c478bd9Sstevel@tonic-gate if (i2 == 0) 186*7c478bd9Sstevel@tonic-gate yyerror("division by zero"); 187*7c478bd9Sstevel@tonic-gate i1 = i1 / i2; 188*7c478bd9Sstevel@tonic-gate break; 189*7c478bd9Sstevel@tonic-gate case REM: 190*7c478bd9Sstevel@tonic-gate if (i2 == 0) 191*7c478bd9Sstevel@tonic-gate yyerror("division by zero"); 192*7c478bd9Sstevel@tonic-gate i1 = i1 % i2; 193*7c478bd9Sstevel@tonic-gate break; 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate rv = malloc(16); 196*7c478bd9Sstevel@tonic-gate (void) strcpy(rv, ltoa(i1)); 197*7c478bd9Sstevel@tonic-gate return rv; 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate char *conj(oper, r1, r2) char *r1, *r2; 200*7c478bd9Sstevel@tonic-gate { 201*7c478bd9Sstevel@tonic-gate register char *rv; 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate switch(oper) { 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate case OR: 206*7c478bd9Sstevel@tonic-gate if(EQL(r1, "0") 207*7c478bd9Sstevel@tonic-gate || EQL(r1, "")) 208*7c478bd9Sstevel@tonic-gate if(EQL(r2, "0") 209*7c478bd9Sstevel@tonic-gate || EQL(r2, "")) 210*7c478bd9Sstevel@tonic-gate rv = "0"; 211*7c478bd9Sstevel@tonic-gate else 212*7c478bd9Sstevel@tonic-gate rv = r2; 213*7c478bd9Sstevel@tonic-gate else 214*7c478bd9Sstevel@tonic-gate rv = r1; 215*7c478bd9Sstevel@tonic-gate break; 216*7c478bd9Sstevel@tonic-gate case AND: 217*7c478bd9Sstevel@tonic-gate if(EQL(r1, "0") 218*7c478bd9Sstevel@tonic-gate || EQL(r1, "")) 219*7c478bd9Sstevel@tonic-gate rv = "0"; 220*7c478bd9Sstevel@tonic-gate else if(EQL(r2, "0") 221*7c478bd9Sstevel@tonic-gate || EQL(r2, "")) 222*7c478bd9Sstevel@tonic-gate rv = "0"; 223*7c478bd9Sstevel@tonic-gate else 224*7c478bd9Sstevel@tonic-gate rv = r1; 225*7c478bd9Sstevel@tonic-gate break; 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate return rv; 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate char *substr(v, s, w) char *v, *s, *w; { 231*7c478bd9Sstevel@tonic-gate register si, wi; 232*7c478bd9Sstevel@tonic-gate register char *res; 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate si = atol(s); 235*7c478bd9Sstevel@tonic-gate wi = atol(w); 236*7c478bd9Sstevel@tonic-gate while(--si) if(*v) ++v; 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate res = v; 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate while(wi--) if(*v) ++v; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate *v = '\0'; 243*7c478bd9Sstevel@tonic-gate return res; 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate char *index(s, t) char *s, *t; { 247*7c478bd9Sstevel@tonic-gate register long i, j; 248*7c478bd9Sstevel@tonic-gate register char *rv; 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate for(i = 0; s[i] ; ++i) 251*7c478bd9Sstevel@tonic-gate for(j = 0; t[j] ; ++j) 252*7c478bd9Sstevel@tonic-gate if(s[i]==t[j]) { 253*7c478bd9Sstevel@tonic-gate (void) strcpy(rv = malloc(8), ltoa(++i)); 254*7c478bd9Sstevel@tonic-gate return rv; 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate return "0"; 257*7c478bd9Sstevel@tonic-gate } 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate char *length(s) register char *s; { 260*7c478bd9Sstevel@tonic-gate register long i = 0; 261*7c478bd9Sstevel@tonic-gate register char *rv; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate while(*s++) ++i; 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate rv = malloc(8); 266*7c478bd9Sstevel@tonic-gate (void) strcpy(rv, ltoa(i)); 267*7c478bd9Sstevel@tonic-gate return rv; 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate char *match(s, p) 271*7c478bd9Sstevel@tonic-gate char *s, *p; 272*7c478bd9Sstevel@tonic-gate { 273*7c478bd9Sstevel@tonic-gate register char *rv; 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate (void) strcpy(rv=malloc(8), ltoa((long)ematch(s, p))); 276*7c478bd9Sstevel@tonic-gate if(nbra) { 277*7c478bd9Sstevel@tonic-gate rv = malloc((unsigned) strlen(Mstring[0]) + 1); 278*7c478bd9Sstevel@tonic-gate (void) strcpy(rv, Mstring[0]); 279*7c478bd9Sstevel@tonic-gate } 280*7c478bd9Sstevel@tonic-gate return rv; 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate ematch(s, p) 284*7c478bd9Sstevel@tonic-gate char *s; 285*7c478bd9Sstevel@tonic-gate register char *p; 286*7c478bd9Sstevel@tonic-gate { 287*7c478bd9Sstevel@tonic-gate static char expbuf[ESIZE]; 288*7c478bd9Sstevel@tonic-gate char *compile(); 289*7c478bd9Sstevel@tonic-gate register num; 290*7c478bd9Sstevel@tonic-gate extern char *braslist[], *braelist[], *loc2; 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate compile(p, expbuf, &expbuf[ESIZE], 0); 293*7c478bd9Sstevel@tonic-gate if(nbra > 1) 294*7c478bd9Sstevel@tonic-gate yyerror("Too many '\\('s"); 295*7c478bd9Sstevel@tonic-gate if(advance(s, expbuf)) { 296*7c478bd9Sstevel@tonic-gate if(nbra == 1) { 297*7c478bd9Sstevel@tonic-gate p = braslist[0]; 298*7c478bd9Sstevel@tonic-gate num = braelist[0] - p; 299*7c478bd9Sstevel@tonic-gate if ((num > 127) || (num < 0)) yyerror("Paren problem"); 300*7c478bd9Sstevel@tonic-gate (void) strncpy(Mstring[0], p, num); 301*7c478bd9Sstevel@tonic-gate Mstring[0][num] = '\0'; 302*7c478bd9Sstevel@tonic-gate } 303*7c478bd9Sstevel@tonic-gate return(loc2-s); 304*7c478bd9Sstevel@tonic-gate } 305*7c478bd9Sstevel@tonic-gate return(0); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate errxx(err) 309*7c478bd9Sstevel@tonic-gate register err; 310*7c478bd9Sstevel@tonic-gate { 311*7c478bd9Sstevel@tonic-gate register char *message; 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate switch(err) { 314*7c478bd9Sstevel@tonic-gate case 11: 315*7c478bd9Sstevel@tonic-gate message = "Range endpoint too large"; 316*7c478bd9Sstevel@tonic-gate break; 317*7c478bd9Sstevel@tonic-gate case 16: 318*7c478bd9Sstevel@tonic-gate message = "Bad number"; 319*7c478bd9Sstevel@tonic-gate break; 320*7c478bd9Sstevel@tonic-gate case 25: 321*7c478bd9Sstevel@tonic-gate message = "``\\digit'' out of range"; 322*7c478bd9Sstevel@tonic-gate break; 323*7c478bd9Sstevel@tonic-gate case 36: 324*7c478bd9Sstevel@tonic-gate message = "Illegal or missing delimiter"; 325*7c478bd9Sstevel@tonic-gate break; 326*7c478bd9Sstevel@tonic-gate case 41: 327*7c478bd9Sstevel@tonic-gate message = "No remembered search string"; 328*7c478bd9Sstevel@tonic-gate break; 329*7c478bd9Sstevel@tonic-gate case 42: 330*7c478bd9Sstevel@tonic-gate message = "\\( \\) imbalance"; 331*7c478bd9Sstevel@tonic-gate break; 332*7c478bd9Sstevel@tonic-gate case 43: 333*7c478bd9Sstevel@tonic-gate message = "Too many \\("; 334*7c478bd9Sstevel@tonic-gate break; 335*7c478bd9Sstevel@tonic-gate case 44: 336*7c478bd9Sstevel@tonic-gate message = "More than 2 numbers given in \\{ \\}"; 337*7c478bd9Sstevel@tonic-gate break; 338*7c478bd9Sstevel@tonic-gate case 45: 339*7c478bd9Sstevel@tonic-gate message = "} expected after \\"; 340*7c478bd9Sstevel@tonic-gate break; 341*7c478bd9Sstevel@tonic-gate case 46: 342*7c478bd9Sstevel@tonic-gate message = "First number exceeds second in \\{ \\}"; 343*7c478bd9Sstevel@tonic-gate break; 344*7c478bd9Sstevel@tonic-gate case 49: 345*7c478bd9Sstevel@tonic-gate message = "[ ] imbalance"; 346*7c478bd9Sstevel@tonic-gate break; 347*7c478bd9Sstevel@tonic-gate case 50: 348*7c478bd9Sstevel@tonic-gate message = "Regular expression too long"; 349*7c478bd9Sstevel@tonic-gate break; 350*7c478bd9Sstevel@tonic-gate default: 351*7c478bd9Sstevel@tonic-gate message = "Unknown regexp error code!!"; 352*7c478bd9Sstevel@tonic-gate break; 353*7c478bd9Sstevel@tonic-gate } 354*7c478bd9Sstevel@tonic-gate yyerror(message); 355*7c478bd9Sstevel@tonic-gate } 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate yyerror(s) 358*7c478bd9Sstevel@tonic-gate char *s; 359*7c478bd9Sstevel@tonic-gate { 360*7c478bd9Sstevel@tonic-gate (void) write(2, "expr: ", 6); 361*7c478bd9Sstevel@tonic-gate (void) write(2, s, (unsigned) strlen(s)); 362*7c478bd9Sstevel@tonic-gate (void) write(2, "\n", 1); 363*7c478bd9Sstevel@tonic-gate exit(2); 364*7c478bd9Sstevel@tonic-gate } 365*7c478bd9Sstevel@tonic-gate 366*7c478bd9Sstevel@tonic-gate char *ltoa(l) 367*7c478bd9Sstevel@tonic-gate long l; 368*7c478bd9Sstevel@tonic-gate { 369*7c478bd9Sstevel@tonic-gate static char str[20]; 370*7c478bd9Sstevel@tonic-gate register char *sp; 371*7c478bd9Sstevel@tonic-gate register i; 372*7c478bd9Sstevel@tonic-gate register neg; 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate if(l == 0x80000000L) 375*7c478bd9Sstevel@tonic-gate return "-2147483648"; 376*7c478bd9Sstevel@tonic-gate neg = 0; 377*7c478bd9Sstevel@tonic-gate if(l < 0) 378*7c478bd9Sstevel@tonic-gate ++neg, l = -l; 379*7c478bd9Sstevel@tonic-gate sp = &str[20]; 380*7c478bd9Sstevel@tonic-gate *--sp = '\0'; 381*7c478bd9Sstevel@tonic-gate do { 382*7c478bd9Sstevel@tonic-gate i = l % 10; 383*7c478bd9Sstevel@tonic-gate *--sp = '0' + i; 384*7c478bd9Sstevel@tonic-gate l /= 10; 385*7c478bd9Sstevel@tonic-gate } 386*7c478bd9Sstevel@tonic-gate while(l); 387*7c478bd9Sstevel@tonic-gate if(neg) 388*7c478bd9Sstevel@tonic-gate *--sp = '-'; 389*7c478bd9Sstevel@tonic-gate return sp; 390*7c478bd9Sstevel@tonic-gate } 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate main(argc, argv) char **argv; 393*7c478bd9Sstevel@tonic-gate { 394*7c478bd9Sstevel@tonic-gate Ac = argc; 395*7c478bd9Sstevel@tonic-gate Argi = 1; 396*7c478bd9Sstevel@tonic-gate Av = argv; 397*7c478bd9Sstevel@tonic-gate yyparse(); 398*7c478bd9Sstevel@tonic-gate } 399