10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54538Sdamico * Common Development and Distribution License (the "License").
64538Sdamico * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*6951Sab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
300Sstevel@tonic-gate
314538Sdamico #include "ldefs.h"
320Sstevel@tonic-gate #include <limits.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate /*
350Sstevel@tonic-gate * return next line of input, throw away trailing '\n'
360Sstevel@tonic-gate * and also throw away trailing blanks (spaces and tabs)
370Sstevel@tonic-gate * returns 0 if eof is had immediately
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
400Sstevel@tonic-gate CHR *
getl(CHR * p)410Sstevel@tonic-gate getl(CHR *p)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate int c;
440Sstevel@tonic-gate CHR *s, *t, *u;
450Sstevel@tonic-gate int blank = 0;
460Sstevel@tonic-gate
470Sstevel@tonic-gate t = s = p;
480Sstevel@tonic-gate while (((c = gch()) != 0) && c != '\n') {
490Sstevel@tonic-gate if (t >= &p[BUF_SIZ])
500Sstevel@tonic-gate error("definitions too long");
510Sstevel@tonic-gate if (c == ' ' || c == '\t') {
524538Sdamico if (!blank) {
534538Sdamico blank = 1;
544538Sdamico u = t;
554538Sdamico }
560Sstevel@tonic-gate } else
570Sstevel@tonic-gate blank = 0;
580Sstevel@tonic-gate
590Sstevel@tonic-gate *t++ = c;
600Sstevel@tonic-gate }
610Sstevel@tonic-gate if (blank)
620Sstevel@tonic-gate *u = 0;
630Sstevel@tonic-gate else
640Sstevel@tonic-gate *t = 0;
650Sstevel@tonic-gate
660Sstevel@tonic-gate if (c == 0 && s == t)
670Sstevel@tonic-gate return ((CHR *) 0);
680Sstevel@tonic-gate prev = '\n';
690Sstevel@tonic-gate pres = '\n';
700Sstevel@tonic-gate return (s);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
730Sstevel@tonic-gate int
space(int ch)740Sstevel@tonic-gate space(int ch)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate switch (ch) {
770Sstevel@tonic-gate case ' ':
780Sstevel@tonic-gate case '\t':
790Sstevel@tonic-gate case '\n':
800Sstevel@tonic-gate return (1);
810Sstevel@tonic-gate }
820Sstevel@tonic-gate return (0);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate int
digit(int c)860Sstevel@tonic-gate digit(int c)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate return (c >= '0' && c <= '9');
890Sstevel@tonic-gate }
900Sstevel@tonic-gate
910Sstevel@tonic-gate /* VARARGS1 */
920Sstevel@tonic-gate void
error(s,p,d)930Sstevel@tonic-gate error(s, p, d)
940Sstevel@tonic-gate char *s;
950Sstevel@tonic-gate int p, d;
960Sstevel@tonic-gate {
970Sstevel@tonic-gate /* if(!eof) */
980Sstevel@tonic-gate if (!yyline)
990Sstevel@tonic-gate (void) fprintf(errorf, "Command line: ");
1000Sstevel@tonic-gate else {
1010Sstevel@tonic-gate (void) fprintf(errorf,
1020Sstevel@tonic-gate !no_input ? "" : "\"%s\":", sargv[optind]);
1030Sstevel@tonic-gate (void) fprintf(errorf, "line %d: ", yyline);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate (void) fprintf(errorf, "Error: ");
106*6951Sab196087 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
1070Sstevel@tonic-gate (void) fprintf(errorf, s, p, d);
1080Sstevel@tonic-gate (void) putc('\n', errorf);
1090Sstevel@tonic-gate if (fatal)
1100Sstevel@tonic-gate error_tail();
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate void
error_tail(void)1140Sstevel@tonic-gate error_tail(void)
1150Sstevel@tonic-gate {
1160Sstevel@tonic-gate #ifdef DEBUG
1170Sstevel@tonic-gate if (debug && sect != ENDSECTION) {
1180Sstevel@tonic-gate sect1dump();
1190Sstevel@tonic-gate sect2dump();
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate #endif
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate if (report == 1)
1240Sstevel@tonic-gate statistics();
1250Sstevel@tonic-gate exit(1);
1260Sstevel@tonic-gate /* NOTREACHED */
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate /* VARARGS1 */
1300Sstevel@tonic-gate void
warning(s,p,d)1310Sstevel@tonic-gate warning(s, p, d)
1320Sstevel@tonic-gate char *s;
1330Sstevel@tonic-gate int p, d;
1340Sstevel@tonic-gate {
1350Sstevel@tonic-gate if (!eof)
1360Sstevel@tonic-gate if (!yyline)
1370Sstevel@tonic-gate (void) fprintf(errorf, "Command line: ");
1380Sstevel@tonic-gate else {
1390Sstevel@tonic-gate (void) fprintf(errorf,
1400Sstevel@tonic-gate !no_input?"":"\"%s\":", sargv[optind]);
1410Sstevel@tonic-gate (void) fprintf(errorf,
1420Sstevel@tonic-gate "line %d: ", yyline);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate (void) fprintf(errorf, "Warning: ");
145*6951Sab196087 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
1460Sstevel@tonic-gate (void) fprintf(errorf, s, p, d);
1470Sstevel@tonic-gate (void) putc('\n', errorf);
1480Sstevel@tonic-gate (void) fflush(errorf);
1490Sstevel@tonic-gate if (fout)
1500Sstevel@tonic-gate (void) fflush(fout);
1510Sstevel@tonic-gate (void) fflush(stdout);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate
154*6951Sab196087 /*
155*6951Sab196087 * This function is apparently unused, but lint flags the fact
156*6951Sab196087 * that it does not have the same signature as the libc function
157*6951Sab196087 * of the same name. So, take it out of view for lint.
158*6951Sab196087 */
159*6951Sab196087 #if !defined(__lint)
1600Sstevel@tonic-gate int
index(int a,CHR * s)1610Sstevel@tonic-gate index(int a, CHR *s)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate int k;
1640Sstevel@tonic-gate for (k = 0; s[k]; k++)
1650Sstevel@tonic-gate if (s[k] == a)
1660Sstevel@tonic-gate return (k);
1670Sstevel@tonic-gate return (-1);
1680Sstevel@tonic-gate }
169*6951Sab196087 #endif
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate int
alpha(int c)1720Sstevel@tonic-gate alpha(int c)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate return ('a' <= c && c <= 'z' ||
1754538Sdamico 'A' <= c && c <= 'Z');
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate int
printable(int c)1790Sstevel@tonic-gate printable(int c)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate return (c > 040 && c < 0177);
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate void
lgate(void)1850Sstevel@tonic-gate lgate(void)
1860Sstevel@tonic-gate {
1870Sstevel@tonic-gate char fname[20];
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate if (lgatflg)
1900Sstevel@tonic-gate return;
1910Sstevel@tonic-gate lgatflg = 1;
1920Sstevel@tonic-gate if (fout == NULL) {
1930Sstevel@tonic-gate (void) sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c');
1940Sstevel@tonic-gate fout = fopen(fname, "w");
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate if (fout == NULL)
1970Sstevel@tonic-gate error("Can't open %s", fname);
1980Sstevel@tonic-gate if (ratfor)
1990Sstevel@tonic-gate (void) fprintf(fout, "#\n");
2000Sstevel@tonic-gate phead1();
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate /*
2040Sstevel@tonic-gate * scopy(ptr to str, ptr to str) - copy first arg str to second
2050Sstevel@tonic-gate * returns ptr to second arg
2060Sstevel@tonic-gate */
2070Sstevel@tonic-gate void
scopy(CHR * s,CHR * t)2080Sstevel@tonic-gate scopy(CHR *s, CHR *t)
2090Sstevel@tonic-gate {
2100Sstevel@tonic-gate CHR *i;
2110Sstevel@tonic-gate i = t;
2124538Sdamico while (*i++ = *s++)
213*6951Sab196087 ;
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate /*
2170Sstevel@tonic-gate * convert string t, return integer value
2180Sstevel@tonic-gate */
2190Sstevel@tonic-gate int
siconv(CHR * t)2200Sstevel@tonic-gate siconv(CHR *t)
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate int i, sw;
2230Sstevel@tonic-gate CHR *s;
2240Sstevel@tonic-gate s = t;
2250Sstevel@tonic-gate while (space(*s))
2260Sstevel@tonic-gate s++;
2270Sstevel@tonic-gate if (!digit(*s) && *s != '-')
2280Sstevel@tonic-gate error("missing translation value");
2290Sstevel@tonic-gate sw = 0;
2300Sstevel@tonic-gate if (*s == '-') {
2310Sstevel@tonic-gate sw = 1;
2320Sstevel@tonic-gate s++;
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate if (!digit(*s))
2350Sstevel@tonic-gate error("incomplete translation format");
2360Sstevel@tonic-gate i = 0;
2370Sstevel@tonic-gate while ('0' <= *s && *s <= '9')
2380Sstevel@tonic-gate i = i * 10 + (*(s++)-'0');
2390Sstevel@tonic-gate return (sw ? -i : i);
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate * slength(ptr to str) - return integer length of string arg
2440Sstevel@tonic-gate * excludes '\0' terminator
2450Sstevel@tonic-gate */
2460Sstevel@tonic-gate int
slength(CHR * s)2470Sstevel@tonic-gate slength(CHR *s)
2480Sstevel@tonic-gate {
2490Sstevel@tonic-gate int n;
2500Sstevel@tonic-gate CHR *t;
2510Sstevel@tonic-gate t = s;
2524538Sdamico for (n = 0; *t++; n++)
253*6951Sab196087 ;
2540Sstevel@tonic-gate return (n);
2550Sstevel@tonic-gate }
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate * scomp(x,y) - return -1 if x < y,
2590Sstevel@tonic-gate * 0 if x == y,
2600Sstevel@tonic-gate * return 1 if x > y, all lexicographically
2610Sstevel@tonic-gate */
2620Sstevel@tonic-gate int
scomp(CHR * x,CHR * y)2630Sstevel@tonic-gate scomp(CHR *x, CHR *y)
2640Sstevel@tonic-gate {
2650Sstevel@tonic-gate CHR *a, *d;
2660Sstevel@tonic-gate a = (CHR *) x;
2670Sstevel@tonic-gate d = (CHR *) y;
2680Sstevel@tonic-gate while (*a || *d) {
2690Sstevel@tonic-gate if (*a > *d)
2700Sstevel@tonic-gate return (1);
2710Sstevel@tonic-gate if (*a < *d)
2720Sstevel@tonic-gate return (-1);
2730Sstevel@tonic-gate a++;
2740Sstevel@tonic-gate d++;
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate return (0);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate int
ctrans(CHR ** ss)2800Sstevel@tonic-gate ctrans(CHR **ss)
2810Sstevel@tonic-gate {
2820Sstevel@tonic-gate int c, k;
2830Sstevel@tonic-gate if ((c = **ss) != '\\')
2840Sstevel@tonic-gate return (c);
2850Sstevel@tonic-gate switch (c = *++*ss) {
2860Sstevel@tonic-gate case 'a':
2870Sstevel@tonic-gate c = '\a';
2880Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character");
2890Sstevel@tonic-gate break;
2900Sstevel@tonic-gate case 'v': c = '\v'; break;
2910Sstevel@tonic-gate case 'n': c = '\n'; break;
2920Sstevel@tonic-gate case 't': c = '\t'; break;
2930Sstevel@tonic-gate case 'r': c = '\r'; break;
2940Sstevel@tonic-gate case 'b': c = '\b'; break;
2950Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */
2960Sstevel@tonic-gate case '\\': c = '\\'; break;
2970Sstevel@tonic-gate case 'x': {
2980Sstevel@tonic-gate int dd;
2990Sstevel@tonic-gate warning("\\x is ANSI C hex escape");
3000Sstevel@tonic-gate if (digit((dd = *++*ss)) ||
3014538Sdamico ('a' <= dd && dd <= 'f') ||
3024538Sdamico ('A' <= dd && dd <= 'F')) {
3030Sstevel@tonic-gate c = 0;
3040Sstevel@tonic-gate while (digit(dd) ||
3054538Sdamico ('A' <= dd && dd <= 'F') ||
3064538Sdamico ('a' <= dd && dd <= 'f')) {
3070Sstevel@tonic-gate if (digit(dd))
3080Sstevel@tonic-gate c = c*16 + dd - '0';
3090Sstevel@tonic-gate else if (dd >= 'a')
3100Sstevel@tonic-gate c = c*16 + 10 + dd - 'a';
3110Sstevel@tonic-gate else
3120Sstevel@tonic-gate c = c*16 + 10 + dd - 'A';
3130Sstevel@tonic-gate dd = *++*ss;
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate } else
3160Sstevel@tonic-gate c = 'x';
3170Sstevel@tonic-gate break;
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate case '0': case '1': case '2': case '3':
3200Sstevel@tonic-gate case '4': case '5': case '6': case '7':
3210Sstevel@tonic-gate c -= '0';
3220Sstevel@tonic-gate while ((k = *(*ss+1)) >= '0' && k <= '7') {
3230Sstevel@tonic-gate c = c*8 + k - '0';
3240Sstevel@tonic-gate (*ss)++;
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate break;
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate return (c);
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate void
cclinter(int sw)3320Sstevel@tonic-gate cclinter(int sw)
3330Sstevel@tonic-gate {
3340Sstevel@tonic-gate /* sw = 1 ==> ccl */
3350Sstevel@tonic-gate int i, j, k;
3360Sstevel@tonic-gate int m;
3370Sstevel@tonic-gate if (!sw) { /* is NCCL */
3380Sstevel@tonic-gate for (i = 1; i < ncg; i++)
3390Sstevel@tonic-gate symbol[i] ^= 1; /* reverse value */
3400Sstevel@tonic-gate }
3410Sstevel@tonic-gate for (i = 1; i < ncg; i++)
3420Sstevel@tonic-gate if (symbol[i])
3430Sstevel@tonic-gate break;
3440Sstevel@tonic-gate if (i >= ncg)
3450Sstevel@tonic-gate return;
3460Sstevel@tonic-gate i = cindex[i];
3470Sstevel@tonic-gate /* see if ccl is already in our table */
3480Sstevel@tonic-gate j = 0;
3490Sstevel@tonic-gate if (i) {
3500Sstevel@tonic-gate for (j = 1; j < ncg; j++) {
3510Sstevel@tonic-gate if ((symbol[j] && cindex[j] != i) ||
3524538Sdamico (!symbol[j] && cindex[j] == i))
3530Sstevel@tonic-gate break;
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate }
3560Sstevel@tonic-gate if (j >= ncg)
3570Sstevel@tonic-gate return; /* already in */
3580Sstevel@tonic-gate m = 0;
3590Sstevel@tonic-gate k = 0;
3600Sstevel@tonic-gate for (i = 1; i < ncg; i++) {
3610Sstevel@tonic-gate if (symbol[i]) {
3620Sstevel@tonic-gate if (!cindex[i]) {
3630Sstevel@tonic-gate cindex[i] = ccount;
3640Sstevel@tonic-gate symbol[i] = 0;
3650Sstevel@tonic-gate m = 1;
3660Sstevel@tonic-gate } else
3670Sstevel@tonic-gate k = 1;
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate /* m == 1 implies last value of ccount has been used */
3710Sstevel@tonic-gate if (m)
3720Sstevel@tonic-gate ccount++;
3730Sstevel@tonic-gate if (k == 0)
3740Sstevel@tonic-gate return; /* is now in as ccount wholly */
3750Sstevel@tonic-gate /* intersection must be computed */
3760Sstevel@tonic-gate for (i = 1; i < ncg; i++) {
3770Sstevel@tonic-gate if (symbol[i]) {
3780Sstevel@tonic-gate m = 0;
3790Sstevel@tonic-gate j = cindex[i]; /* will be non-zero */
3800Sstevel@tonic-gate for (k = 1; k < ncg; k++) {
3810Sstevel@tonic-gate if (cindex[k] == j) {
3820Sstevel@tonic-gate if (symbol[k])
3830Sstevel@tonic-gate symbol[k] = 0;
3840Sstevel@tonic-gate else {
3850Sstevel@tonic-gate cindex[k] = ccount;
3860Sstevel@tonic-gate m = 1;
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate if (m)
3910Sstevel@tonic-gate ccount++;
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate int
usescape(int c)3970Sstevel@tonic-gate usescape(int c)
3980Sstevel@tonic-gate {
3990Sstevel@tonic-gate char d;
4000Sstevel@tonic-gate switch (c) {
4010Sstevel@tonic-gate case 'a':
4020Sstevel@tonic-gate c = '\a';
4030Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character"); break;
4040Sstevel@tonic-gate case 'v': c = '\v'; break;
4050Sstevel@tonic-gate case 'n': c = '\n'; break;
4060Sstevel@tonic-gate case 'r': c = '\r'; break;
4070Sstevel@tonic-gate case 't': c = '\t'; break;
4080Sstevel@tonic-gate case 'b': c = '\b'; break;
4090Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */
4100Sstevel@tonic-gate case 'x': {
4110Sstevel@tonic-gate int dd;
4120Sstevel@tonic-gate if (digit((dd = gch())) ||
4134538Sdamico ('A' <= dd && dd <= 'F') ||
4144538Sdamico ('a' <= dd && dd <= 'f')) {
4150Sstevel@tonic-gate c = 0;
4160Sstevel@tonic-gate while (digit(dd) ||
4174538Sdamico ('A' <= dd && dd <= 'F') ||
4184538Sdamico ('a' <= dd && dd <= 'f')) {
4190Sstevel@tonic-gate if (digit(dd))
4200Sstevel@tonic-gate c = c*16 + dd - '0';
4210Sstevel@tonic-gate else if (dd >= 'a')
4220Sstevel@tonic-gate c = c*16 + 10 + dd - 'a';
4230Sstevel@tonic-gate else
4240Sstevel@tonic-gate c = c*16 + 10 + dd - 'A';
4250Sstevel@tonic-gate if (!digit(peek) &&
4264538Sdamico !('A' <= peek && peek <= 'F') &&
4274538Sdamico !('a' <= peek && peek <= 'f'))
4280Sstevel@tonic-gate break;
4290Sstevel@tonic-gate dd = gch();
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate } else
4330Sstevel@tonic-gate c = 'x';
4340Sstevel@tonic-gate break;
4350Sstevel@tonic-gate }
4360Sstevel@tonic-gate case '0': case '1': case '2': case '3':
4370Sstevel@tonic-gate case '4': case '5': case '6': case '7':
4380Sstevel@tonic-gate c -= '0';
4390Sstevel@tonic-gate while ('0' <= (d = gch()) && d <= '7') {
4400Sstevel@tonic-gate c = c * 8 + (d-'0');
4410Sstevel@tonic-gate if (!('0' <= peek && peek <= '7')) break;
4420Sstevel@tonic-gate }
4430Sstevel@tonic-gate
4440Sstevel@tonic-gate break;
4450Sstevel@tonic-gate }
4460Sstevel@tonic-gate
4470Sstevel@tonic-gate if (handleeuc && !isascii(c)) {
4480Sstevel@tonic-gate char tmpchar = c & 0x00ff;
449*6951Sab196087 (void) mbtowc((wchar_t *)&c, &tmpchar, sizeof (tmpchar));
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate return (c);
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate
4540Sstevel@tonic-gate int
lookup(CHR * s,CHR ** t)4550Sstevel@tonic-gate lookup(CHR *s, CHR **t)
4560Sstevel@tonic-gate {
4570Sstevel@tonic-gate int i;
4580Sstevel@tonic-gate i = 0;
4590Sstevel@tonic-gate while (*t) {
4600Sstevel@tonic-gate if (scomp(s, *t) == 0)
4610Sstevel@tonic-gate return (i);
4620Sstevel@tonic-gate i++;
4630Sstevel@tonic-gate t++;
4640Sstevel@tonic-gate }
4650Sstevel@tonic-gate return (-1);
4660Sstevel@tonic-gate }
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate void
cpycom(CHR * p)4690Sstevel@tonic-gate cpycom(CHR *p)
4700Sstevel@tonic-gate {
4710Sstevel@tonic-gate static CHR *t;
4720Sstevel@tonic-gate static int c;
4730Sstevel@tonic-gate t = p;
4740Sstevel@tonic-gate
4750Sstevel@tonic-gate if (sargv[optind] == NULL)
4760Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline);
4770Sstevel@tonic-gate else
4780Sstevel@tonic-gate (void) fprintf(fout,
4794538Sdamico "\n# line %d \"%s\"\n", yyline, sargv[optind]);
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate (void) putc(*t++, fout);
4820Sstevel@tonic-gate (void) putc(*t++, fout);
4830Sstevel@tonic-gate while (*t) {
4840Sstevel@tonic-gate while (*t == '*') {
4850Sstevel@tonic-gate (void) putc(*t++, fout);
4860Sstevel@tonic-gate if (*t == '/')
4870Sstevel@tonic-gate goto backcall;
4880Sstevel@tonic-gate }
4890Sstevel@tonic-gate /*
4900Sstevel@tonic-gate * FIX BUG #1058428, not parsing comments correctly
4910Sstevel@tonic-gate * that span more than one line
4920Sstevel@tonic-gate */
4930Sstevel@tonic-gate if (*t != NULL)
4940Sstevel@tonic-gate (void) putc(*t++, fout);
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate (void) putc('\n', fout);
4970Sstevel@tonic-gate while (c = gch()) {
4980Sstevel@tonic-gate while (c == '*') {
4990Sstevel@tonic-gate (void) putc((char)c, fout);
5000Sstevel@tonic-gate if ((c = gch()) == '/') {
5014538Sdamico while ((c = gch()) == ' ' || c == '\t')
502*6951Sab196087 ;
5030Sstevel@tonic-gate if (!space(c))
5040Sstevel@tonic-gate error("unacceptable statement");
5050Sstevel@tonic-gate prev = '\n';
5060Sstevel@tonic-gate goto backcall;
5070Sstevel@tonic-gate }
5080Sstevel@tonic-gate }
5090Sstevel@tonic-gate (void) putc((char)c, fout);
5100Sstevel@tonic-gate }
5110Sstevel@tonic-gate error("unexpected EOF inside comment");
5120Sstevel@tonic-gate backcall:
5130Sstevel@tonic-gate (void) putc('/', fout);
5140Sstevel@tonic-gate (void) putc('\n', fout);
5150Sstevel@tonic-gate }
5160Sstevel@tonic-gate
5170Sstevel@tonic-gate /*
5180Sstevel@tonic-gate * copy C action to the next ; or closing
5190Sstevel@tonic-gate */
5200Sstevel@tonic-gate int
cpyact(void)5210Sstevel@tonic-gate cpyact(void)
5220Sstevel@tonic-gate {
5230Sstevel@tonic-gate int brac, c, mth;
5240Sstevel@tonic-gate static int sw, savline;
5250Sstevel@tonic-gate
5260Sstevel@tonic-gate brac = 0;
5270Sstevel@tonic-gate sw = TRUE;
5280Sstevel@tonic-gate savline = yyline;
5290Sstevel@tonic-gate
5300Sstevel@tonic-gate if (sargv[optind] == NULL)
5310Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline);
5320Sstevel@tonic-gate else
5330Sstevel@tonic-gate (void) fprintf(fout,
5344538Sdamico "\n# line %d \"%s\"\n", yyline, sargv[optind]);
5350Sstevel@tonic-gate
5360Sstevel@tonic-gate while (!eof) {
5370Sstevel@tonic-gate c = gch();
5380Sstevel@tonic-gate swt:
5390Sstevel@tonic-gate switch (c) {
5400Sstevel@tonic-gate case '|':
5410Sstevel@tonic-gate if (brac == 0 && sw == TRUE) {
5420Sstevel@tonic-gate if (peek == '|')
5430Sstevel@tonic-gate (void) gch(); /* eat up an extra '|' */
5440Sstevel@tonic-gate return (0);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate break;
5470Sstevel@tonic-gate case ';':
5480Sstevel@tonic-gate if (brac == 0) {
5490Sstevel@tonic-gate (void) putwc(c, fout);
5500Sstevel@tonic-gate (void) putc('\n', fout);
5510Sstevel@tonic-gate return (1);
5520Sstevel@tonic-gate }
5530Sstevel@tonic-gate break;
5540Sstevel@tonic-gate case '{':
5550Sstevel@tonic-gate brac++;
5560Sstevel@tonic-gate savline = yyline;
5570Sstevel@tonic-gate break;
5580Sstevel@tonic-gate case '}':
5590Sstevel@tonic-gate brac--;
5600Sstevel@tonic-gate if (brac == 0) {
5610Sstevel@tonic-gate (void) putwc(c, fout);
5620Sstevel@tonic-gate (void) putc('\n', fout);
5630Sstevel@tonic-gate return (1);
5640Sstevel@tonic-gate }
5650Sstevel@tonic-gate break;
5660Sstevel@tonic-gate case '/':
5670Sstevel@tonic-gate (void) putwc(c, fout);
5680Sstevel@tonic-gate c = gch();
5690Sstevel@tonic-gate if (c != '*')
5700Sstevel@tonic-gate goto swt;
5710Sstevel@tonic-gate (void) putwc(c, fout);
5720Sstevel@tonic-gate savline = yyline;
5730Sstevel@tonic-gate while (c = gch()) {
5740Sstevel@tonic-gate while (c == '*') {
5750Sstevel@tonic-gate (void) putwc(c, fout);
5760Sstevel@tonic-gate if ((c = gch()) == '/') {
5770Sstevel@tonic-gate (void) putc('/', fout);
5780Sstevel@tonic-gate while ((c = gch()) == ' ' ||
5794538Sdamico c == '\t' || c == '\n')
5800Sstevel@tonic-gate (void) putwc(c, fout);
5810Sstevel@tonic-gate goto swt;
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate }
5840Sstevel@tonic-gate (void) putc((char)c, fout);
5850Sstevel@tonic-gate }
5860Sstevel@tonic-gate yyline = savline;
5870Sstevel@tonic-gate error("EOF inside comment");
5880Sstevel@tonic-gate /* NOTREACHED */
5890Sstevel@tonic-gate break;
5900Sstevel@tonic-gate case '\'': /* character constant */
5910Sstevel@tonic-gate case '"': /* character string */
5920Sstevel@tonic-gate mth = c;
5930Sstevel@tonic-gate (void) putwc(c, fout);
5940Sstevel@tonic-gate while (c = gch()) {
5950Sstevel@tonic-gate if (c == '\\') {
5960Sstevel@tonic-gate (void) putwc(c, fout);
5970Sstevel@tonic-gate c = gch();
5980Sstevel@tonic-gate }
5990Sstevel@tonic-gate else
6000Sstevel@tonic-gate if (c == mth)
6010Sstevel@tonic-gate goto loop;
6020Sstevel@tonic-gate (void) putwc(c, fout);
6030Sstevel@tonic-gate if (c == '\n') {
6040Sstevel@tonic-gate yyline--;
6050Sstevel@tonic-gate error(
6060Sstevel@tonic-gate "Non-terminated string or character constant");
6070Sstevel@tonic-gate }
6080Sstevel@tonic-gate }
6090Sstevel@tonic-gate error("EOF in string or character constant");
6100Sstevel@tonic-gate /* NOTREACHED */
6110Sstevel@tonic-gate break;
6120Sstevel@tonic-gate case '\0':
6130Sstevel@tonic-gate yyline = savline;
6140Sstevel@tonic-gate error("Action does not terminate");
6150Sstevel@tonic-gate /* NOTREACHED */
6160Sstevel@tonic-gate break;
6170Sstevel@tonic-gate default:
6180Sstevel@tonic-gate break; /* usual character */
6190Sstevel@tonic-gate }
6200Sstevel@tonic-gate loop:
6210Sstevel@tonic-gate if (c != ' ' && c != '\t' && c != '\n')
6220Sstevel@tonic-gate sw = FALSE;
6230Sstevel@tonic-gate (void) putwc(c, fout);
6240Sstevel@tonic-gate if (peek == '\n' && !brac && copy_line) {
6250Sstevel@tonic-gate (void) putc('\n', fout);
6260Sstevel@tonic-gate return (1);
6270Sstevel@tonic-gate }
6280Sstevel@tonic-gate }
6290Sstevel@tonic-gate error("Premature EOF");
6300Sstevel@tonic-gate return (0);
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate
6330Sstevel@tonic-gate int
gch(void)6340Sstevel@tonic-gate gch(void)
6350Sstevel@tonic-gate {
6360Sstevel@tonic-gate int c;
6370Sstevel@tonic-gate prev = pres;
6380Sstevel@tonic-gate c = pres = peek;
6390Sstevel@tonic-gate peek = pushptr > pushc ? *--pushptr : getwc(fin);
6400Sstevel@tonic-gate while (peek == EOF) {
6410Sstevel@tonic-gate if (no_input) {
6420Sstevel@tonic-gate if (!yyline)
6430Sstevel@tonic-gate error("Cannot read from -- %s",
6444538Sdamico sargv[optind]);
6450Sstevel@tonic-gate if (optind < sargc-1) {
6460Sstevel@tonic-gate yyline = 0;
6470Sstevel@tonic-gate if (fin != stdin)
6480Sstevel@tonic-gate (void) fclose(fin);
6490Sstevel@tonic-gate fin = fopen(sargv[++optind], "r");
6500Sstevel@tonic-gate if (fin == NULL)
6510Sstevel@tonic-gate error("Cannot open file -- %s",
6524538Sdamico sargv[optind]);
6530Sstevel@tonic-gate peek = getwc(fin);
6540Sstevel@tonic-gate } else
6550Sstevel@tonic-gate break;
6560Sstevel@tonic-gate } else {
6570Sstevel@tonic-gate if (fin != stdin)
6580Sstevel@tonic-gate (void) fclose(fin);
6590Sstevel@tonic-gate if (!yyline)
6600Sstevel@tonic-gate error("Cannot read from -- standard input");
6610Sstevel@tonic-gate else
6620Sstevel@tonic-gate break;
6630Sstevel@tonic-gate }
6640Sstevel@tonic-gate }
6650Sstevel@tonic-gate if (c == EOF) {
6660Sstevel@tonic-gate eof = TRUE;
6670Sstevel@tonic-gate return (0);
6680Sstevel@tonic-gate }
6690Sstevel@tonic-gate if (c == '\n')
6700Sstevel@tonic-gate yyline++;
6710Sstevel@tonic-gate return (c);
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate
6740Sstevel@tonic-gate int
mn2(int a,int d,int c)6750Sstevel@tonic-gate mn2(int a, int d, int c)
6760Sstevel@tonic-gate {
6770Sstevel@tonic-gate if (tptr >= treesize) {
6780Sstevel@tonic-gate tptr++;
6790Sstevel@tonic-gate error("Parse tree too big %s",
6804538Sdamico (treesize == TREESIZE ? "\nTry using %e num" : ""));
6810Sstevel@tonic-gate }
6820Sstevel@tonic-gate if (d >= treesize) {
6830Sstevel@tonic-gate error("Parse error");
6840Sstevel@tonic-gate }
6850Sstevel@tonic-gate name[tptr] = a;
6860Sstevel@tonic-gate left[tptr] = d;
6870Sstevel@tonic-gate right[tptr] = c;
6880Sstevel@tonic-gate parent[tptr] = 0;
6890Sstevel@tonic-gate nullstr[tptr] = 0;
6900Sstevel@tonic-gate switch (a) {
6910Sstevel@tonic-gate case RSTR:
6920Sstevel@tonic-gate parent[d] = tptr;
6930Sstevel@tonic-gate break;
6940Sstevel@tonic-gate case BAR:
6950Sstevel@tonic-gate case RNEWE:
6960Sstevel@tonic-gate if (nullstr[d] || nullstr[c])
6970Sstevel@tonic-gate nullstr[tptr] = TRUE;
6980Sstevel@tonic-gate parent[d] = parent[c] = tptr;
6990Sstevel@tonic-gate break;
7000Sstevel@tonic-gate case RCAT:
7010Sstevel@tonic-gate case DIV:
7020Sstevel@tonic-gate if (nullstr[d] && nullstr[c])
7030Sstevel@tonic-gate nullstr[tptr] = TRUE;
7040Sstevel@tonic-gate parent[d] = parent[c] = tptr;
7050Sstevel@tonic-gate break;
7060Sstevel@tonic-gate /* XCU4: add RXSCON */
7070Sstevel@tonic-gate case RXSCON:
7080Sstevel@tonic-gate case RSCON:
7090Sstevel@tonic-gate parent[d] = tptr;
7100Sstevel@tonic-gate nullstr[tptr] = nullstr[d];
7110Sstevel@tonic-gate break;
7120Sstevel@tonic-gate #ifdef DEBUG
7130Sstevel@tonic-gate default:
7140Sstevel@tonic-gate warning("bad switch mn2 %d %d", a, d);
7150Sstevel@tonic-gate break;
7160Sstevel@tonic-gate #endif
7170Sstevel@tonic-gate }
7180Sstevel@tonic-gate return (tptr++);
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate
7210Sstevel@tonic-gate int
mn1(int a,int d)7220Sstevel@tonic-gate mn1(int a, int d)
7230Sstevel@tonic-gate {
7240Sstevel@tonic-gate if (tptr >= treesize) {
7250Sstevel@tonic-gate tptr++;
7260Sstevel@tonic-gate error("Parse tree too big %s",
7274538Sdamico (treesize == TREESIZE ? "\nTry using %e num" : ""));
7280Sstevel@tonic-gate }
7290Sstevel@tonic-gate name[tptr] = a;
7300Sstevel@tonic-gate left[tptr] = d;
7310Sstevel@tonic-gate parent[tptr] = 0;
7320Sstevel@tonic-gate nullstr[tptr] = 0;
7330Sstevel@tonic-gate switch (a) {
7340Sstevel@tonic-gate case RCCL:
7350Sstevel@tonic-gate case RNCCL:
7360Sstevel@tonic-gate if (slength((CHR *)d) == 0)
7370Sstevel@tonic-gate nullstr[tptr] = TRUE;
7380Sstevel@tonic-gate break;
7390Sstevel@tonic-gate case STAR:
7400Sstevel@tonic-gate case QUEST:
7410Sstevel@tonic-gate nullstr[tptr] = TRUE;
7420Sstevel@tonic-gate parent[d] = tptr;
7430Sstevel@tonic-gate break;
7440Sstevel@tonic-gate case PLUS:
7450Sstevel@tonic-gate case CARAT:
7460Sstevel@tonic-gate nullstr[tptr] = nullstr[d];
7470Sstevel@tonic-gate parent[d] = tptr;
7480Sstevel@tonic-gate break;
7490Sstevel@tonic-gate case S2FINAL:
7500Sstevel@tonic-gate nullstr[tptr] = TRUE;
7510Sstevel@tonic-gate break;
7520Sstevel@tonic-gate #ifdef DEBUG
7530Sstevel@tonic-gate case FINAL:
7540Sstevel@tonic-gate case S1FINAL:
7550Sstevel@tonic-gate break;
7560Sstevel@tonic-gate default:
7570Sstevel@tonic-gate warning("bad switch mn1 %d %d", a, d);
7580Sstevel@tonic-gate break;
7590Sstevel@tonic-gate #endif
7600Sstevel@tonic-gate }
7610Sstevel@tonic-gate return (tptr++);
7620Sstevel@tonic-gate }
7630Sstevel@tonic-gate
7640Sstevel@tonic-gate int
mn0(int a)7650Sstevel@tonic-gate mn0(int a)
7660Sstevel@tonic-gate {
7670Sstevel@tonic-gate if (tptr >= treesize) {
7680Sstevel@tonic-gate tptr++;
7690Sstevel@tonic-gate error("Parse tree too big %s",
7704538Sdamico (treesize == TREESIZE ? "\nTry using %e num" : ""));
7710Sstevel@tonic-gate }
7720Sstevel@tonic-gate
7730Sstevel@tonic-gate name[tptr] = a;
7740Sstevel@tonic-gate parent[tptr] = 0;
7750Sstevel@tonic-gate nullstr[tptr] = 0;
7760Sstevel@tonic-gate if (ISOPERATOR(a)) {
7770Sstevel@tonic-gate switch (a) {
7780Sstevel@tonic-gate case DOT: break;
7790Sstevel@tonic-gate case RNULLS: nullstr[tptr] = TRUE; break;
7800Sstevel@tonic-gate #ifdef DEBUG
7810Sstevel@tonic-gate default:
7820Sstevel@tonic-gate warning("bad switch mn0 %d", a);
7830Sstevel@tonic-gate break;
7840Sstevel@tonic-gate #endif
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate }
7870Sstevel@tonic-gate return (tptr++);
7880Sstevel@tonic-gate }
7890Sstevel@tonic-gate
7900Sstevel@tonic-gate void
munput(int t,CHR * p)7910Sstevel@tonic-gate munput(int t, CHR *p)
7920Sstevel@tonic-gate {
7930Sstevel@tonic-gate int i, j;
7940Sstevel@tonic-gate if (t == 'c') {
7950Sstevel@tonic-gate *pushptr++ = peek;
7960Sstevel@tonic-gate peek = *p;
7970Sstevel@tonic-gate } else if (t == 's') {
7980Sstevel@tonic-gate *pushptr++ = peek;
7990Sstevel@tonic-gate peek = p[0];
8000Sstevel@tonic-gate i = slength(p);
8010Sstevel@tonic-gate for (j = i - 1; j >= 1; j--)
8020Sstevel@tonic-gate *pushptr++ = p[j];
8030Sstevel@tonic-gate }
8040Sstevel@tonic-gate if (pushptr >= pushc + TOKENSIZE)
8050Sstevel@tonic-gate error("Too many characters pushed");
8060Sstevel@tonic-gate }
8070Sstevel@tonic-gate
8080Sstevel@tonic-gate int
dupl(int n)8090Sstevel@tonic-gate dupl(int n)
8100Sstevel@tonic-gate {
8110Sstevel@tonic-gate /* duplicate the subtree whose root is n, return ptr to it */
8120Sstevel@tonic-gate int i;
8130Sstevel@tonic-gate i = name[n];
8140Sstevel@tonic-gate if (!ISOPERATOR(i))
8150Sstevel@tonic-gate return (mn0(i));
8160Sstevel@tonic-gate switch (i) {
8170Sstevel@tonic-gate case DOT:
8180Sstevel@tonic-gate case RNULLS:
8190Sstevel@tonic-gate return (mn0(i));
8200Sstevel@tonic-gate case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL:
8210Sstevel@tonic-gate return (mn1(i, left[n]));
8220Sstevel@tonic-gate case STAR: case QUEST: case PLUS: case CARAT:
8230Sstevel@tonic-gate return (mn1(i, dupl(left[n])));
8240Sstevel@tonic-gate
8250Sstevel@tonic-gate /* XCU4: add RXSCON */
8260Sstevel@tonic-gate case RSTR: case RSCON: case RXSCON:
8270Sstevel@tonic-gate return (mn2(i, dupl(left[n]), right[n]));
8280Sstevel@tonic-gate case BAR: case RNEWE: case RCAT: case DIV:
8290Sstevel@tonic-gate return (mn2(i, dupl(left[n]), dupl(right[n])));
8300Sstevel@tonic-gate }
8310Sstevel@tonic-gate return (0);
8320Sstevel@tonic-gate }
8330Sstevel@tonic-gate
8340Sstevel@tonic-gate #ifdef DEBUG
8350Sstevel@tonic-gate void
allprint(CHR c)8360Sstevel@tonic-gate allprint(CHR c)
8370Sstevel@tonic-gate {
8380Sstevel@tonic-gate switch (c) {
8390Sstevel@tonic-gate case 014:
8400Sstevel@tonic-gate (void) printf("\\f");
8410Sstevel@tonic-gate charc++;
8420Sstevel@tonic-gate break;
8430Sstevel@tonic-gate case '\n':
8440Sstevel@tonic-gate (void) printf("\\n");
8450Sstevel@tonic-gate charc++;
8460Sstevel@tonic-gate break;
8470Sstevel@tonic-gate case '\t':
8480Sstevel@tonic-gate (void) printf("\\t");
8490Sstevel@tonic-gate charc++;
8500Sstevel@tonic-gate break;
8510Sstevel@tonic-gate case '\b':
8520Sstevel@tonic-gate (void) printf("\\b");
8530Sstevel@tonic-gate charc++;
8540Sstevel@tonic-gate break;
8550Sstevel@tonic-gate case ' ':
8560Sstevel@tonic-gate (void) printf("\\_");
8570Sstevel@tonic-gate break;
8580Sstevel@tonic-gate default:
8590Sstevel@tonic-gate if (!iswprint(c)) {
8600Sstevel@tonic-gate printf("\\x%-2x", c); /* up to fashion. */
8610Sstevel@tonic-gate charc += 3;
8620Sstevel@tonic-gate } else
8630Sstevel@tonic-gate (void) putwc(c, stdout);
8640Sstevel@tonic-gate break;
8650Sstevel@tonic-gate }
8660Sstevel@tonic-gate charc++;
8670Sstevel@tonic-gate }
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate void
strpt(CHR * s)8700Sstevel@tonic-gate strpt(CHR *s)
8710Sstevel@tonic-gate {
8720Sstevel@tonic-gate charc = 0;
8730Sstevel@tonic-gate while (*s) {
8740Sstevel@tonic-gate allprint(*s++);
8750Sstevel@tonic-gate if (charc > LINESIZE) {
8760Sstevel@tonic-gate charc = 0;
8770Sstevel@tonic-gate (void) printf("\n\t");
8780Sstevel@tonic-gate }
8790Sstevel@tonic-gate }
8800Sstevel@tonic-gate }
8810Sstevel@tonic-gate
8820Sstevel@tonic-gate void
sect1dump(void)8830Sstevel@tonic-gate sect1dump(void)
8840Sstevel@tonic-gate {
8850Sstevel@tonic-gate int i;
8860Sstevel@tonic-gate (void) printf("Sect 1:\n");
8870Sstevel@tonic-gate if (def[0]) {
8880Sstevel@tonic-gate (void) printf("str trans\n");
8890Sstevel@tonic-gate i = -1;
8900Sstevel@tonic-gate while (def[++i])
8910Sstevel@tonic-gate (void) printf("%ws\t%ws\n", def[i], subs[i]);
8920Sstevel@tonic-gate }
8930Sstevel@tonic-gate if (sname[0]) {
8940Sstevel@tonic-gate (void) printf("start names\n");
8950Sstevel@tonic-gate i = -1;
8960Sstevel@tonic-gate while (sname[++i])
8970Sstevel@tonic-gate (void) printf("%ws\n", sname[i]);
8980Sstevel@tonic-gate }
8990Sstevel@tonic-gate if (chset == TRUE) {
9000Sstevel@tonic-gate (void) printf("char set changed\n");
9010Sstevel@tonic-gate for (i = 1; i < NCH; i++) {
9020Sstevel@tonic-gate if (i != ctable[i]) {
9030Sstevel@tonic-gate allprint(i);
9040Sstevel@tonic-gate (void) putchar(' ');
9050Sstevel@tonic-gate iswprint(ctable[i]) ?
9064538Sdamico (void) putwc(ctable[i], stdout) :
9074538Sdamico (void) printf("%d", ctable[i]);
9080Sstevel@tonic-gate (void) putchar('\n');
9090Sstevel@tonic-gate }
9100Sstevel@tonic-gate }
9110Sstevel@tonic-gate }
9120Sstevel@tonic-gate }
9130Sstevel@tonic-gate
9140Sstevel@tonic-gate void
sect2dump(void)9150Sstevel@tonic-gate sect2dump(void)
9160Sstevel@tonic-gate {
9170Sstevel@tonic-gate (void) printf("Sect 2:\n");
9180Sstevel@tonic-gate treedump();
9190Sstevel@tonic-gate }
9200Sstevel@tonic-gate
9210Sstevel@tonic-gate void
treedump(void)9220Sstevel@tonic-gate treedump(void)
9230Sstevel@tonic-gate {
9240Sstevel@tonic-gate int t;
9250Sstevel@tonic-gate CHR *p;
9260Sstevel@tonic-gate (void) printf("treedump %d nodes:\n", tptr);
9270Sstevel@tonic-gate for (t = 0; t < tptr; t++) {
9280Sstevel@tonic-gate (void) printf("%4d ", t);
9290Sstevel@tonic-gate parent[t] ? (void) printf("p=%4d", parent[t]) :
9304538Sdamico (void) printf(" ");
9310Sstevel@tonic-gate (void) printf(" ");
9320Sstevel@tonic-gate if (!ISOPERATOR(name[t])) {
9330Sstevel@tonic-gate allprint(name[t]);
9340Sstevel@tonic-gate } else
9350Sstevel@tonic-gate switch (name[t]) {
9360Sstevel@tonic-gate case RSTR:
9370Sstevel@tonic-gate (void) printf("%d ", left[t]);
9380Sstevel@tonic-gate allprint(right[t]);
9390Sstevel@tonic-gate break;
9400Sstevel@tonic-gate case RCCL:
9410Sstevel@tonic-gate (void) printf("ccl ");
9420Sstevel@tonic-gate strpt(left[t]);
9430Sstevel@tonic-gate break;
9440Sstevel@tonic-gate case RNCCL:
9450Sstevel@tonic-gate (void) printf("nccl ");
9460Sstevel@tonic-gate strpt(left[t]);
9470Sstevel@tonic-gate break;
9480Sstevel@tonic-gate case DIV:
9490Sstevel@tonic-gate (void) printf("/ %d %d", left[t], right[t]);
9500Sstevel@tonic-gate break;
9510Sstevel@tonic-gate case BAR:
9520Sstevel@tonic-gate (void) printf("| %d %d", left[t], right[t]);
9530Sstevel@tonic-gate break;
9540Sstevel@tonic-gate case RCAT:
9550Sstevel@tonic-gate (void) printf("cat %d %d", left[t], right[t]);
9560Sstevel@tonic-gate break;
9570Sstevel@tonic-gate case PLUS:
9580Sstevel@tonic-gate (void) printf("+ %d", left[t]);
9590Sstevel@tonic-gate break;
9600Sstevel@tonic-gate case STAR:
9610Sstevel@tonic-gate (void) printf("* %d", left[t]);
9620Sstevel@tonic-gate break;
9630Sstevel@tonic-gate case CARAT:
9640Sstevel@tonic-gate (void) printf("^ %d", left[t]);
9650Sstevel@tonic-gate break;
9660Sstevel@tonic-gate case QUEST:
9670Sstevel@tonic-gate (void) printf("? %d", left[t]);
9680Sstevel@tonic-gate break;
9690Sstevel@tonic-gate case RNULLS:
9700Sstevel@tonic-gate (void) printf("nullstring");
9710Sstevel@tonic-gate break;
9720Sstevel@tonic-gate case FINAL:
9730Sstevel@tonic-gate (void) printf("final %d", left[t]);
9740Sstevel@tonic-gate break;
9750Sstevel@tonic-gate case S1FINAL:
9760Sstevel@tonic-gate (void) printf("s1final %d", left[t]);
9770Sstevel@tonic-gate break;
9780Sstevel@tonic-gate case S2FINAL:
9790Sstevel@tonic-gate (void) printf("s2final %d", left[t]);
9800Sstevel@tonic-gate break;
9810Sstevel@tonic-gate case RNEWE:
9820Sstevel@tonic-gate (void) printf("new %d %d", left[t], right[t]);
9830Sstevel@tonic-gate break;
9840Sstevel@tonic-gate
9850Sstevel@tonic-gate /* XCU4: add RXSCON */
9860Sstevel@tonic-gate case RXSCON:
9870Sstevel@tonic-gate p = (CHR *)right[t];
9880Sstevel@tonic-gate (void) printf("exstart %s", sname[*p++-1]);
9890Sstevel@tonic-gate while (*p)
9900Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]);
9910Sstevel@tonic-gate (void) printf(" %d", left[t]);
9920Sstevel@tonic-gate break;
9930Sstevel@tonic-gate case RSCON:
9940Sstevel@tonic-gate p = (CHR *)right[t];
9950Sstevel@tonic-gate (void) printf("start %s", sname[*p++-1]);
9960Sstevel@tonic-gate while (*p)
9970Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]);
9980Sstevel@tonic-gate (void) printf(" %d", left[t]);
9990Sstevel@tonic-gate break;
10000Sstevel@tonic-gate case DOT:
10010Sstevel@tonic-gate printf("dot");
10020Sstevel@tonic-gate break;
10030Sstevel@tonic-gate default:
10040Sstevel@tonic-gate (void) printf(
10050Sstevel@tonic-gate "unknown %d %d %d", name[t], left[t], right[t]);
10060Sstevel@tonic-gate break;
10070Sstevel@tonic-gate }
10080Sstevel@tonic-gate if (nullstr[t])
10090Sstevel@tonic-gate (void) printf("\t(null poss.)");
10100Sstevel@tonic-gate (void) putchar('\n');
10110Sstevel@tonic-gate }
10120Sstevel@tonic-gate }
10130Sstevel@tonic-gate #endif
1014