17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
567298654Sdamico * Common Development and Distribution License (the "License").
667298654Sdamico * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*1dd08564Sab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
307c478bd9Sstevel@tonic-gate
3167298654Sdamico #include "ldefs.h"
327c478bd9Sstevel@tonic-gate #include <limits.h>
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate * return next line of input, throw away trailing '\n'
367c478bd9Sstevel@tonic-gate * and also throw away trailing blanks (spaces and tabs)
377c478bd9Sstevel@tonic-gate * returns 0 if eof is had immediately
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate CHR *
getl(CHR * p)417c478bd9Sstevel@tonic-gate getl(CHR *p)
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate int c;
447c478bd9Sstevel@tonic-gate CHR *s, *t, *u;
457c478bd9Sstevel@tonic-gate int blank = 0;
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate t = s = p;
487c478bd9Sstevel@tonic-gate while (((c = gch()) != 0) && c != '\n') {
497c478bd9Sstevel@tonic-gate if (t >= &p[BUF_SIZ])
507c478bd9Sstevel@tonic-gate error("definitions too long");
517c478bd9Sstevel@tonic-gate if (c == ' ' || c == '\t') {
527c478bd9Sstevel@tonic-gate if (!blank) {
537c478bd9Sstevel@tonic-gate blank = 1;
547c478bd9Sstevel@tonic-gate u = t;
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate } else
577c478bd9Sstevel@tonic-gate blank = 0;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate *t++ = c;
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate if (blank)
627c478bd9Sstevel@tonic-gate *u = 0;
637c478bd9Sstevel@tonic-gate else
647c478bd9Sstevel@tonic-gate *t = 0;
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate if (c == 0 && s == t)
677c478bd9Sstevel@tonic-gate return ((CHR *) 0);
687c478bd9Sstevel@tonic-gate prev = '\n';
697c478bd9Sstevel@tonic-gate pres = '\n';
707c478bd9Sstevel@tonic-gate return (s);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate int
space(int ch)747c478bd9Sstevel@tonic-gate space(int ch)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate switch (ch) {
777c478bd9Sstevel@tonic-gate case ' ':
787c478bd9Sstevel@tonic-gate case '\t':
797c478bd9Sstevel@tonic-gate case '\n':
807c478bd9Sstevel@tonic-gate return (1);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate return (0);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate int
digit(int c)867c478bd9Sstevel@tonic-gate digit(int c)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate return (c >= '0' && c <= '9');
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate /* VARARGS1 */
927c478bd9Sstevel@tonic-gate void
error(s,p,d)937c478bd9Sstevel@tonic-gate error(s, p, d)
947c478bd9Sstevel@tonic-gate char *s;
957c478bd9Sstevel@tonic-gate int p, d;
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate /* if(!eof) */
987c478bd9Sstevel@tonic-gate if (!yyline)
997c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Command line: ");
1007c478bd9Sstevel@tonic-gate else {
1017c478bd9Sstevel@tonic-gate (void) fprintf(errorf,
1027c478bd9Sstevel@tonic-gate !no_input ? "" : "\"%s\":", sargv[optind]);
1037c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "line %d: ", yyline);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Error: ");
106*1dd08564Sab196087 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
1077c478bd9Sstevel@tonic-gate (void) fprintf(errorf, s, p, d);
1087c478bd9Sstevel@tonic-gate (void) putc('\n', errorf);
1097c478bd9Sstevel@tonic-gate if (fatal)
1107c478bd9Sstevel@tonic-gate error_tail();
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate void
error_tail(void)1147c478bd9Sstevel@tonic-gate error_tail(void)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate #ifdef DEBUG
1177c478bd9Sstevel@tonic-gate if (debug && sect != ENDSECTION) {
1187c478bd9Sstevel@tonic-gate sect1dump();
1197c478bd9Sstevel@tonic-gate sect2dump();
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate if (report == 1)
1247c478bd9Sstevel@tonic-gate statistics();
1257c478bd9Sstevel@tonic-gate exit(1);
1267c478bd9Sstevel@tonic-gate /* NOTREACHED */
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /* VARARGS1 */
1307c478bd9Sstevel@tonic-gate void
warning(s,p,d)1317c478bd9Sstevel@tonic-gate warning(s, p, d)
1327c478bd9Sstevel@tonic-gate char *s;
1337c478bd9Sstevel@tonic-gate int p, d;
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate if (!eof)
1367c478bd9Sstevel@tonic-gate if (!yyline)
1377c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Command line: ");
1387c478bd9Sstevel@tonic-gate else {
1397c478bd9Sstevel@tonic-gate (void) fprintf(errorf,
1407c478bd9Sstevel@tonic-gate !no_input?"":"\"%s\":", sargv[optind]);
1417c478bd9Sstevel@tonic-gate (void) fprintf(errorf,
1427c478bd9Sstevel@tonic-gate "line %d: ", yyline);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Warning: ");
145*1dd08564Sab196087 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
1467c478bd9Sstevel@tonic-gate (void) fprintf(errorf, s, p, d);
1477c478bd9Sstevel@tonic-gate (void) putc('\n', errorf);
1487c478bd9Sstevel@tonic-gate (void) fflush(errorf);
1497c478bd9Sstevel@tonic-gate if (fout)
1507c478bd9Sstevel@tonic-gate (void) fflush(fout);
1517c478bd9Sstevel@tonic-gate (void) fflush(stdout);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate
154*1dd08564Sab196087 /*
155*1dd08564Sab196087 * This function is apparently unused, but lint flags the fact
156*1dd08564Sab196087 * that it does not have the same signature as the libc function
157*1dd08564Sab196087 * of the same name. So, take it out of view for lint.
158*1dd08564Sab196087 */
159*1dd08564Sab196087 #if !defined(__lint)
1607c478bd9Sstevel@tonic-gate int
index(int a,CHR * s)1617c478bd9Sstevel@tonic-gate index(int a, CHR *s)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate int k;
1647c478bd9Sstevel@tonic-gate for (k = 0; s[k]; k++)
1657c478bd9Sstevel@tonic-gate if (s[k] == a)
1667c478bd9Sstevel@tonic-gate return (k);
1677c478bd9Sstevel@tonic-gate return (-1);
1687c478bd9Sstevel@tonic-gate }
169*1dd08564Sab196087 #endif
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate int
alpha(int c)1727c478bd9Sstevel@tonic-gate alpha(int c)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate return ('a' <= c && c <= 'z' ||
1757c478bd9Sstevel@tonic-gate 'A' <= c && c <= 'Z');
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate int
printable(int c)1797c478bd9Sstevel@tonic-gate printable(int c)
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate return (c > 040 && c < 0177);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate void
lgate(void)1857c478bd9Sstevel@tonic-gate lgate(void)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate char fname[20];
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate if (lgatflg)
1907c478bd9Sstevel@tonic-gate return;
1917c478bd9Sstevel@tonic-gate lgatflg = 1;
1927c478bd9Sstevel@tonic-gate if (fout == NULL) {
1937c478bd9Sstevel@tonic-gate (void) sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c');
1947c478bd9Sstevel@tonic-gate fout = fopen(fname, "w");
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate if (fout == NULL)
1977c478bd9Sstevel@tonic-gate error("Can't open %s", fname);
1987c478bd9Sstevel@tonic-gate if (ratfor)
1997c478bd9Sstevel@tonic-gate (void) fprintf(fout, "#\n");
2007c478bd9Sstevel@tonic-gate phead1();
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate * scopy(ptr to str, ptr to str) - copy first arg str to second
2057c478bd9Sstevel@tonic-gate * returns ptr to second arg
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate void
scopy(CHR * s,CHR * t)2087c478bd9Sstevel@tonic-gate scopy(CHR *s, CHR *t)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate CHR *i;
2117c478bd9Sstevel@tonic-gate i = t;
21267298654Sdamico while (*i++ = *s++)
213*1dd08564Sab196087 ;
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate /*
2177c478bd9Sstevel@tonic-gate * convert string t, return integer value
2187c478bd9Sstevel@tonic-gate */
2197c478bd9Sstevel@tonic-gate int
siconv(CHR * t)2207c478bd9Sstevel@tonic-gate siconv(CHR *t)
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate int i, sw;
2237c478bd9Sstevel@tonic-gate CHR *s;
2247c478bd9Sstevel@tonic-gate s = t;
2257c478bd9Sstevel@tonic-gate while (space(*s))
2267c478bd9Sstevel@tonic-gate s++;
2277c478bd9Sstevel@tonic-gate if (!digit(*s) && *s != '-')
2287c478bd9Sstevel@tonic-gate error("missing translation value");
2297c478bd9Sstevel@tonic-gate sw = 0;
2307c478bd9Sstevel@tonic-gate if (*s == '-') {
2317c478bd9Sstevel@tonic-gate sw = 1;
2327c478bd9Sstevel@tonic-gate s++;
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate if (!digit(*s))
2357c478bd9Sstevel@tonic-gate error("incomplete translation format");
2367c478bd9Sstevel@tonic-gate i = 0;
2377c478bd9Sstevel@tonic-gate while ('0' <= *s && *s <= '9')
2387c478bd9Sstevel@tonic-gate i = i * 10 + (*(s++)-'0');
2397c478bd9Sstevel@tonic-gate return (sw ? -i : i);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate * slength(ptr to str) - return integer length of string arg
2447c478bd9Sstevel@tonic-gate * excludes '\0' terminator
2457c478bd9Sstevel@tonic-gate */
2467c478bd9Sstevel@tonic-gate int
slength(CHR * s)2477c478bd9Sstevel@tonic-gate slength(CHR *s)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate int n;
2507c478bd9Sstevel@tonic-gate CHR *t;
2517c478bd9Sstevel@tonic-gate t = s;
25267298654Sdamico for (n = 0; *t++; n++)
253*1dd08564Sab196087 ;
2547c478bd9Sstevel@tonic-gate return (n);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate * scomp(x,y) - return -1 if x < y,
2597c478bd9Sstevel@tonic-gate * 0 if x == y,
2607c478bd9Sstevel@tonic-gate * return 1 if x > y, all lexicographically
2617c478bd9Sstevel@tonic-gate */
2627c478bd9Sstevel@tonic-gate int
scomp(CHR * x,CHR * y)2637c478bd9Sstevel@tonic-gate scomp(CHR *x, CHR *y)
2647c478bd9Sstevel@tonic-gate {
2657c478bd9Sstevel@tonic-gate CHR *a, *d;
2667c478bd9Sstevel@tonic-gate a = (CHR *) x;
2677c478bd9Sstevel@tonic-gate d = (CHR *) y;
2687c478bd9Sstevel@tonic-gate while (*a || *d) {
2697c478bd9Sstevel@tonic-gate if (*a > *d)
2707c478bd9Sstevel@tonic-gate return (1);
2717c478bd9Sstevel@tonic-gate if (*a < *d)
2727c478bd9Sstevel@tonic-gate return (-1);
2737c478bd9Sstevel@tonic-gate a++;
2747c478bd9Sstevel@tonic-gate d++;
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate return (0);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate int
ctrans(CHR ** ss)2807c478bd9Sstevel@tonic-gate ctrans(CHR **ss)
2817c478bd9Sstevel@tonic-gate {
2827c478bd9Sstevel@tonic-gate int c, k;
2837c478bd9Sstevel@tonic-gate if ((c = **ss) != '\\')
2847c478bd9Sstevel@tonic-gate return (c);
2857c478bd9Sstevel@tonic-gate switch (c = *++*ss) {
2867c478bd9Sstevel@tonic-gate case 'a':
2877c478bd9Sstevel@tonic-gate c = '\a';
2887c478bd9Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character");
2897c478bd9Sstevel@tonic-gate break;
2907c478bd9Sstevel@tonic-gate case 'v': c = '\v'; break;
2917c478bd9Sstevel@tonic-gate case 'n': c = '\n'; break;
2927c478bd9Sstevel@tonic-gate case 't': c = '\t'; break;
2937c478bd9Sstevel@tonic-gate case 'r': c = '\r'; break;
2947c478bd9Sstevel@tonic-gate case 'b': c = '\b'; break;
2957c478bd9Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */
2967c478bd9Sstevel@tonic-gate case '\\': c = '\\'; break;
2977c478bd9Sstevel@tonic-gate case 'x': {
2987c478bd9Sstevel@tonic-gate int dd;
2997c478bd9Sstevel@tonic-gate warning("\\x is ANSI C hex escape");
3007c478bd9Sstevel@tonic-gate if (digit((dd = *++*ss)) ||
3017c478bd9Sstevel@tonic-gate ('a' <= dd && dd <= 'f') ||
3027c478bd9Sstevel@tonic-gate ('A' <= dd && dd <= 'F')) {
3037c478bd9Sstevel@tonic-gate c = 0;
3047c478bd9Sstevel@tonic-gate while (digit(dd) ||
3057c478bd9Sstevel@tonic-gate ('A' <= dd && dd <= 'F') ||
3067c478bd9Sstevel@tonic-gate ('a' <= dd && dd <= 'f')) {
3077c478bd9Sstevel@tonic-gate if (digit(dd))
3087c478bd9Sstevel@tonic-gate c = c*16 + dd - '0';
3097c478bd9Sstevel@tonic-gate else if (dd >= 'a')
3107c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'a';
3117c478bd9Sstevel@tonic-gate else
3127c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'A';
3137c478bd9Sstevel@tonic-gate dd = *++*ss;
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate } else
3167c478bd9Sstevel@tonic-gate c = 'x';
3177c478bd9Sstevel@tonic-gate break;
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3':
3207c478bd9Sstevel@tonic-gate case '4': case '5': case '6': case '7':
3217c478bd9Sstevel@tonic-gate c -= '0';
3227c478bd9Sstevel@tonic-gate while ((k = *(*ss+1)) >= '0' && k <= '7') {
3237c478bd9Sstevel@tonic-gate c = c*8 + k - '0';
3247c478bd9Sstevel@tonic-gate (*ss)++;
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate break;
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate return (c);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate void
cclinter(int sw)3327c478bd9Sstevel@tonic-gate cclinter(int sw)
3337c478bd9Sstevel@tonic-gate {
3347c478bd9Sstevel@tonic-gate /* sw = 1 ==> ccl */
3357c478bd9Sstevel@tonic-gate int i, j, k;
3367c478bd9Sstevel@tonic-gate int m;
3377c478bd9Sstevel@tonic-gate if (!sw) { /* is NCCL */
3387c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++)
3397c478bd9Sstevel@tonic-gate symbol[i] ^= 1; /* reverse value */
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++)
3427c478bd9Sstevel@tonic-gate if (symbol[i])
3437c478bd9Sstevel@tonic-gate break;
3447c478bd9Sstevel@tonic-gate if (i >= ncg)
3457c478bd9Sstevel@tonic-gate return;
3467c478bd9Sstevel@tonic-gate i = cindex[i];
3477c478bd9Sstevel@tonic-gate /* see if ccl is already in our table */
3487c478bd9Sstevel@tonic-gate j = 0;
3497c478bd9Sstevel@tonic-gate if (i) {
3507c478bd9Sstevel@tonic-gate for (j = 1; j < ncg; j++) {
3517c478bd9Sstevel@tonic-gate if ((symbol[j] && cindex[j] != i) ||
3527c478bd9Sstevel@tonic-gate (!symbol[j] && cindex[j] == i))
3537c478bd9Sstevel@tonic-gate break;
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate if (j >= ncg)
3577c478bd9Sstevel@tonic-gate return; /* already in */
3587c478bd9Sstevel@tonic-gate m = 0;
3597c478bd9Sstevel@tonic-gate k = 0;
3607c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++) {
3617c478bd9Sstevel@tonic-gate if (symbol[i]) {
3627c478bd9Sstevel@tonic-gate if (!cindex[i]) {
3637c478bd9Sstevel@tonic-gate cindex[i] = ccount;
3647c478bd9Sstevel@tonic-gate symbol[i] = 0;
3657c478bd9Sstevel@tonic-gate m = 1;
3667c478bd9Sstevel@tonic-gate } else
3677c478bd9Sstevel@tonic-gate k = 1;
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate /* m == 1 implies last value of ccount has been used */
3717c478bd9Sstevel@tonic-gate if (m)
3727c478bd9Sstevel@tonic-gate ccount++;
3737c478bd9Sstevel@tonic-gate if (k == 0)
3747c478bd9Sstevel@tonic-gate return; /* is now in as ccount wholly */
3757c478bd9Sstevel@tonic-gate /* intersection must be computed */
3767c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++) {
3777c478bd9Sstevel@tonic-gate if (symbol[i]) {
3787c478bd9Sstevel@tonic-gate m = 0;
3797c478bd9Sstevel@tonic-gate j = cindex[i]; /* will be non-zero */
3807c478bd9Sstevel@tonic-gate for (k = 1; k < ncg; k++) {
3817c478bd9Sstevel@tonic-gate if (cindex[k] == j) {
3827c478bd9Sstevel@tonic-gate if (symbol[k])
3837c478bd9Sstevel@tonic-gate symbol[k] = 0;
3847c478bd9Sstevel@tonic-gate else {
3857c478bd9Sstevel@tonic-gate cindex[k] = ccount;
3867c478bd9Sstevel@tonic-gate m = 1;
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate if (m)
3917c478bd9Sstevel@tonic-gate ccount++;
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate int
usescape(int c)3977c478bd9Sstevel@tonic-gate usescape(int c)
3987c478bd9Sstevel@tonic-gate {
3997c478bd9Sstevel@tonic-gate char d;
4007c478bd9Sstevel@tonic-gate switch (c) {
4017c478bd9Sstevel@tonic-gate case 'a':
4027c478bd9Sstevel@tonic-gate c = '\a';
4037c478bd9Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character"); break;
4047c478bd9Sstevel@tonic-gate case 'v': c = '\v'; break;
4057c478bd9Sstevel@tonic-gate case 'n': c = '\n'; break;
4067c478bd9Sstevel@tonic-gate case 'r': c = '\r'; break;
4077c478bd9Sstevel@tonic-gate case 't': c = '\t'; break;
4087c478bd9Sstevel@tonic-gate case 'b': c = '\b'; break;
4097c478bd9Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */
4107c478bd9Sstevel@tonic-gate case 'x': {
4117c478bd9Sstevel@tonic-gate int dd;
4127c478bd9Sstevel@tonic-gate if (digit((dd = gch())) ||
4137c478bd9Sstevel@tonic-gate ('A' <= dd && dd <= 'F') ||
4147c478bd9Sstevel@tonic-gate ('a' <= dd && dd <= 'f')) {
4157c478bd9Sstevel@tonic-gate c = 0;
4167c478bd9Sstevel@tonic-gate while (digit(dd) ||
4177c478bd9Sstevel@tonic-gate ('A' <= dd && dd <= 'F') ||
4187c478bd9Sstevel@tonic-gate ('a' <= dd && dd <= 'f')) {
4197c478bd9Sstevel@tonic-gate if (digit(dd))
4207c478bd9Sstevel@tonic-gate c = c*16 + dd - '0';
4217c478bd9Sstevel@tonic-gate else if (dd >= 'a')
4227c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'a';
4237c478bd9Sstevel@tonic-gate else
4247c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'A';
4257c478bd9Sstevel@tonic-gate if (!digit(peek) &&
4267c478bd9Sstevel@tonic-gate !('A' <= peek && peek <= 'F') &&
4277c478bd9Sstevel@tonic-gate !('a' <= peek && peek <= 'f'))
4287c478bd9Sstevel@tonic-gate break;
4297c478bd9Sstevel@tonic-gate dd = gch();
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate } else
4337c478bd9Sstevel@tonic-gate c = 'x';
4347c478bd9Sstevel@tonic-gate break;
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3':
4377c478bd9Sstevel@tonic-gate case '4': case '5': case '6': case '7':
4387c478bd9Sstevel@tonic-gate c -= '0';
4397c478bd9Sstevel@tonic-gate while ('0' <= (d = gch()) && d <= '7') {
4407c478bd9Sstevel@tonic-gate c = c * 8 + (d-'0');
4417c478bd9Sstevel@tonic-gate if (!('0' <= peek && peek <= '7')) break;
4427c478bd9Sstevel@tonic-gate }
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate break;
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate if (handleeuc && !isascii(c)) {
4487c478bd9Sstevel@tonic-gate char tmpchar = c & 0x00ff;
449*1dd08564Sab196087 (void) mbtowc((wchar_t *)&c, &tmpchar, sizeof (tmpchar));
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate return (c);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate int
lookup(CHR * s,CHR ** t)4557c478bd9Sstevel@tonic-gate lookup(CHR *s, CHR **t)
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate int i;
4587c478bd9Sstevel@tonic-gate i = 0;
4597c478bd9Sstevel@tonic-gate while (*t) {
4607c478bd9Sstevel@tonic-gate if (scomp(s, *t) == 0)
4617c478bd9Sstevel@tonic-gate return (i);
4627c478bd9Sstevel@tonic-gate i++;
4637c478bd9Sstevel@tonic-gate t++;
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate return (-1);
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate void
cpycom(CHR * p)4697c478bd9Sstevel@tonic-gate cpycom(CHR *p)
4707c478bd9Sstevel@tonic-gate {
4717c478bd9Sstevel@tonic-gate static CHR *t;
4727c478bd9Sstevel@tonic-gate static int c;
4737c478bd9Sstevel@tonic-gate t = p;
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate if (sargv[optind] == NULL)
4767c478bd9Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline);
4777c478bd9Sstevel@tonic-gate else
4787c478bd9Sstevel@tonic-gate (void) fprintf(fout,
4797c478bd9Sstevel@tonic-gate "\n# line %d \"%s\"\n", yyline, sargv[optind]);
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4827c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4837c478bd9Sstevel@tonic-gate while (*t) {
4847c478bd9Sstevel@tonic-gate while (*t == '*') {
4857c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4867c478bd9Sstevel@tonic-gate if (*t == '/')
4877c478bd9Sstevel@tonic-gate goto backcall;
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate * FIX BUG #1058428, not parsing comments correctly
4917c478bd9Sstevel@tonic-gate * that span more than one line
4927c478bd9Sstevel@tonic-gate */
4937c478bd9Sstevel@tonic-gate if (*t != NULL)
4947c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
4977c478bd9Sstevel@tonic-gate while (c = gch()) {
4987c478bd9Sstevel@tonic-gate while (c == '*') {
4997c478bd9Sstevel@tonic-gate (void) putc((char)c, fout);
5007c478bd9Sstevel@tonic-gate if ((c = gch()) == '/') {
50167298654Sdamico while ((c = gch()) == ' ' || c == '\t')
502*1dd08564Sab196087 ;
5037c478bd9Sstevel@tonic-gate if (!space(c))
5047c478bd9Sstevel@tonic-gate error("unacceptable statement");
5057c478bd9Sstevel@tonic-gate prev = '\n';
5067c478bd9Sstevel@tonic-gate goto backcall;
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate }
5097c478bd9Sstevel@tonic-gate (void) putc((char)c, fout);
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate error("unexpected EOF inside comment");
5127c478bd9Sstevel@tonic-gate backcall:
5137c478bd9Sstevel@tonic-gate (void) putc('/', fout);
5147c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
5157c478bd9Sstevel@tonic-gate }
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate /*
5187c478bd9Sstevel@tonic-gate * copy C action to the next ; or closing
5197c478bd9Sstevel@tonic-gate */
5207c478bd9Sstevel@tonic-gate int
cpyact(void)5217c478bd9Sstevel@tonic-gate cpyact(void)
5227c478bd9Sstevel@tonic-gate {
5237c478bd9Sstevel@tonic-gate int brac, c, mth;
5247c478bd9Sstevel@tonic-gate static int sw, savline;
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate brac = 0;
5277c478bd9Sstevel@tonic-gate sw = TRUE;
5287c478bd9Sstevel@tonic-gate savline = yyline;
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate if (sargv[optind] == NULL)
5317c478bd9Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline);
5327c478bd9Sstevel@tonic-gate else
5337c478bd9Sstevel@tonic-gate (void) fprintf(fout,
5347c478bd9Sstevel@tonic-gate "\n# line %d \"%s\"\n", yyline, sargv[optind]);
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate while (!eof) {
5377c478bd9Sstevel@tonic-gate c = gch();
5387c478bd9Sstevel@tonic-gate swt:
5397c478bd9Sstevel@tonic-gate switch (c) {
5407c478bd9Sstevel@tonic-gate case '|':
5417c478bd9Sstevel@tonic-gate if (brac == 0 && sw == TRUE) {
5427c478bd9Sstevel@tonic-gate if (peek == '|')
5437c478bd9Sstevel@tonic-gate (void) gch(); /* eat up an extra '|' */
5447c478bd9Sstevel@tonic-gate return (0);
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate break;
5477c478bd9Sstevel@tonic-gate case ';':
5487c478bd9Sstevel@tonic-gate if (brac == 0) {
5497c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5507c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
5517c478bd9Sstevel@tonic-gate return (1);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate break;
5547c478bd9Sstevel@tonic-gate case '{':
5557c478bd9Sstevel@tonic-gate brac++;
5567c478bd9Sstevel@tonic-gate savline = yyline;
5577c478bd9Sstevel@tonic-gate break;
5587c478bd9Sstevel@tonic-gate case '}':
5597c478bd9Sstevel@tonic-gate brac--;
5607c478bd9Sstevel@tonic-gate if (brac == 0) {
5617c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5627c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
5637c478bd9Sstevel@tonic-gate return (1);
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate break;
5667c478bd9Sstevel@tonic-gate case '/':
5677c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5687c478bd9Sstevel@tonic-gate c = gch();
5697c478bd9Sstevel@tonic-gate if (c != '*')
5707c478bd9Sstevel@tonic-gate goto swt;
5717c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5727c478bd9Sstevel@tonic-gate savline = yyline;
5737c478bd9Sstevel@tonic-gate while (c = gch()) {
5747c478bd9Sstevel@tonic-gate while (c == '*') {
5757c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5767c478bd9Sstevel@tonic-gate if ((c = gch()) == '/') {
5777c478bd9Sstevel@tonic-gate (void) putc('/', fout);
5787c478bd9Sstevel@tonic-gate while ((c = gch()) == ' ' ||
5797c478bd9Sstevel@tonic-gate c == '\t' || c == '\n')
5807c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5817c478bd9Sstevel@tonic-gate goto swt;
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate (void) putc((char)c, fout);
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate yyline = savline;
5877c478bd9Sstevel@tonic-gate error("EOF inside comment");
5887c478bd9Sstevel@tonic-gate /* NOTREACHED */
5897c478bd9Sstevel@tonic-gate break;
5907c478bd9Sstevel@tonic-gate case '\'': /* character constant */
5917c478bd9Sstevel@tonic-gate case '"': /* character string */
5927c478bd9Sstevel@tonic-gate mth = c;
5937c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5947c478bd9Sstevel@tonic-gate while (c = gch()) {
5957c478bd9Sstevel@tonic-gate if (c == '\\') {
5967c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5977c478bd9Sstevel@tonic-gate c = gch();
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate else
6007c478bd9Sstevel@tonic-gate if (c == mth)
6017c478bd9Sstevel@tonic-gate goto loop;
6027c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
6037c478bd9Sstevel@tonic-gate if (c == '\n') {
6047c478bd9Sstevel@tonic-gate yyline--;
6057c478bd9Sstevel@tonic-gate error(
6067c478bd9Sstevel@tonic-gate "Non-terminated string or character constant");
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate error("EOF in string or character constant");
6107c478bd9Sstevel@tonic-gate /* NOTREACHED */
6117c478bd9Sstevel@tonic-gate break;
6127c478bd9Sstevel@tonic-gate case '\0':
6137c478bd9Sstevel@tonic-gate yyline = savline;
6147c478bd9Sstevel@tonic-gate error("Action does not terminate");
6157c478bd9Sstevel@tonic-gate /* NOTREACHED */
6167c478bd9Sstevel@tonic-gate break;
6177c478bd9Sstevel@tonic-gate default:
6187c478bd9Sstevel@tonic-gate break; /* usual character */
6197c478bd9Sstevel@tonic-gate }
6207c478bd9Sstevel@tonic-gate loop:
6217c478bd9Sstevel@tonic-gate if (c != ' ' && c != '\t' && c != '\n')
6227c478bd9Sstevel@tonic-gate sw = FALSE;
6237c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
6247c478bd9Sstevel@tonic-gate if (peek == '\n' && !brac && copy_line) {
6257c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
6267c478bd9Sstevel@tonic-gate return (1);
6277c478bd9Sstevel@tonic-gate }
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate error("Premature EOF");
6307c478bd9Sstevel@tonic-gate return (0);
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate int
gch(void)6347c478bd9Sstevel@tonic-gate gch(void)
6357c478bd9Sstevel@tonic-gate {
6367c478bd9Sstevel@tonic-gate int c;
6377c478bd9Sstevel@tonic-gate prev = pres;
6387c478bd9Sstevel@tonic-gate c = pres = peek;
6397c478bd9Sstevel@tonic-gate peek = pushptr > pushc ? *--pushptr : getwc(fin);
6407c478bd9Sstevel@tonic-gate while (peek == EOF) {
6417c478bd9Sstevel@tonic-gate if (no_input) {
6427c478bd9Sstevel@tonic-gate if (!yyline)
6437c478bd9Sstevel@tonic-gate error("Cannot read from -- %s",
6447c478bd9Sstevel@tonic-gate sargv[optind]);
6457c478bd9Sstevel@tonic-gate if (optind < sargc-1) {
6467c478bd9Sstevel@tonic-gate yyline = 0;
6477c478bd9Sstevel@tonic-gate if (fin != stdin)
6487c478bd9Sstevel@tonic-gate (void) fclose(fin);
6497c478bd9Sstevel@tonic-gate fin = fopen(sargv[++optind], "r");
6507c478bd9Sstevel@tonic-gate if (fin == NULL)
6517c478bd9Sstevel@tonic-gate error("Cannot open file -- %s",
6527c478bd9Sstevel@tonic-gate sargv[optind]);
6537c478bd9Sstevel@tonic-gate peek = getwc(fin);
6547c478bd9Sstevel@tonic-gate } else
6557c478bd9Sstevel@tonic-gate break;
6567c478bd9Sstevel@tonic-gate } else {
6577c478bd9Sstevel@tonic-gate if (fin != stdin)
6587c478bd9Sstevel@tonic-gate (void) fclose(fin);
6597c478bd9Sstevel@tonic-gate if (!yyline)
6607c478bd9Sstevel@tonic-gate error("Cannot read from -- standard input");
6617c478bd9Sstevel@tonic-gate else
6627c478bd9Sstevel@tonic-gate break;
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate if (c == EOF) {
6667c478bd9Sstevel@tonic-gate eof = TRUE;
6677c478bd9Sstevel@tonic-gate return (0);
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate if (c == '\n')
6707c478bd9Sstevel@tonic-gate yyline++;
6717c478bd9Sstevel@tonic-gate return (c);
6727c478bd9Sstevel@tonic-gate }
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate int
mn2(int a,int d,int c)6757c478bd9Sstevel@tonic-gate mn2(int a, int d, int c)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate if (tptr >= treesize) {
6787c478bd9Sstevel@tonic-gate tptr++;
6797c478bd9Sstevel@tonic-gate error("Parse tree too big %s",
6807c478bd9Sstevel@tonic-gate (treesize == TREESIZE ? "\nTry using %e num" : ""));
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate if (d >= treesize) {
6837c478bd9Sstevel@tonic-gate error("Parse error");
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate name[tptr] = a;
6867c478bd9Sstevel@tonic-gate left[tptr] = d;
6877c478bd9Sstevel@tonic-gate right[tptr] = c;
6887c478bd9Sstevel@tonic-gate parent[tptr] = 0;
6897c478bd9Sstevel@tonic-gate nullstr[tptr] = 0;
6907c478bd9Sstevel@tonic-gate switch (a) {
6917c478bd9Sstevel@tonic-gate case RSTR:
6927c478bd9Sstevel@tonic-gate parent[d] = tptr;
6937c478bd9Sstevel@tonic-gate break;
6947c478bd9Sstevel@tonic-gate case BAR:
6957c478bd9Sstevel@tonic-gate case RNEWE:
6967c478bd9Sstevel@tonic-gate if (nullstr[d] || nullstr[c])
6977c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
6987c478bd9Sstevel@tonic-gate parent[d] = parent[c] = tptr;
6997c478bd9Sstevel@tonic-gate break;
7007c478bd9Sstevel@tonic-gate case RCAT:
7017c478bd9Sstevel@tonic-gate case DIV:
7027c478bd9Sstevel@tonic-gate if (nullstr[d] && nullstr[c])
7037c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7047c478bd9Sstevel@tonic-gate parent[d] = parent[c] = tptr;
7057c478bd9Sstevel@tonic-gate break;
7067c478bd9Sstevel@tonic-gate /* XCU4: add RXSCON */
7077c478bd9Sstevel@tonic-gate case RXSCON:
7087c478bd9Sstevel@tonic-gate case RSCON:
7097c478bd9Sstevel@tonic-gate parent[d] = tptr;
7107c478bd9Sstevel@tonic-gate nullstr[tptr] = nullstr[d];
7117c478bd9Sstevel@tonic-gate break;
7127c478bd9Sstevel@tonic-gate #ifdef DEBUG
7137c478bd9Sstevel@tonic-gate default:
7147c478bd9Sstevel@tonic-gate warning("bad switch mn2 %d %d", a, d);
7157c478bd9Sstevel@tonic-gate break;
7167c478bd9Sstevel@tonic-gate #endif
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate return (tptr++);
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate int
mn1(int a,int d)7227c478bd9Sstevel@tonic-gate mn1(int a, int d)
7237c478bd9Sstevel@tonic-gate {
7247c478bd9Sstevel@tonic-gate if (tptr >= treesize) {
7257c478bd9Sstevel@tonic-gate tptr++;
7267c478bd9Sstevel@tonic-gate error("Parse tree too big %s",
7277c478bd9Sstevel@tonic-gate (treesize == TREESIZE ? "\nTry using %e num" : ""));
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate name[tptr] = a;
7307c478bd9Sstevel@tonic-gate left[tptr] = d;
7317c478bd9Sstevel@tonic-gate parent[tptr] = 0;
7327c478bd9Sstevel@tonic-gate nullstr[tptr] = 0;
7337c478bd9Sstevel@tonic-gate switch (a) {
7347c478bd9Sstevel@tonic-gate case RCCL:
7357c478bd9Sstevel@tonic-gate case RNCCL:
7367c478bd9Sstevel@tonic-gate if (slength((CHR *)d) == 0)
7377c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7387c478bd9Sstevel@tonic-gate break;
7397c478bd9Sstevel@tonic-gate case STAR:
7407c478bd9Sstevel@tonic-gate case QUEST:
7417c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7427c478bd9Sstevel@tonic-gate parent[d] = tptr;
7437c478bd9Sstevel@tonic-gate break;
7447c478bd9Sstevel@tonic-gate case PLUS:
7457c478bd9Sstevel@tonic-gate case CARAT:
7467c478bd9Sstevel@tonic-gate nullstr[tptr] = nullstr[d];
7477c478bd9Sstevel@tonic-gate parent[d] = tptr;
7487c478bd9Sstevel@tonic-gate break;
7497c478bd9Sstevel@tonic-gate case S2FINAL:
7507c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7517c478bd9Sstevel@tonic-gate break;
7527c478bd9Sstevel@tonic-gate #ifdef DEBUG
7537c478bd9Sstevel@tonic-gate case FINAL:
7547c478bd9Sstevel@tonic-gate case S1FINAL:
7557c478bd9Sstevel@tonic-gate break;
7567c478bd9Sstevel@tonic-gate default:
7577c478bd9Sstevel@tonic-gate warning("bad switch mn1 %d %d", a, d);
7587c478bd9Sstevel@tonic-gate break;
7597c478bd9Sstevel@tonic-gate #endif
7607c478bd9Sstevel@tonic-gate }
7617c478bd9Sstevel@tonic-gate return (tptr++);
7627c478bd9Sstevel@tonic-gate }
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate int
mn0(int a)7657c478bd9Sstevel@tonic-gate mn0(int a)
7667c478bd9Sstevel@tonic-gate {
7677c478bd9Sstevel@tonic-gate if (tptr >= treesize) {
7687c478bd9Sstevel@tonic-gate tptr++;
7697c478bd9Sstevel@tonic-gate error("Parse tree too big %s",
7707c478bd9Sstevel@tonic-gate (treesize == TREESIZE ? "\nTry using %e num" : ""));
7717c478bd9Sstevel@tonic-gate }
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate name[tptr] = a;
7747c478bd9Sstevel@tonic-gate parent[tptr] = 0;
7757c478bd9Sstevel@tonic-gate nullstr[tptr] = 0;
7767c478bd9Sstevel@tonic-gate if (ISOPERATOR(a)) {
7777c478bd9Sstevel@tonic-gate switch (a) {
7787c478bd9Sstevel@tonic-gate case DOT: break;
7797c478bd9Sstevel@tonic-gate case RNULLS: nullstr[tptr] = TRUE; break;
7807c478bd9Sstevel@tonic-gate #ifdef DEBUG
7817c478bd9Sstevel@tonic-gate default:
7827c478bd9Sstevel@tonic-gate warning("bad switch mn0 %d", a);
7837c478bd9Sstevel@tonic-gate break;
7847c478bd9Sstevel@tonic-gate #endif
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate return (tptr++);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate void
munput(int t,CHR * p)7917c478bd9Sstevel@tonic-gate munput(int t, CHR *p)
7927c478bd9Sstevel@tonic-gate {
7937c478bd9Sstevel@tonic-gate int i, j;
7947c478bd9Sstevel@tonic-gate if (t == 'c') {
7957c478bd9Sstevel@tonic-gate *pushptr++ = peek;
7967c478bd9Sstevel@tonic-gate peek = *p;
7977c478bd9Sstevel@tonic-gate } else if (t == 's') {
7987c478bd9Sstevel@tonic-gate *pushptr++ = peek;
7997c478bd9Sstevel@tonic-gate peek = p[0];
8007c478bd9Sstevel@tonic-gate i = slength(p);
8017c478bd9Sstevel@tonic-gate for (j = i - 1; j >= 1; j--)
8027c478bd9Sstevel@tonic-gate *pushptr++ = p[j];
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate if (pushptr >= pushc + TOKENSIZE)
8057c478bd9Sstevel@tonic-gate error("Too many characters pushed");
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate int
dupl(int n)8097c478bd9Sstevel@tonic-gate dupl(int n)
8107c478bd9Sstevel@tonic-gate {
8117c478bd9Sstevel@tonic-gate /* duplicate the subtree whose root is n, return ptr to it */
8127c478bd9Sstevel@tonic-gate int i;
8137c478bd9Sstevel@tonic-gate i = name[n];
8147c478bd9Sstevel@tonic-gate if (!ISOPERATOR(i))
8157c478bd9Sstevel@tonic-gate return (mn0(i));
8167c478bd9Sstevel@tonic-gate switch (i) {
8177c478bd9Sstevel@tonic-gate case DOT:
8187c478bd9Sstevel@tonic-gate case RNULLS:
8197c478bd9Sstevel@tonic-gate return (mn0(i));
8207c478bd9Sstevel@tonic-gate case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL:
8217c478bd9Sstevel@tonic-gate return (mn1(i, left[n]));
8227c478bd9Sstevel@tonic-gate case STAR: case QUEST: case PLUS: case CARAT:
8237c478bd9Sstevel@tonic-gate return (mn1(i, dupl(left[n])));
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate /* XCU4: add RXSCON */
8267c478bd9Sstevel@tonic-gate case RSTR: case RSCON: case RXSCON:
8277c478bd9Sstevel@tonic-gate return (mn2(i, dupl(left[n]), right[n]));
8287c478bd9Sstevel@tonic-gate case BAR: case RNEWE: case RCAT: case DIV:
8297c478bd9Sstevel@tonic-gate return (mn2(i, dupl(left[n]), dupl(right[n])));
8307c478bd9Sstevel@tonic-gate }
8317c478bd9Sstevel@tonic-gate return (0);
8327c478bd9Sstevel@tonic-gate }
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate #ifdef DEBUG
8357c478bd9Sstevel@tonic-gate void
allprint(CHR c)8367c478bd9Sstevel@tonic-gate allprint(CHR c)
8377c478bd9Sstevel@tonic-gate {
8387c478bd9Sstevel@tonic-gate switch (c) {
8397c478bd9Sstevel@tonic-gate case 014:
8407c478bd9Sstevel@tonic-gate (void) printf("\\f");
8417c478bd9Sstevel@tonic-gate charc++;
8427c478bd9Sstevel@tonic-gate break;
8437c478bd9Sstevel@tonic-gate case '\n':
8447c478bd9Sstevel@tonic-gate (void) printf("\\n");
8457c478bd9Sstevel@tonic-gate charc++;
8467c478bd9Sstevel@tonic-gate break;
8477c478bd9Sstevel@tonic-gate case '\t':
8487c478bd9Sstevel@tonic-gate (void) printf("\\t");
8497c478bd9Sstevel@tonic-gate charc++;
8507c478bd9Sstevel@tonic-gate break;
8517c478bd9Sstevel@tonic-gate case '\b':
8527c478bd9Sstevel@tonic-gate (void) printf("\\b");
8537c478bd9Sstevel@tonic-gate charc++;
8547c478bd9Sstevel@tonic-gate break;
8557c478bd9Sstevel@tonic-gate case ' ':
8567c478bd9Sstevel@tonic-gate (void) printf("\\_");
8577c478bd9Sstevel@tonic-gate break;
8587c478bd9Sstevel@tonic-gate default:
8597c478bd9Sstevel@tonic-gate if (!iswprint(c)) {
8607c478bd9Sstevel@tonic-gate printf("\\x%-2x", c); /* up to fashion. */
8617c478bd9Sstevel@tonic-gate charc += 3;
8627c478bd9Sstevel@tonic-gate } else
8637c478bd9Sstevel@tonic-gate (void) putwc(c, stdout);
8647c478bd9Sstevel@tonic-gate break;
8657c478bd9Sstevel@tonic-gate }
8667c478bd9Sstevel@tonic-gate charc++;
8677c478bd9Sstevel@tonic-gate }
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate void
strpt(CHR * s)8707c478bd9Sstevel@tonic-gate strpt(CHR *s)
8717c478bd9Sstevel@tonic-gate {
8727c478bd9Sstevel@tonic-gate charc = 0;
8737c478bd9Sstevel@tonic-gate while (*s) {
8747c478bd9Sstevel@tonic-gate allprint(*s++);
8757c478bd9Sstevel@tonic-gate if (charc > LINESIZE) {
8767c478bd9Sstevel@tonic-gate charc = 0;
8777c478bd9Sstevel@tonic-gate (void) printf("\n\t");
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate }
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate void
sect1dump(void)8837c478bd9Sstevel@tonic-gate sect1dump(void)
8847c478bd9Sstevel@tonic-gate {
8857c478bd9Sstevel@tonic-gate int i;
8867c478bd9Sstevel@tonic-gate (void) printf("Sect 1:\n");
8877c478bd9Sstevel@tonic-gate if (def[0]) {
8887c478bd9Sstevel@tonic-gate (void) printf("str trans\n");
8897c478bd9Sstevel@tonic-gate i = -1;
8907c478bd9Sstevel@tonic-gate while (def[++i])
8917c478bd9Sstevel@tonic-gate (void) printf("%ws\t%ws\n", def[i], subs[i]);
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate if (sname[0]) {
8947c478bd9Sstevel@tonic-gate (void) printf("start names\n");
8957c478bd9Sstevel@tonic-gate i = -1;
8967c478bd9Sstevel@tonic-gate while (sname[++i])
8977c478bd9Sstevel@tonic-gate (void) printf("%ws\n", sname[i]);
8987c478bd9Sstevel@tonic-gate }
8997c478bd9Sstevel@tonic-gate if (chset == TRUE) {
9007c478bd9Sstevel@tonic-gate (void) printf("char set changed\n");
9017c478bd9Sstevel@tonic-gate for (i = 1; i < NCH; i++) {
9027c478bd9Sstevel@tonic-gate if (i != ctable[i]) {
9037c478bd9Sstevel@tonic-gate allprint(i);
9047c478bd9Sstevel@tonic-gate (void) putchar(' ');
9057c478bd9Sstevel@tonic-gate iswprint(ctable[i]) ?
9067c478bd9Sstevel@tonic-gate (void) putwc(ctable[i], stdout) :
9077c478bd9Sstevel@tonic-gate (void) printf("%d", ctable[i]);
9087c478bd9Sstevel@tonic-gate (void) putchar('\n');
9097c478bd9Sstevel@tonic-gate }
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate }
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate void
sect2dump(void)9157c478bd9Sstevel@tonic-gate sect2dump(void)
9167c478bd9Sstevel@tonic-gate {
9177c478bd9Sstevel@tonic-gate (void) printf("Sect 2:\n");
9187c478bd9Sstevel@tonic-gate treedump();
9197c478bd9Sstevel@tonic-gate }
9207c478bd9Sstevel@tonic-gate
9217c478bd9Sstevel@tonic-gate void
treedump(void)9227c478bd9Sstevel@tonic-gate treedump(void)
9237c478bd9Sstevel@tonic-gate {
9247c478bd9Sstevel@tonic-gate int t;
9257c478bd9Sstevel@tonic-gate CHR *p;
9267c478bd9Sstevel@tonic-gate (void) printf("treedump %d nodes:\n", tptr);
9277c478bd9Sstevel@tonic-gate for (t = 0; t < tptr; t++) {
9287c478bd9Sstevel@tonic-gate (void) printf("%4d ", t);
9297c478bd9Sstevel@tonic-gate parent[t] ? (void) printf("p=%4d", parent[t]) :
9307c478bd9Sstevel@tonic-gate (void) printf(" ");
9317c478bd9Sstevel@tonic-gate (void) printf(" ");
9327c478bd9Sstevel@tonic-gate if (!ISOPERATOR(name[t])) {
9337c478bd9Sstevel@tonic-gate allprint(name[t]);
9347c478bd9Sstevel@tonic-gate } else
9357c478bd9Sstevel@tonic-gate switch (name[t]) {
9367c478bd9Sstevel@tonic-gate case RSTR:
9377c478bd9Sstevel@tonic-gate (void) printf("%d ", left[t]);
9387c478bd9Sstevel@tonic-gate allprint(right[t]);
9397c478bd9Sstevel@tonic-gate break;
9407c478bd9Sstevel@tonic-gate case RCCL:
9417c478bd9Sstevel@tonic-gate (void) printf("ccl ");
9427c478bd9Sstevel@tonic-gate strpt(left[t]);
9437c478bd9Sstevel@tonic-gate break;
9447c478bd9Sstevel@tonic-gate case RNCCL:
9457c478bd9Sstevel@tonic-gate (void) printf("nccl ");
9467c478bd9Sstevel@tonic-gate strpt(left[t]);
9477c478bd9Sstevel@tonic-gate break;
9487c478bd9Sstevel@tonic-gate case DIV:
9497c478bd9Sstevel@tonic-gate (void) printf("/ %d %d", left[t], right[t]);
9507c478bd9Sstevel@tonic-gate break;
9517c478bd9Sstevel@tonic-gate case BAR:
9527c478bd9Sstevel@tonic-gate (void) printf("| %d %d", left[t], right[t]);
9537c478bd9Sstevel@tonic-gate break;
9547c478bd9Sstevel@tonic-gate case RCAT:
9557c478bd9Sstevel@tonic-gate (void) printf("cat %d %d", left[t], right[t]);
9567c478bd9Sstevel@tonic-gate break;
9577c478bd9Sstevel@tonic-gate case PLUS:
9587c478bd9Sstevel@tonic-gate (void) printf("+ %d", left[t]);
9597c478bd9Sstevel@tonic-gate break;
9607c478bd9Sstevel@tonic-gate case STAR:
9617c478bd9Sstevel@tonic-gate (void) printf("* %d", left[t]);
9627c478bd9Sstevel@tonic-gate break;
9637c478bd9Sstevel@tonic-gate case CARAT:
9647c478bd9Sstevel@tonic-gate (void) printf("^ %d", left[t]);
9657c478bd9Sstevel@tonic-gate break;
9667c478bd9Sstevel@tonic-gate case QUEST:
9677c478bd9Sstevel@tonic-gate (void) printf("? %d", left[t]);
9687c478bd9Sstevel@tonic-gate break;
9697c478bd9Sstevel@tonic-gate case RNULLS:
9707c478bd9Sstevel@tonic-gate (void) printf("nullstring");
9717c478bd9Sstevel@tonic-gate break;
9727c478bd9Sstevel@tonic-gate case FINAL:
9737c478bd9Sstevel@tonic-gate (void) printf("final %d", left[t]);
9747c478bd9Sstevel@tonic-gate break;
9757c478bd9Sstevel@tonic-gate case S1FINAL:
9767c478bd9Sstevel@tonic-gate (void) printf("s1final %d", left[t]);
9777c478bd9Sstevel@tonic-gate break;
9787c478bd9Sstevel@tonic-gate case S2FINAL:
9797c478bd9Sstevel@tonic-gate (void) printf("s2final %d", left[t]);
9807c478bd9Sstevel@tonic-gate break;
9817c478bd9Sstevel@tonic-gate case RNEWE:
9827c478bd9Sstevel@tonic-gate (void) printf("new %d %d", left[t], right[t]);
9837c478bd9Sstevel@tonic-gate break;
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate /* XCU4: add RXSCON */
9867c478bd9Sstevel@tonic-gate case RXSCON:
9877c478bd9Sstevel@tonic-gate p = (CHR *)right[t];
9887c478bd9Sstevel@tonic-gate (void) printf("exstart %s", sname[*p++-1]);
9897c478bd9Sstevel@tonic-gate while (*p)
9907c478bd9Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]);
9917c478bd9Sstevel@tonic-gate (void) printf(" %d", left[t]);
9927c478bd9Sstevel@tonic-gate break;
9937c478bd9Sstevel@tonic-gate case RSCON:
9947c478bd9Sstevel@tonic-gate p = (CHR *)right[t];
9957c478bd9Sstevel@tonic-gate (void) printf("start %s", sname[*p++-1]);
9967c478bd9Sstevel@tonic-gate while (*p)
9977c478bd9Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]);
9987c478bd9Sstevel@tonic-gate (void) printf(" %d", left[t]);
9997c478bd9Sstevel@tonic-gate break;
10007c478bd9Sstevel@tonic-gate case DOT:
10017c478bd9Sstevel@tonic-gate printf("dot");
10027c478bd9Sstevel@tonic-gate break;
10037c478bd9Sstevel@tonic-gate default:
10047c478bd9Sstevel@tonic-gate (void) printf(
10057c478bd9Sstevel@tonic-gate "unknown %d %d %d", name[t], left[t], right[t]);
10067c478bd9Sstevel@tonic-gate break;
10077c478bd9Sstevel@tonic-gate }
10087c478bd9Sstevel@tonic-gate if (nullstr[t])
10097c478bd9Sstevel@tonic-gate (void) printf("\t(null poss.)");
10107c478bd9Sstevel@tonic-gate (void) putchar('\n');
10117c478bd9Sstevel@tonic-gate }
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate #endif
1014