1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate * Use is subject to license terms. 26*0Sstevel@tonic-gate */ 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 29*0Sstevel@tonic-gate /* All Rights Reserved */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include "ldefs.c" 34*0Sstevel@tonic-gate #include <limits.h> 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate /* 37*0Sstevel@tonic-gate * return next line of input, throw away trailing '\n' 38*0Sstevel@tonic-gate * and also throw away trailing blanks (spaces and tabs) 39*0Sstevel@tonic-gate * returns 0 if eof is had immediately 40*0Sstevel@tonic-gate */ 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate CHR * 43*0Sstevel@tonic-gate getl(CHR *p) 44*0Sstevel@tonic-gate { 45*0Sstevel@tonic-gate int c; 46*0Sstevel@tonic-gate CHR *s, *t, *u; 47*0Sstevel@tonic-gate int blank = 0; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate t = s = p; 50*0Sstevel@tonic-gate while (((c = gch()) != 0) && c != '\n') { 51*0Sstevel@tonic-gate if (t >= &p[BUF_SIZ]) 52*0Sstevel@tonic-gate error("definitions too long"); 53*0Sstevel@tonic-gate if (c == ' ' || c == '\t') { 54*0Sstevel@tonic-gate if (!blank) { 55*0Sstevel@tonic-gate blank = 1; 56*0Sstevel@tonic-gate u = t; 57*0Sstevel@tonic-gate } 58*0Sstevel@tonic-gate } else 59*0Sstevel@tonic-gate blank = 0; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate *t++ = c; 62*0Sstevel@tonic-gate } 63*0Sstevel@tonic-gate if (blank) 64*0Sstevel@tonic-gate *u = 0; 65*0Sstevel@tonic-gate else 66*0Sstevel@tonic-gate *t = 0; 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate if (c == 0 && s == t) 69*0Sstevel@tonic-gate return ((CHR *) 0); 70*0Sstevel@tonic-gate prev = '\n'; 71*0Sstevel@tonic-gate pres = '\n'; 72*0Sstevel@tonic-gate return (s); 73*0Sstevel@tonic-gate } 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate int 76*0Sstevel@tonic-gate space(int ch) 77*0Sstevel@tonic-gate { 78*0Sstevel@tonic-gate switch (ch) { 79*0Sstevel@tonic-gate case ' ': 80*0Sstevel@tonic-gate case '\t': 81*0Sstevel@tonic-gate case '\n': 82*0Sstevel@tonic-gate return (1); 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate return (0); 85*0Sstevel@tonic-gate } 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate int 88*0Sstevel@tonic-gate digit(int c) 89*0Sstevel@tonic-gate { 90*0Sstevel@tonic-gate return (c >= '0' && c <= '9'); 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate /* VARARGS1 */ 94*0Sstevel@tonic-gate void 95*0Sstevel@tonic-gate error(s, p, d) 96*0Sstevel@tonic-gate char *s; 97*0Sstevel@tonic-gate int p, d; 98*0Sstevel@tonic-gate { 99*0Sstevel@tonic-gate /* if(!eof) */ 100*0Sstevel@tonic-gate if (!yyline) 101*0Sstevel@tonic-gate (void) fprintf(errorf, "Command line: "); 102*0Sstevel@tonic-gate else { 103*0Sstevel@tonic-gate (void) fprintf(errorf, 104*0Sstevel@tonic-gate !no_input ? "" : "\"%s\":", sargv[optind]); 105*0Sstevel@tonic-gate (void) fprintf(errorf, "line %d: ", yyline); 106*0Sstevel@tonic-gate } 107*0Sstevel@tonic-gate (void) fprintf(errorf, "Error: "); 108*0Sstevel@tonic-gate (void) fprintf(errorf, s, p, d); 109*0Sstevel@tonic-gate (void) putc('\n', errorf); 110*0Sstevel@tonic-gate if (fatal) 111*0Sstevel@tonic-gate error_tail(); 112*0Sstevel@tonic-gate } 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate void 115*0Sstevel@tonic-gate error_tail(void) 116*0Sstevel@tonic-gate { 117*0Sstevel@tonic-gate #ifdef DEBUG 118*0Sstevel@tonic-gate if (debug && sect != ENDSECTION) { 119*0Sstevel@tonic-gate sect1dump(); 120*0Sstevel@tonic-gate sect2dump(); 121*0Sstevel@tonic-gate } 122*0Sstevel@tonic-gate #endif 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate if (report == 1) 125*0Sstevel@tonic-gate statistics(); 126*0Sstevel@tonic-gate exit(1); 127*0Sstevel@tonic-gate /* NOTREACHED */ 128*0Sstevel@tonic-gate } 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* VARARGS1 */ 131*0Sstevel@tonic-gate void 132*0Sstevel@tonic-gate warning(s, p, d) 133*0Sstevel@tonic-gate char *s; 134*0Sstevel@tonic-gate int p, d; 135*0Sstevel@tonic-gate { 136*0Sstevel@tonic-gate if (!eof) 137*0Sstevel@tonic-gate if (!yyline) 138*0Sstevel@tonic-gate (void) fprintf(errorf, "Command line: "); 139*0Sstevel@tonic-gate else { 140*0Sstevel@tonic-gate (void) fprintf(errorf, 141*0Sstevel@tonic-gate !no_input?"":"\"%s\":", sargv[optind]); 142*0Sstevel@tonic-gate (void) fprintf(errorf, 143*0Sstevel@tonic-gate "line %d: ", yyline); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate (void) fprintf(errorf, "Warning: "); 146*0Sstevel@tonic-gate (void) fprintf(errorf, s, p, d); 147*0Sstevel@tonic-gate (void) putc('\n', errorf); 148*0Sstevel@tonic-gate (void) fflush(errorf); 149*0Sstevel@tonic-gate if (fout) 150*0Sstevel@tonic-gate (void) fflush(fout); 151*0Sstevel@tonic-gate (void) fflush(stdout); 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate int 155*0Sstevel@tonic-gate index(int a, CHR *s) 156*0Sstevel@tonic-gate { 157*0Sstevel@tonic-gate int k; 158*0Sstevel@tonic-gate for (k = 0; s[k]; k++) 159*0Sstevel@tonic-gate if (s[k] == a) 160*0Sstevel@tonic-gate return (k); 161*0Sstevel@tonic-gate return (-1); 162*0Sstevel@tonic-gate } 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate int 165*0Sstevel@tonic-gate alpha(int c) 166*0Sstevel@tonic-gate { 167*0Sstevel@tonic-gate return ('a' <= c && c <= 'z' || 168*0Sstevel@tonic-gate 'A' <= c && c <= 'Z'); 169*0Sstevel@tonic-gate } 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate int 172*0Sstevel@tonic-gate printable(int c) 173*0Sstevel@tonic-gate { 174*0Sstevel@tonic-gate return (c > 040 && c < 0177); 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate void 178*0Sstevel@tonic-gate lgate(void) 179*0Sstevel@tonic-gate { 180*0Sstevel@tonic-gate char fname[20]; 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate if (lgatflg) 183*0Sstevel@tonic-gate return; 184*0Sstevel@tonic-gate lgatflg = 1; 185*0Sstevel@tonic-gate if (fout == NULL) { 186*0Sstevel@tonic-gate (void) sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c'); 187*0Sstevel@tonic-gate fout = fopen(fname, "w"); 188*0Sstevel@tonic-gate } 189*0Sstevel@tonic-gate if (fout == NULL) 190*0Sstevel@tonic-gate error("Can't open %s", fname); 191*0Sstevel@tonic-gate if (ratfor) 192*0Sstevel@tonic-gate (void) fprintf(fout, "#\n"); 193*0Sstevel@tonic-gate phead1(); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate /* 197*0Sstevel@tonic-gate * scopy(ptr to str, ptr to str) - copy first arg str to second 198*0Sstevel@tonic-gate * returns ptr to second arg 199*0Sstevel@tonic-gate */ 200*0Sstevel@tonic-gate void 201*0Sstevel@tonic-gate scopy(CHR *s, CHR *t) 202*0Sstevel@tonic-gate { 203*0Sstevel@tonic-gate CHR *i; 204*0Sstevel@tonic-gate i = t; 205*0Sstevel@tonic-gate while (*i++ = *s++); 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate /* 209*0Sstevel@tonic-gate * convert string t, return integer value 210*0Sstevel@tonic-gate */ 211*0Sstevel@tonic-gate int 212*0Sstevel@tonic-gate siconv(CHR *t) 213*0Sstevel@tonic-gate { 214*0Sstevel@tonic-gate int i, sw; 215*0Sstevel@tonic-gate CHR *s; 216*0Sstevel@tonic-gate s = t; 217*0Sstevel@tonic-gate while (space(*s)) 218*0Sstevel@tonic-gate s++; 219*0Sstevel@tonic-gate if (!digit(*s) && *s != '-') 220*0Sstevel@tonic-gate error("missing translation value"); 221*0Sstevel@tonic-gate sw = 0; 222*0Sstevel@tonic-gate if (*s == '-') { 223*0Sstevel@tonic-gate sw = 1; 224*0Sstevel@tonic-gate s++; 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate if (!digit(*s)) 227*0Sstevel@tonic-gate error("incomplete translation format"); 228*0Sstevel@tonic-gate i = 0; 229*0Sstevel@tonic-gate while ('0' <= *s && *s <= '9') 230*0Sstevel@tonic-gate i = i * 10 + (*(s++)-'0'); 231*0Sstevel@tonic-gate return (sw ? -i : i); 232*0Sstevel@tonic-gate } 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gate /* 235*0Sstevel@tonic-gate * slength(ptr to str) - return integer length of string arg 236*0Sstevel@tonic-gate * excludes '\0' terminator 237*0Sstevel@tonic-gate */ 238*0Sstevel@tonic-gate int 239*0Sstevel@tonic-gate slength(CHR *s) 240*0Sstevel@tonic-gate { 241*0Sstevel@tonic-gate int n; 242*0Sstevel@tonic-gate CHR *t; 243*0Sstevel@tonic-gate t = s; 244*0Sstevel@tonic-gate for (n = 0; *t++; n++); 245*0Sstevel@tonic-gate return (n); 246*0Sstevel@tonic-gate } 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate /* 249*0Sstevel@tonic-gate * scomp(x,y) - return -1 if x < y, 250*0Sstevel@tonic-gate * 0 if x == y, 251*0Sstevel@tonic-gate * return 1 if x > y, all lexicographically 252*0Sstevel@tonic-gate */ 253*0Sstevel@tonic-gate int 254*0Sstevel@tonic-gate scomp(CHR *x, CHR *y) 255*0Sstevel@tonic-gate { 256*0Sstevel@tonic-gate CHR *a, *d; 257*0Sstevel@tonic-gate a = (CHR *) x; 258*0Sstevel@tonic-gate d = (CHR *) y; 259*0Sstevel@tonic-gate while (*a || *d) { 260*0Sstevel@tonic-gate if (*a > *d) 261*0Sstevel@tonic-gate return (1); 262*0Sstevel@tonic-gate if (*a < *d) 263*0Sstevel@tonic-gate return (-1); 264*0Sstevel@tonic-gate a++; 265*0Sstevel@tonic-gate d++; 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate return (0); 268*0Sstevel@tonic-gate } 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate int 271*0Sstevel@tonic-gate ctrans(CHR **ss) 272*0Sstevel@tonic-gate { 273*0Sstevel@tonic-gate int c, k; 274*0Sstevel@tonic-gate if ((c = **ss) != '\\') 275*0Sstevel@tonic-gate return (c); 276*0Sstevel@tonic-gate switch (c = *++*ss) { 277*0Sstevel@tonic-gate case 'a': 278*0Sstevel@tonic-gate c = '\a'; 279*0Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character"); 280*0Sstevel@tonic-gate break; 281*0Sstevel@tonic-gate case 'v': c = '\v'; break; 282*0Sstevel@tonic-gate case 'n': c = '\n'; break; 283*0Sstevel@tonic-gate case 't': c = '\t'; break; 284*0Sstevel@tonic-gate case 'r': c = '\r'; break; 285*0Sstevel@tonic-gate case 'b': c = '\b'; break; 286*0Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */ 287*0Sstevel@tonic-gate case '\\': c = '\\'; break; 288*0Sstevel@tonic-gate case 'x': { 289*0Sstevel@tonic-gate int dd; 290*0Sstevel@tonic-gate warning("\\x is ANSI C hex escape"); 291*0Sstevel@tonic-gate if (digit((dd = *++*ss)) || 292*0Sstevel@tonic-gate ('a' <= dd && dd <= 'f') || 293*0Sstevel@tonic-gate ('A' <= dd && dd <= 'F')) { 294*0Sstevel@tonic-gate c = 0; 295*0Sstevel@tonic-gate while (digit(dd) || 296*0Sstevel@tonic-gate ('A' <= dd && dd <= 'F') || 297*0Sstevel@tonic-gate ('a' <= dd && dd <= 'f')) { 298*0Sstevel@tonic-gate if (digit(dd)) 299*0Sstevel@tonic-gate c = c*16 + dd - '0'; 300*0Sstevel@tonic-gate else if (dd >= 'a') 301*0Sstevel@tonic-gate c = c*16 + 10 + dd - 'a'; 302*0Sstevel@tonic-gate else 303*0Sstevel@tonic-gate c = c*16 + 10 + dd - 'A'; 304*0Sstevel@tonic-gate dd = *++*ss; 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate } else 307*0Sstevel@tonic-gate c = 'x'; 308*0Sstevel@tonic-gate break; 309*0Sstevel@tonic-gate } 310*0Sstevel@tonic-gate case '0': case '1': case '2': case '3': 311*0Sstevel@tonic-gate case '4': case '5': case '6': case '7': 312*0Sstevel@tonic-gate c -= '0'; 313*0Sstevel@tonic-gate while ((k = *(*ss+1)) >= '0' && k <= '7') { 314*0Sstevel@tonic-gate c = c*8 + k - '0'; 315*0Sstevel@tonic-gate (*ss)++; 316*0Sstevel@tonic-gate } 317*0Sstevel@tonic-gate break; 318*0Sstevel@tonic-gate } 319*0Sstevel@tonic-gate return (c); 320*0Sstevel@tonic-gate } 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gate void 323*0Sstevel@tonic-gate cclinter(int sw) 324*0Sstevel@tonic-gate { 325*0Sstevel@tonic-gate /* sw = 1 ==> ccl */ 326*0Sstevel@tonic-gate int i, j, k; 327*0Sstevel@tonic-gate int m; 328*0Sstevel@tonic-gate if (!sw) { /* is NCCL */ 329*0Sstevel@tonic-gate for (i = 1; i < ncg; i++) 330*0Sstevel@tonic-gate symbol[i] ^= 1; /* reverse value */ 331*0Sstevel@tonic-gate } 332*0Sstevel@tonic-gate for (i = 1; i < ncg; i++) 333*0Sstevel@tonic-gate if (symbol[i]) 334*0Sstevel@tonic-gate break; 335*0Sstevel@tonic-gate if (i >= ncg) 336*0Sstevel@tonic-gate return; 337*0Sstevel@tonic-gate i = cindex[i]; 338*0Sstevel@tonic-gate /* see if ccl is already in our table */ 339*0Sstevel@tonic-gate j = 0; 340*0Sstevel@tonic-gate if (i) { 341*0Sstevel@tonic-gate for (j = 1; j < ncg; j++) { 342*0Sstevel@tonic-gate if ((symbol[j] && cindex[j] != i) || 343*0Sstevel@tonic-gate (!symbol[j] && cindex[j] == i)) 344*0Sstevel@tonic-gate break; 345*0Sstevel@tonic-gate } 346*0Sstevel@tonic-gate } 347*0Sstevel@tonic-gate if (j >= ncg) 348*0Sstevel@tonic-gate return; /* already in */ 349*0Sstevel@tonic-gate m = 0; 350*0Sstevel@tonic-gate k = 0; 351*0Sstevel@tonic-gate for (i = 1; i < ncg; i++) { 352*0Sstevel@tonic-gate if (symbol[i]) { 353*0Sstevel@tonic-gate if (!cindex[i]) { 354*0Sstevel@tonic-gate cindex[i] = ccount; 355*0Sstevel@tonic-gate symbol[i] = 0; 356*0Sstevel@tonic-gate m = 1; 357*0Sstevel@tonic-gate } else 358*0Sstevel@tonic-gate k = 1; 359*0Sstevel@tonic-gate } 360*0Sstevel@tonic-gate } 361*0Sstevel@tonic-gate /* m == 1 implies last value of ccount has been used */ 362*0Sstevel@tonic-gate if (m) 363*0Sstevel@tonic-gate ccount++; 364*0Sstevel@tonic-gate if (k == 0) 365*0Sstevel@tonic-gate return; /* is now in as ccount wholly */ 366*0Sstevel@tonic-gate /* intersection must be computed */ 367*0Sstevel@tonic-gate for (i = 1; i < ncg; i++) { 368*0Sstevel@tonic-gate if (symbol[i]) { 369*0Sstevel@tonic-gate m = 0; 370*0Sstevel@tonic-gate j = cindex[i]; /* will be non-zero */ 371*0Sstevel@tonic-gate for (k = 1; k < ncg; k++) { 372*0Sstevel@tonic-gate if (cindex[k] == j) { 373*0Sstevel@tonic-gate if (symbol[k]) 374*0Sstevel@tonic-gate symbol[k] = 0; 375*0Sstevel@tonic-gate else { 376*0Sstevel@tonic-gate cindex[k] = ccount; 377*0Sstevel@tonic-gate m = 1; 378*0Sstevel@tonic-gate } 379*0Sstevel@tonic-gate } 380*0Sstevel@tonic-gate } 381*0Sstevel@tonic-gate if (m) 382*0Sstevel@tonic-gate ccount++; 383*0Sstevel@tonic-gate } 384*0Sstevel@tonic-gate } 385*0Sstevel@tonic-gate } 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gate int 388*0Sstevel@tonic-gate usescape(int c) 389*0Sstevel@tonic-gate { 390*0Sstevel@tonic-gate char d; 391*0Sstevel@tonic-gate switch (c) { 392*0Sstevel@tonic-gate case 'a': 393*0Sstevel@tonic-gate c = '\a'; 394*0Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character"); break; 395*0Sstevel@tonic-gate case 'v': c = '\v'; break; 396*0Sstevel@tonic-gate case 'n': c = '\n'; break; 397*0Sstevel@tonic-gate case 'r': c = '\r'; break; 398*0Sstevel@tonic-gate case 't': c = '\t'; break; 399*0Sstevel@tonic-gate case 'b': c = '\b'; break; 400*0Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */ 401*0Sstevel@tonic-gate case 'x': { 402*0Sstevel@tonic-gate int dd; 403*0Sstevel@tonic-gate if (digit((dd = gch())) || 404*0Sstevel@tonic-gate ('A' <= dd && dd <= 'F') || 405*0Sstevel@tonic-gate ('a' <= dd && dd <= 'f')) { 406*0Sstevel@tonic-gate c = 0; 407*0Sstevel@tonic-gate while (digit(dd) || 408*0Sstevel@tonic-gate ('A' <= dd && dd <= 'F') || 409*0Sstevel@tonic-gate ('a' <= dd && dd <= 'f')) { 410*0Sstevel@tonic-gate if (digit(dd)) 411*0Sstevel@tonic-gate c = c*16 + dd - '0'; 412*0Sstevel@tonic-gate else if (dd >= 'a') 413*0Sstevel@tonic-gate c = c*16 + 10 + dd - 'a'; 414*0Sstevel@tonic-gate else 415*0Sstevel@tonic-gate c = c*16 + 10 + dd - 'A'; 416*0Sstevel@tonic-gate if (!digit(peek) && 417*0Sstevel@tonic-gate !('A' <= peek && peek <= 'F') && 418*0Sstevel@tonic-gate !('a' <= peek && peek <= 'f')) 419*0Sstevel@tonic-gate break; 420*0Sstevel@tonic-gate dd = gch(); 421*0Sstevel@tonic-gate } 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate } else 424*0Sstevel@tonic-gate c = 'x'; 425*0Sstevel@tonic-gate break; 426*0Sstevel@tonic-gate } 427*0Sstevel@tonic-gate case '0': case '1': case '2': case '3': 428*0Sstevel@tonic-gate case '4': case '5': case '6': case '7': 429*0Sstevel@tonic-gate c -= '0'; 430*0Sstevel@tonic-gate while ('0' <= (d = gch()) && d <= '7') { 431*0Sstevel@tonic-gate c = c * 8 + (d-'0'); 432*0Sstevel@tonic-gate if (!('0' <= peek && peek <= '7')) break; 433*0Sstevel@tonic-gate } 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate break; 436*0Sstevel@tonic-gate } 437*0Sstevel@tonic-gate 438*0Sstevel@tonic-gate if (handleeuc && !isascii(c)) { 439*0Sstevel@tonic-gate char tmpchar = c & 0x00ff; 440*0Sstevel@tonic-gate mbtowc((wchar_t *)&c, &tmpchar, sizeof (tmpchar)); 441*0Sstevel@tonic-gate } 442*0Sstevel@tonic-gate return (c); 443*0Sstevel@tonic-gate } 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate int 446*0Sstevel@tonic-gate lookup(CHR *s, CHR **t) 447*0Sstevel@tonic-gate { 448*0Sstevel@tonic-gate int i; 449*0Sstevel@tonic-gate i = 0; 450*0Sstevel@tonic-gate while (*t) { 451*0Sstevel@tonic-gate if (scomp(s, *t) == 0) 452*0Sstevel@tonic-gate return (i); 453*0Sstevel@tonic-gate i++; 454*0Sstevel@tonic-gate t++; 455*0Sstevel@tonic-gate } 456*0Sstevel@tonic-gate return (-1); 457*0Sstevel@tonic-gate } 458*0Sstevel@tonic-gate 459*0Sstevel@tonic-gate void 460*0Sstevel@tonic-gate cpycom(CHR *p) 461*0Sstevel@tonic-gate { 462*0Sstevel@tonic-gate static CHR *t; 463*0Sstevel@tonic-gate static int c; 464*0Sstevel@tonic-gate t = p; 465*0Sstevel@tonic-gate 466*0Sstevel@tonic-gate if (sargv[optind] == NULL) 467*0Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline); 468*0Sstevel@tonic-gate else 469*0Sstevel@tonic-gate (void) fprintf(fout, 470*0Sstevel@tonic-gate "\n# line %d \"%s\"\n", yyline, sargv[optind]); 471*0Sstevel@tonic-gate 472*0Sstevel@tonic-gate (void) putc(*t++, fout); 473*0Sstevel@tonic-gate (void) putc(*t++, fout); 474*0Sstevel@tonic-gate while (*t) { 475*0Sstevel@tonic-gate while (*t == '*') { 476*0Sstevel@tonic-gate (void) putc(*t++, fout); 477*0Sstevel@tonic-gate if (*t == '/') 478*0Sstevel@tonic-gate goto backcall; 479*0Sstevel@tonic-gate } 480*0Sstevel@tonic-gate /* 481*0Sstevel@tonic-gate * FIX BUG #1058428, not parsing comments correctly 482*0Sstevel@tonic-gate * that span more than one line 483*0Sstevel@tonic-gate */ 484*0Sstevel@tonic-gate if (*t != NULL) 485*0Sstevel@tonic-gate (void) putc(*t++, fout); 486*0Sstevel@tonic-gate } 487*0Sstevel@tonic-gate (void) putc('\n', fout); 488*0Sstevel@tonic-gate while (c = gch()) { 489*0Sstevel@tonic-gate while (c == '*') { 490*0Sstevel@tonic-gate (void) putc((char)c, fout); 491*0Sstevel@tonic-gate if ((c = gch()) == '/') { 492*0Sstevel@tonic-gate while ((c = gch()) == ' ' || c == '\t'); 493*0Sstevel@tonic-gate if (!space(c)) 494*0Sstevel@tonic-gate error("unacceptable statement"); 495*0Sstevel@tonic-gate prev = '\n'; 496*0Sstevel@tonic-gate goto backcall; 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate } 499*0Sstevel@tonic-gate (void) putc((char)c, fout); 500*0Sstevel@tonic-gate } 501*0Sstevel@tonic-gate error("unexpected EOF inside comment"); 502*0Sstevel@tonic-gate backcall: 503*0Sstevel@tonic-gate (void) putc('/', fout); 504*0Sstevel@tonic-gate (void) putc('\n', fout); 505*0Sstevel@tonic-gate } 506*0Sstevel@tonic-gate 507*0Sstevel@tonic-gate /* 508*0Sstevel@tonic-gate * copy C action to the next ; or closing 509*0Sstevel@tonic-gate */ 510*0Sstevel@tonic-gate int 511*0Sstevel@tonic-gate cpyact(void) 512*0Sstevel@tonic-gate { 513*0Sstevel@tonic-gate int brac, c, mth; 514*0Sstevel@tonic-gate static int sw, savline; 515*0Sstevel@tonic-gate 516*0Sstevel@tonic-gate brac = 0; 517*0Sstevel@tonic-gate sw = TRUE; 518*0Sstevel@tonic-gate savline = yyline; 519*0Sstevel@tonic-gate 520*0Sstevel@tonic-gate if (sargv[optind] == NULL) 521*0Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline); 522*0Sstevel@tonic-gate else 523*0Sstevel@tonic-gate (void) fprintf(fout, 524*0Sstevel@tonic-gate "\n# line %d \"%s\"\n", yyline, sargv[optind]); 525*0Sstevel@tonic-gate 526*0Sstevel@tonic-gate while (!eof) { 527*0Sstevel@tonic-gate c = gch(); 528*0Sstevel@tonic-gate swt: 529*0Sstevel@tonic-gate switch (c) { 530*0Sstevel@tonic-gate case '|': 531*0Sstevel@tonic-gate if (brac == 0 && sw == TRUE) { 532*0Sstevel@tonic-gate if (peek == '|') 533*0Sstevel@tonic-gate (void) gch(); /* eat up an extra '|' */ 534*0Sstevel@tonic-gate return (0); 535*0Sstevel@tonic-gate } 536*0Sstevel@tonic-gate break; 537*0Sstevel@tonic-gate case ';': 538*0Sstevel@tonic-gate if (brac == 0) { 539*0Sstevel@tonic-gate (void) putwc(c, fout); 540*0Sstevel@tonic-gate (void) putc('\n', fout); 541*0Sstevel@tonic-gate return (1); 542*0Sstevel@tonic-gate } 543*0Sstevel@tonic-gate break; 544*0Sstevel@tonic-gate case '{': 545*0Sstevel@tonic-gate brac++; 546*0Sstevel@tonic-gate savline = yyline; 547*0Sstevel@tonic-gate break; 548*0Sstevel@tonic-gate case '}': 549*0Sstevel@tonic-gate brac--; 550*0Sstevel@tonic-gate if (brac == 0) { 551*0Sstevel@tonic-gate (void) putwc(c, fout); 552*0Sstevel@tonic-gate (void) putc('\n', fout); 553*0Sstevel@tonic-gate return (1); 554*0Sstevel@tonic-gate } 555*0Sstevel@tonic-gate break; 556*0Sstevel@tonic-gate case '/': 557*0Sstevel@tonic-gate (void) putwc(c, fout); 558*0Sstevel@tonic-gate c = gch(); 559*0Sstevel@tonic-gate if (c != '*') 560*0Sstevel@tonic-gate goto swt; 561*0Sstevel@tonic-gate (void) putwc(c, fout); 562*0Sstevel@tonic-gate savline = yyline; 563*0Sstevel@tonic-gate while (c = gch()) { 564*0Sstevel@tonic-gate while (c == '*') { 565*0Sstevel@tonic-gate (void) putwc(c, fout); 566*0Sstevel@tonic-gate if ((c = gch()) == '/') { 567*0Sstevel@tonic-gate (void) putc('/', fout); 568*0Sstevel@tonic-gate while ((c = gch()) == ' ' || 569*0Sstevel@tonic-gate c == '\t' || c == '\n') 570*0Sstevel@tonic-gate (void) putwc(c, fout); 571*0Sstevel@tonic-gate goto swt; 572*0Sstevel@tonic-gate } 573*0Sstevel@tonic-gate } 574*0Sstevel@tonic-gate (void) putc((char)c, fout); 575*0Sstevel@tonic-gate } 576*0Sstevel@tonic-gate yyline = savline; 577*0Sstevel@tonic-gate error("EOF inside comment"); 578*0Sstevel@tonic-gate /* NOTREACHED */ 579*0Sstevel@tonic-gate break; 580*0Sstevel@tonic-gate case '\'': /* character constant */ 581*0Sstevel@tonic-gate case '"': /* character string */ 582*0Sstevel@tonic-gate mth = c; 583*0Sstevel@tonic-gate (void) putwc(c, fout); 584*0Sstevel@tonic-gate while (c = gch()) { 585*0Sstevel@tonic-gate if (c == '\\') { 586*0Sstevel@tonic-gate (void) putwc(c, fout); 587*0Sstevel@tonic-gate c = gch(); 588*0Sstevel@tonic-gate } 589*0Sstevel@tonic-gate else 590*0Sstevel@tonic-gate if (c == mth) 591*0Sstevel@tonic-gate goto loop; 592*0Sstevel@tonic-gate (void) putwc(c, fout); 593*0Sstevel@tonic-gate if (c == '\n') { 594*0Sstevel@tonic-gate yyline--; 595*0Sstevel@tonic-gate error( 596*0Sstevel@tonic-gate "Non-terminated string or character constant"); 597*0Sstevel@tonic-gate } 598*0Sstevel@tonic-gate } 599*0Sstevel@tonic-gate error("EOF in string or character constant"); 600*0Sstevel@tonic-gate /* NOTREACHED */ 601*0Sstevel@tonic-gate break; 602*0Sstevel@tonic-gate case '\0': 603*0Sstevel@tonic-gate yyline = savline; 604*0Sstevel@tonic-gate error("Action does not terminate"); 605*0Sstevel@tonic-gate /* NOTREACHED */ 606*0Sstevel@tonic-gate break; 607*0Sstevel@tonic-gate default: 608*0Sstevel@tonic-gate break; /* usual character */ 609*0Sstevel@tonic-gate } 610*0Sstevel@tonic-gate loop: 611*0Sstevel@tonic-gate if (c != ' ' && c != '\t' && c != '\n') 612*0Sstevel@tonic-gate sw = FALSE; 613*0Sstevel@tonic-gate (void) putwc(c, fout); 614*0Sstevel@tonic-gate if (peek == '\n' && !brac && copy_line) { 615*0Sstevel@tonic-gate (void) putc('\n', fout); 616*0Sstevel@tonic-gate return (1); 617*0Sstevel@tonic-gate } 618*0Sstevel@tonic-gate } 619*0Sstevel@tonic-gate error("Premature EOF"); 620*0Sstevel@tonic-gate return (0); 621*0Sstevel@tonic-gate } 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate int 624*0Sstevel@tonic-gate gch(void) 625*0Sstevel@tonic-gate { 626*0Sstevel@tonic-gate int c; 627*0Sstevel@tonic-gate prev = pres; 628*0Sstevel@tonic-gate c = pres = peek; 629*0Sstevel@tonic-gate peek = pushptr > pushc ? *--pushptr : getwc(fin); 630*0Sstevel@tonic-gate while (peek == EOF) { 631*0Sstevel@tonic-gate if (no_input) { 632*0Sstevel@tonic-gate if (!yyline) 633*0Sstevel@tonic-gate error("Cannot read from -- %s", 634*0Sstevel@tonic-gate sargv[optind]); 635*0Sstevel@tonic-gate if (optind < sargc-1) { 636*0Sstevel@tonic-gate yyline = 0; 637*0Sstevel@tonic-gate if (fin != stdin) 638*0Sstevel@tonic-gate (void) fclose(fin); 639*0Sstevel@tonic-gate fin = fopen(sargv[++optind], "r"); 640*0Sstevel@tonic-gate if (fin == NULL) 641*0Sstevel@tonic-gate error("Cannot open file -- %s", 642*0Sstevel@tonic-gate sargv[optind]); 643*0Sstevel@tonic-gate peek = getwc(fin); 644*0Sstevel@tonic-gate } else 645*0Sstevel@tonic-gate break; 646*0Sstevel@tonic-gate } else { 647*0Sstevel@tonic-gate if (fin != stdin) 648*0Sstevel@tonic-gate (void) fclose(fin); 649*0Sstevel@tonic-gate if (!yyline) 650*0Sstevel@tonic-gate error("Cannot read from -- standard input"); 651*0Sstevel@tonic-gate else 652*0Sstevel@tonic-gate break; 653*0Sstevel@tonic-gate } 654*0Sstevel@tonic-gate } 655*0Sstevel@tonic-gate if (c == EOF) { 656*0Sstevel@tonic-gate eof = TRUE; 657*0Sstevel@tonic-gate return (0); 658*0Sstevel@tonic-gate } 659*0Sstevel@tonic-gate if (c == '\n') 660*0Sstevel@tonic-gate yyline++; 661*0Sstevel@tonic-gate return (c); 662*0Sstevel@tonic-gate } 663*0Sstevel@tonic-gate 664*0Sstevel@tonic-gate int 665*0Sstevel@tonic-gate mn2(int a, int d, int c) 666*0Sstevel@tonic-gate { 667*0Sstevel@tonic-gate if (tptr >= treesize) { 668*0Sstevel@tonic-gate tptr++; 669*0Sstevel@tonic-gate error("Parse tree too big %s", 670*0Sstevel@tonic-gate (treesize == TREESIZE ? "\nTry using %e num" : "")); 671*0Sstevel@tonic-gate } 672*0Sstevel@tonic-gate if (d >= treesize) { 673*0Sstevel@tonic-gate error("Parse error"); 674*0Sstevel@tonic-gate } 675*0Sstevel@tonic-gate name[tptr] = a; 676*0Sstevel@tonic-gate left[tptr] = d; 677*0Sstevel@tonic-gate right[tptr] = c; 678*0Sstevel@tonic-gate parent[tptr] = 0; 679*0Sstevel@tonic-gate nullstr[tptr] = 0; 680*0Sstevel@tonic-gate switch (a) { 681*0Sstevel@tonic-gate case RSTR: 682*0Sstevel@tonic-gate parent[d] = tptr; 683*0Sstevel@tonic-gate break; 684*0Sstevel@tonic-gate case BAR: 685*0Sstevel@tonic-gate case RNEWE: 686*0Sstevel@tonic-gate if (nullstr[d] || nullstr[c]) 687*0Sstevel@tonic-gate nullstr[tptr] = TRUE; 688*0Sstevel@tonic-gate parent[d] = parent[c] = tptr; 689*0Sstevel@tonic-gate break; 690*0Sstevel@tonic-gate case RCAT: 691*0Sstevel@tonic-gate case DIV: 692*0Sstevel@tonic-gate if (nullstr[d] && nullstr[c]) 693*0Sstevel@tonic-gate nullstr[tptr] = TRUE; 694*0Sstevel@tonic-gate parent[d] = parent[c] = tptr; 695*0Sstevel@tonic-gate break; 696*0Sstevel@tonic-gate /* XCU4: add RXSCON */ 697*0Sstevel@tonic-gate case RXSCON: 698*0Sstevel@tonic-gate case RSCON: 699*0Sstevel@tonic-gate parent[d] = tptr; 700*0Sstevel@tonic-gate nullstr[tptr] = nullstr[d]; 701*0Sstevel@tonic-gate break; 702*0Sstevel@tonic-gate #ifdef DEBUG 703*0Sstevel@tonic-gate default: 704*0Sstevel@tonic-gate warning("bad switch mn2 %d %d", a, d); 705*0Sstevel@tonic-gate break; 706*0Sstevel@tonic-gate #endif 707*0Sstevel@tonic-gate } 708*0Sstevel@tonic-gate return (tptr++); 709*0Sstevel@tonic-gate } 710*0Sstevel@tonic-gate 711*0Sstevel@tonic-gate int 712*0Sstevel@tonic-gate mn1(int a, int d) 713*0Sstevel@tonic-gate { 714*0Sstevel@tonic-gate if (tptr >= treesize) { 715*0Sstevel@tonic-gate tptr++; 716*0Sstevel@tonic-gate error("Parse tree too big %s", 717*0Sstevel@tonic-gate (treesize == TREESIZE ? "\nTry using %e num" : "")); 718*0Sstevel@tonic-gate } 719*0Sstevel@tonic-gate name[tptr] = a; 720*0Sstevel@tonic-gate left[tptr] = d; 721*0Sstevel@tonic-gate parent[tptr] = 0; 722*0Sstevel@tonic-gate nullstr[tptr] = 0; 723*0Sstevel@tonic-gate switch (a) { 724*0Sstevel@tonic-gate case RCCL: 725*0Sstevel@tonic-gate case RNCCL: 726*0Sstevel@tonic-gate if (slength((CHR *)d) == 0) 727*0Sstevel@tonic-gate nullstr[tptr] = TRUE; 728*0Sstevel@tonic-gate break; 729*0Sstevel@tonic-gate case STAR: 730*0Sstevel@tonic-gate case QUEST: 731*0Sstevel@tonic-gate nullstr[tptr] = TRUE; 732*0Sstevel@tonic-gate parent[d] = tptr; 733*0Sstevel@tonic-gate break; 734*0Sstevel@tonic-gate case PLUS: 735*0Sstevel@tonic-gate case CARAT: 736*0Sstevel@tonic-gate nullstr[tptr] = nullstr[d]; 737*0Sstevel@tonic-gate parent[d] = tptr; 738*0Sstevel@tonic-gate break; 739*0Sstevel@tonic-gate case S2FINAL: 740*0Sstevel@tonic-gate nullstr[tptr] = TRUE; 741*0Sstevel@tonic-gate break; 742*0Sstevel@tonic-gate #ifdef DEBUG 743*0Sstevel@tonic-gate case FINAL: 744*0Sstevel@tonic-gate case S1FINAL: 745*0Sstevel@tonic-gate break; 746*0Sstevel@tonic-gate default: 747*0Sstevel@tonic-gate warning("bad switch mn1 %d %d", a, d); 748*0Sstevel@tonic-gate break; 749*0Sstevel@tonic-gate #endif 750*0Sstevel@tonic-gate } 751*0Sstevel@tonic-gate return (tptr++); 752*0Sstevel@tonic-gate } 753*0Sstevel@tonic-gate 754*0Sstevel@tonic-gate int 755*0Sstevel@tonic-gate mn0(int a) 756*0Sstevel@tonic-gate { 757*0Sstevel@tonic-gate if (tptr >= treesize) { 758*0Sstevel@tonic-gate tptr++; 759*0Sstevel@tonic-gate error("Parse tree too big %s", 760*0Sstevel@tonic-gate (treesize == TREESIZE ? "\nTry using %e num" : "")); 761*0Sstevel@tonic-gate } 762*0Sstevel@tonic-gate 763*0Sstevel@tonic-gate name[tptr] = a; 764*0Sstevel@tonic-gate parent[tptr] = 0; 765*0Sstevel@tonic-gate nullstr[tptr] = 0; 766*0Sstevel@tonic-gate if (ISOPERATOR(a)) { 767*0Sstevel@tonic-gate switch (a) { 768*0Sstevel@tonic-gate case DOT: break; 769*0Sstevel@tonic-gate case RNULLS: nullstr[tptr] = TRUE; break; 770*0Sstevel@tonic-gate #ifdef DEBUG 771*0Sstevel@tonic-gate default: 772*0Sstevel@tonic-gate warning("bad switch mn0 %d", a); 773*0Sstevel@tonic-gate break; 774*0Sstevel@tonic-gate #endif 775*0Sstevel@tonic-gate } 776*0Sstevel@tonic-gate } 777*0Sstevel@tonic-gate return (tptr++); 778*0Sstevel@tonic-gate } 779*0Sstevel@tonic-gate 780*0Sstevel@tonic-gate void 781*0Sstevel@tonic-gate munput(int t, CHR *p) 782*0Sstevel@tonic-gate { 783*0Sstevel@tonic-gate int i, j; 784*0Sstevel@tonic-gate if (t == 'c') { 785*0Sstevel@tonic-gate *pushptr++ = peek; 786*0Sstevel@tonic-gate peek = *p; 787*0Sstevel@tonic-gate } else if (t == 's') { 788*0Sstevel@tonic-gate *pushptr++ = peek; 789*0Sstevel@tonic-gate peek = p[0]; 790*0Sstevel@tonic-gate i = slength(p); 791*0Sstevel@tonic-gate for (j = i - 1; j >= 1; j--) 792*0Sstevel@tonic-gate *pushptr++ = p[j]; 793*0Sstevel@tonic-gate } 794*0Sstevel@tonic-gate if (pushptr >= pushc + TOKENSIZE) 795*0Sstevel@tonic-gate error("Too many characters pushed"); 796*0Sstevel@tonic-gate } 797*0Sstevel@tonic-gate 798*0Sstevel@tonic-gate int 799*0Sstevel@tonic-gate dupl(int n) 800*0Sstevel@tonic-gate { 801*0Sstevel@tonic-gate /* duplicate the subtree whose root is n, return ptr to it */ 802*0Sstevel@tonic-gate int i; 803*0Sstevel@tonic-gate i = name[n]; 804*0Sstevel@tonic-gate if (!ISOPERATOR(i)) 805*0Sstevel@tonic-gate return (mn0(i)); 806*0Sstevel@tonic-gate switch (i) { 807*0Sstevel@tonic-gate case DOT: 808*0Sstevel@tonic-gate case RNULLS: 809*0Sstevel@tonic-gate return (mn0(i)); 810*0Sstevel@tonic-gate case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL: 811*0Sstevel@tonic-gate return (mn1(i, left[n])); 812*0Sstevel@tonic-gate case STAR: case QUEST: case PLUS: case CARAT: 813*0Sstevel@tonic-gate return (mn1(i, dupl(left[n]))); 814*0Sstevel@tonic-gate 815*0Sstevel@tonic-gate /* XCU4: add RXSCON */ 816*0Sstevel@tonic-gate case RSTR: case RSCON: case RXSCON: 817*0Sstevel@tonic-gate return (mn2(i, dupl(left[n]), right[n])); 818*0Sstevel@tonic-gate case BAR: case RNEWE: case RCAT: case DIV: 819*0Sstevel@tonic-gate return (mn2(i, dupl(left[n]), dupl(right[n]))); 820*0Sstevel@tonic-gate } 821*0Sstevel@tonic-gate return (0); 822*0Sstevel@tonic-gate } 823*0Sstevel@tonic-gate 824*0Sstevel@tonic-gate #ifdef DEBUG 825*0Sstevel@tonic-gate void 826*0Sstevel@tonic-gate allprint(CHR c) 827*0Sstevel@tonic-gate { 828*0Sstevel@tonic-gate switch (c) { 829*0Sstevel@tonic-gate case 014: 830*0Sstevel@tonic-gate (void) printf("\\f"); 831*0Sstevel@tonic-gate charc++; 832*0Sstevel@tonic-gate break; 833*0Sstevel@tonic-gate case '\n': 834*0Sstevel@tonic-gate (void) printf("\\n"); 835*0Sstevel@tonic-gate charc++; 836*0Sstevel@tonic-gate break; 837*0Sstevel@tonic-gate case '\t': 838*0Sstevel@tonic-gate (void) printf("\\t"); 839*0Sstevel@tonic-gate charc++; 840*0Sstevel@tonic-gate break; 841*0Sstevel@tonic-gate case '\b': 842*0Sstevel@tonic-gate (void) printf("\\b"); 843*0Sstevel@tonic-gate charc++; 844*0Sstevel@tonic-gate break; 845*0Sstevel@tonic-gate case ' ': 846*0Sstevel@tonic-gate (void) printf("\\_"); 847*0Sstevel@tonic-gate break; 848*0Sstevel@tonic-gate default: 849*0Sstevel@tonic-gate if (!iswprint(c)) { 850*0Sstevel@tonic-gate printf("\\x%-2x", c); /* up to fashion. */ 851*0Sstevel@tonic-gate charc += 3; 852*0Sstevel@tonic-gate } else 853*0Sstevel@tonic-gate (void) putwc(c, stdout); 854*0Sstevel@tonic-gate break; 855*0Sstevel@tonic-gate } 856*0Sstevel@tonic-gate charc++; 857*0Sstevel@tonic-gate } 858*0Sstevel@tonic-gate 859*0Sstevel@tonic-gate void 860*0Sstevel@tonic-gate strpt(CHR *s) 861*0Sstevel@tonic-gate { 862*0Sstevel@tonic-gate charc = 0; 863*0Sstevel@tonic-gate while (*s) { 864*0Sstevel@tonic-gate allprint(*s++); 865*0Sstevel@tonic-gate if (charc > LINESIZE) { 866*0Sstevel@tonic-gate charc = 0; 867*0Sstevel@tonic-gate (void) printf("\n\t"); 868*0Sstevel@tonic-gate } 869*0Sstevel@tonic-gate } 870*0Sstevel@tonic-gate } 871*0Sstevel@tonic-gate 872*0Sstevel@tonic-gate void 873*0Sstevel@tonic-gate sect1dump(void) 874*0Sstevel@tonic-gate { 875*0Sstevel@tonic-gate int i; 876*0Sstevel@tonic-gate (void) printf("Sect 1:\n"); 877*0Sstevel@tonic-gate if (def[0]) { 878*0Sstevel@tonic-gate (void) printf("str trans\n"); 879*0Sstevel@tonic-gate i = -1; 880*0Sstevel@tonic-gate while (def[++i]) 881*0Sstevel@tonic-gate (void) printf("%ws\t%ws\n", def[i], subs[i]); 882*0Sstevel@tonic-gate } 883*0Sstevel@tonic-gate if (sname[0]) { 884*0Sstevel@tonic-gate (void) printf("start names\n"); 885*0Sstevel@tonic-gate i = -1; 886*0Sstevel@tonic-gate while (sname[++i]) 887*0Sstevel@tonic-gate (void) printf("%ws\n", sname[i]); 888*0Sstevel@tonic-gate } 889*0Sstevel@tonic-gate if (chset == TRUE) { 890*0Sstevel@tonic-gate (void) printf("char set changed\n"); 891*0Sstevel@tonic-gate for (i = 1; i < NCH; i++) { 892*0Sstevel@tonic-gate if (i != ctable[i]) { 893*0Sstevel@tonic-gate allprint(i); 894*0Sstevel@tonic-gate (void) putchar(' '); 895*0Sstevel@tonic-gate iswprint(ctable[i]) ? 896*0Sstevel@tonic-gate (void) putwc(ctable[i], stdout) : 897*0Sstevel@tonic-gate (void) printf("%d", ctable[i]); 898*0Sstevel@tonic-gate (void) putchar('\n'); 899*0Sstevel@tonic-gate } 900*0Sstevel@tonic-gate } 901*0Sstevel@tonic-gate } 902*0Sstevel@tonic-gate } 903*0Sstevel@tonic-gate 904*0Sstevel@tonic-gate void 905*0Sstevel@tonic-gate sect2dump(void) 906*0Sstevel@tonic-gate { 907*0Sstevel@tonic-gate (void) printf("Sect 2:\n"); 908*0Sstevel@tonic-gate treedump(); 909*0Sstevel@tonic-gate } 910*0Sstevel@tonic-gate 911*0Sstevel@tonic-gate void 912*0Sstevel@tonic-gate treedump(void) 913*0Sstevel@tonic-gate { 914*0Sstevel@tonic-gate int t; 915*0Sstevel@tonic-gate CHR *p; 916*0Sstevel@tonic-gate (void) printf("treedump %d nodes:\n", tptr); 917*0Sstevel@tonic-gate for (t = 0; t < tptr; t++) { 918*0Sstevel@tonic-gate (void) printf("%4d ", t); 919*0Sstevel@tonic-gate parent[t] ? (void) printf("p=%4d", parent[t]) : 920*0Sstevel@tonic-gate (void) printf(" "); 921*0Sstevel@tonic-gate (void) printf(" "); 922*0Sstevel@tonic-gate if (!ISOPERATOR(name[t])) { 923*0Sstevel@tonic-gate allprint(name[t]); 924*0Sstevel@tonic-gate } else 925*0Sstevel@tonic-gate switch (name[t]) { 926*0Sstevel@tonic-gate case RSTR: 927*0Sstevel@tonic-gate (void) printf("%d ", left[t]); 928*0Sstevel@tonic-gate allprint(right[t]); 929*0Sstevel@tonic-gate break; 930*0Sstevel@tonic-gate case RCCL: 931*0Sstevel@tonic-gate (void) printf("ccl "); 932*0Sstevel@tonic-gate strpt(left[t]); 933*0Sstevel@tonic-gate break; 934*0Sstevel@tonic-gate case RNCCL: 935*0Sstevel@tonic-gate (void) printf("nccl "); 936*0Sstevel@tonic-gate strpt(left[t]); 937*0Sstevel@tonic-gate break; 938*0Sstevel@tonic-gate case DIV: 939*0Sstevel@tonic-gate (void) printf("/ %d %d", left[t], right[t]); 940*0Sstevel@tonic-gate break; 941*0Sstevel@tonic-gate case BAR: 942*0Sstevel@tonic-gate (void) printf("| %d %d", left[t], right[t]); 943*0Sstevel@tonic-gate break; 944*0Sstevel@tonic-gate case RCAT: 945*0Sstevel@tonic-gate (void) printf("cat %d %d", left[t], right[t]); 946*0Sstevel@tonic-gate break; 947*0Sstevel@tonic-gate case PLUS: 948*0Sstevel@tonic-gate (void) printf("+ %d", left[t]); 949*0Sstevel@tonic-gate break; 950*0Sstevel@tonic-gate case STAR: 951*0Sstevel@tonic-gate (void) printf("* %d", left[t]); 952*0Sstevel@tonic-gate break; 953*0Sstevel@tonic-gate case CARAT: 954*0Sstevel@tonic-gate (void) printf("^ %d", left[t]); 955*0Sstevel@tonic-gate break; 956*0Sstevel@tonic-gate case QUEST: 957*0Sstevel@tonic-gate (void) printf("? %d", left[t]); 958*0Sstevel@tonic-gate break; 959*0Sstevel@tonic-gate case RNULLS: 960*0Sstevel@tonic-gate (void) printf("nullstring"); 961*0Sstevel@tonic-gate break; 962*0Sstevel@tonic-gate case FINAL: 963*0Sstevel@tonic-gate (void) printf("final %d", left[t]); 964*0Sstevel@tonic-gate break; 965*0Sstevel@tonic-gate case S1FINAL: 966*0Sstevel@tonic-gate (void) printf("s1final %d", left[t]); 967*0Sstevel@tonic-gate break; 968*0Sstevel@tonic-gate case S2FINAL: 969*0Sstevel@tonic-gate (void) printf("s2final %d", left[t]); 970*0Sstevel@tonic-gate break; 971*0Sstevel@tonic-gate case RNEWE: 972*0Sstevel@tonic-gate (void) printf("new %d %d", left[t], right[t]); 973*0Sstevel@tonic-gate break; 974*0Sstevel@tonic-gate 975*0Sstevel@tonic-gate /* XCU4: add RXSCON */ 976*0Sstevel@tonic-gate case RXSCON: 977*0Sstevel@tonic-gate p = (CHR *)right[t]; 978*0Sstevel@tonic-gate (void) printf("exstart %s", sname[*p++-1]); 979*0Sstevel@tonic-gate while (*p) 980*0Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]); 981*0Sstevel@tonic-gate (void) printf(" %d", left[t]); 982*0Sstevel@tonic-gate break; 983*0Sstevel@tonic-gate case RSCON: 984*0Sstevel@tonic-gate p = (CHR *)right[t]; 985*0Sstevel@tonic-gate (void) printf("start %s", sname[*p++-1]); 986*0Sstevel@tonic-gate while (*p) 987*0Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]); 988*0Sstevel@tonic-gate (void) printf(" %d", left[t]); 989*0Sstevel@tonic-gate break; 990*0Sstevel@tonic-gate case DOT: 991*0Sstevel@tonic-gate printf("dot"); 992*0Sstevel@tonic-gate break; 993*0Sstevel@tonic-gate default: 994*0Sstevel@tonic-gate (void) printf( 995*0Sstevel@tonic-gate "unknown %d %d %d", name[t], left[t], right[t]); 996*0Sstevel@tonic-gate break; 997*0Sstevel@tonic-gate } 998*0Sstevel@tonic-gate if (nullstr[t]) 999*0Sstevel@tonic-gate (void) printf("\t(null poss.)"); 1000*0Sstevel@tonic-gate (void) putchar('\n'); 1001*0Sstevel@tonic-gate } 1002*0Sstevel@tonic-gate } 1003*0Sstevel@tonic-gate #endif 1004