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 /*
221dd08564Sab * 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
29e207f0deSToomas Soome #include <stdio.h>
30e207f0deSToomas Soome #include <stdarg.h>
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') {
5267298654Sdamico if (!blank) {
5367298654Sdamico blank = 1;
5467298654Sdamico u = t;
5567298654Sdamico }
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 void
error(char * s,...)92e207f0deSToomas Soome error(char *s, ...)
937c478bd9Sstevel@tonic-gate {
94e207f0deSToomas Soome va_list ap;
95e207f0deSToomas Soome
967c478bd9Sstevel@tonic-gate /* if(!eof) */
97e207f0deSToomas Soome if (!yyline) {
987c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Command line: ");
99e207f0deSToomas Soome } else {
1007c478bd9Sstevel@tonic-gate (void) fprintf(errorf,
101e207f0deSToomas Soome !no_input ? "" : "\"%s\":", sargv[optind]);
1027c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "line %d: ", yyline);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Error: ");
105e207f0deSToomas Soome va_start(ap, s);
106e207f0deSToomas Soome (void) vfprintf(errorf, s, ap);
107e207f0deSToomas Soome va_end(ap);
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 void
warning(char * s,...)130e207f0deSToomas Soome warning(char *s, ...)
1317c478bd9Sstevel@tonic-gate {
132e207f0deSToomas Soome va_list ap;
133e207f0deSToomas Soome
134*55855f50SToomas Soome if (!eof) {
135*55855f50SToomas Soome if (!yyline) {
1367c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Command line: ");
137*55855f50SToomas Soome } else {
1387c478bd9Sstevel@tonic-gate (void) fprintf(errorf,
139e207f0deSToomas Soome !no_input ? "" : "\"%s\":", sargv[optind]);
1407c478bd9Sstevel@tonic-gate (void) fprintf(errorf,
141e207f0deSToomas Soome "line %d: ", yyline);
1427c478bd9Sstevel@tonic-gate }
143*55855f50SToomas Soome }
1447c478bd9Sstevel@tonic-gate (void) fprintf(errorf, "Warning: ");
145e207f0deSToomas Soome va_start(ap, s);
146e207f0deSToomas Soome (void) vfprintf(errorf, s, ap);
147e207f0deSToomas Soome va_end(ap);
1487c478bd9Sstevel@tonic-gate (void) putc('\n', errorf);
1497c478bd9Sstevel@tonic-gate (void) fflush(errorf);
1507c478bd9Sstevel@tonic-gate if (fout)
1517c478bd9Sstevel@tonic-gate (void) fflush(fout);
1527c478bd9Sstevel@tonic-gate (void) fflush(stdout);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1551dd08564Sab /*
1561dd08564Sab * This function is apparently unused, but lint flags the fact
1571dd08564Sab * that it does not have the same signature as the libc function
1581dd08564Sab * of the same name. So, take it out of view for lint.
1591dd08564Sab */
1601dd08564Sab #if !defined(__lint)
1617c478bd9Sstevel@tonic-gate int
index(int a,CHR * s)1627c478bd9Sstevel@tonic-gate index(int a, CHR *s)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate int k;
1657c478bd9Sstevel@tonic-gate for (k = 0; s[k]; k++)
1667c478bd9Sstevel@tonic-gate if (s[k] == a)
1677c478bd9Sstevel@tonic-gate return (k);
1687c478bd9Sstevel@tonic-gate return (-1);
1697c478bd9Sstevel@tonic-gate }
1701dd08564Sab #endif
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate int
alpha(int c)1737c478bd9Sstevel@tonic-gate alpha(int c)
1747c478bd9Sstevel@tonic-gate {
175*55855f50SToomas Soome return (('a' <= c && c <= 'z') ||
176*55855f50SToomas Soome ('A' <= c && c <= 'Z'));
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate int
printable(int c)1807c478bd9Sstevel@tonic-gate printable(int c)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate return (c > 040 && c < 0177);
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate void
lgate(void)1867c478bd9Sstevel@tonic-gate lgate(void)
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate char fname[20];
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate if (lgatflg)
1917c478bd9Sstevel@tonic-gate return;
1927c478bd9Sstevel@tonic-gate lgatflg = 1;
1937c478bd9Sstevel@tonic-gate if (fout == NULL) {
1947c478bd9Sstevel@tonic-gate (void) sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c');
1957c478bd9Sstevel@tonic-gate fout = fopen(fname, "w");
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate if (fout == NULL)
1987c478bd9Sstevel@tonic-gate error("Can't open %s", fname);
1997c478bd9Sstevel@tonic-gate if (ratfor)
2007c478bd9Sstevel@tonic-gate (void) fprintf(fout, "#\n");
2017c478bd9Sstevel@tonic-gate phead1();
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * scopy(ptr to str, ptr to str) - copy first arg str to second
2067c478bd9Sstevel@tonic-gate * returns ptr to second arg
2077c478bd9Sstevel@tonic-gate */
2087c478bd9Sstevel@tonic-gate void
scopy(CHR * s,CHR * t)2097c478bd9Sstevel@tonic-gate scopy(CHR *s, CHR *t)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate CHR *i;
2127c478bd9Sstevel@tonic-gate i = t;
213*55855f50SToomas Soome while ((*i++ = *s++) != 0)
2141dd08564Sab ;
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate * convert string t, return integer value
2197c478bd9Sstevel@tonic-gate */
2207c478bd9Sstevel@tonic-gate int
siconv(CHR * t)2217c478bd9Sstevel@tonic-gate siconv(CHR *t)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate int i, sw;
2247c478bd9Sstevel@tonic-gate CHR *s;
2257c478bd9Sstevel@tonic-gate s = t;
2267c478bd9Sstevel@tonic-gate while (space(*s))
2277c478bd9Sstevel@tonic-gate s++;
2287c478bd9Sstevel@tonic-gate if (!digit(*s) && *s != '-')
2297c478bd9Sstevel@tonic-gate error("missing translation value");
2307c478bd9Sstevel@tonic-gate sw = 0;
2317c478bd9Sstevel@tonic-gate if (*s == '-') {
2327c478bd9Sstevel@tonic-gate sw = 1;
2337c478bd9Sstevel@tonic-gate s++;
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate if (!digit(*s))
2367c478bd9Sstevel@tonic-gate error("incomplete translation format");
2377c478bd9Sstevel@tonic-gate i = 0;
2387c478bd9Sstevel@tonic-gate while ('0' <= *s && *s <= '9')
2397c478bd9Sstevel@tonic-gate i = i * 10 + (*(s++)-'0');
2407c478bd9Sstevel@tonic-gate return (sw ? -i : i);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate * slength(ptr to str) - return integer length of string arg
2457c478bd9Sstevel@tonic-gate * excludes '\0' terminator
2467c478bd9Sstevel@tonic-gate */
2477c478bd9Sstevel@tonic-gate int
slength(CHR * s)2487c478bd9Sstevel@tonic-gate slength(CHR *s)
2497c478bd9Sstevel@tonic-gate {
2507c478bd9Sstevel@tonic-gate int n;
2517c478bd9Sstevel@tonic-gate CHR *t;
2527c478bd9Sstevel@tonic-gate t = s;
25367298654Sdamico for (n = 0; *t++; n++)
2541dd08564Sab ;
2557c478bd9Sstevel@tonic-gate return (n);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate * scomp(x,y) - return -1 if x < y,
2607c478bd9Sstevel@tonic-gate * 0 if x == y,
2617c478bd9Sstevel@tonic-gate * return 1 if x > y, all lexicographically
2627c478bd9Sstevel@tonic-gate */
2637c478bd9Sstevel@tonic-gate int
scomp(CHR * x,CHR * y)2647c478bd9Sstevel@tonic-gate scomp(CHR *x, CHR *y)
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate CHR *a, *d;
2677c478bd9Sstevel@tonic-gate a = (CHR *) x;
2687c478bd9Sstevel@tonic-gate d = (CHR *) y;
2697c478bd9Sstevel@tonic-gate while (*a || *d) {
2707c478bd9Sstevel@tonic-gate if (*a > *d)
2717c478bd9Sstevel@tonic-gate return (1);
2727c478bd9Sstevel@tonic-gate if (*a < *d)
2737c478bd9Sstevel@tonic-gate return (-1);
2747c478bd9Sstevel@tonic-gate a++;
2757c478bd9Sstevel@tonic-gate d++;
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate return (0);
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate int
ctrans(CHR ** ss)2817c478bd9Sstevel@tonic-gate ctrans(CHR **ss)
2827c478bd9Sstevel@tonic-gate {
2837c478bd9Sstevel@tonic-gate int c, k;
2847c478bd9Sstevel@tonic-gate if ((c = **ss) != '\\')
2857c478bd9Sstevel@tonic-gate return (c);
2867c478bd9Sstevel@tonic-gate switch (c = *++*ss) {
2877c478bd9Sstevel@tonic-gate case 'a':
2887c478bd9Sstevel@tonic-gate c = '\a';
2897c478bd9Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character");
2907c478bd9Sstevel@tonic-gate break;
2917c478bd9Sstevel@tonic-gate case 'v': c = '\v'; break;
2927c478bd9Sstevel@tonic-gate case 'n': c = '\n'; break;
2937c478bd9Sstevel@tonic-gate case 't': c = '\t'; break;
2947c478bd9Sstevel@tonic-gate case 'r': c = '\r'; break;
2957c478bd9Sstevel@tonic-gate case 'b': c = '\b'; break;
2967c478bd9Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */
2977c478bd9Sstevel@tonic-gate case '\\': c = '\\'; break;
2987c478bd9Sstevel@tonic-gate case 'x': {
2997c478bd9Sstevel@tonic-gate int dd;
3007c478bd9Sstevel@tonic-gate warning("\\x is ANSI C hex escape");
3017c478bd9Sstevel@tonic-gate if (digit((dd = *++*ss)) ||
30267298654Sdamico ('a' <= dd && dd <= 'f') ||
30367298654Sdamico ('A' <= dd && dd <= 'F')) {
3047c478bd9Sstevel@tonic-gate c = 0;
3057c478bd9Sstevel@tonic-gate while (digit(dd) ||
30667298654Sdamico ('A' <= dd && dd <= 'F') ||
30767298654Sdamico ('a' <= dd && dd <= 'f')) {
3087c478bd9Sstevel@tonic-gate if (digit(dd))
3097c478bd9Sstevel@tonic-gate c = c*16 + dd - '0';
3107c478bd9Sstevel@tonic-gate else if (dd >= 'a')
3117c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'a';
3127c478bd9Sstevel@tonic-gate else
3137c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'A';
3147c478bd9Sstevel@tonic-gate dd = *++*ss;
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate } else
3177c478bd9Sstevel@tonic-gate c = 'x';
3187c478bd9Sstevel@tonic-gate break;
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3':
3217c478bd9Sstevel@tonic-gate case '4': case '5': case '6': case '7':
3227c478bd9Sstevel@tonic-gate c -= '0';
3237c478bd9Sstevel@tonic-gate while ((k = *(*ss+1)) >= '0' && k <= '7') {
3247c478bd9Sstevel@tonic-gate c = c*8 + k - '0';
3257c478bd9Sstevel@tonic-gate (*ss)++;
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate break;
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate return (c);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate void
cclinter(int sw)3337c478bd9Sstevel@tonic-gate cclinter(int sw)
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate /* sw = 1 ==> ccl */
3367c478bd9Sstevel@tonic-gate int i, j, k;
3377c478bd9Sstevel@tonic-gate int m;
3387c478bd9Sstevel@tonic-gate if (!sw) { /* is NCCL */
3397c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++)
3407c478bd9Sstevel@tonic-gate symbol[i] ^= 1; /* reverse value */
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++)
3437c478bd9Sstevel@tonic-gate if (symbol[i])
3447c478bd9Sstevel@tonic-gate break;
3457c478bd9Sstevel@tonic-gate if (i >= ncg)
3467c478bd9Sstevel@tonic-gate return;
3477c478bd9Sstevel@tonic-gate i = cindex[i];
3487c478bd9Sstevel@tonic-gate /* see if ccl is already in our table */
3497c478bd9Sstevel@tonic-gate j = 0;
3507c478bd9Sstevel@tonic-gate if (i) {
3517c478bd9Sstevel@tonic-gate for (j = 1; j < ncg; j++) {
3527c478bd9Sstevel@tonic-gate if ((symbol[j] && cindex[j] != i) ||
35367298654Sdamico (!symbol[j] && cindex[j] == i))
3547c478bd9Sstevel@tonic-gate break;
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate if (j >= ncg)
3587c478bd9Sstevel@tonic-gate return; /* already in */
3597c478bd9Sstevel@tonic-gate m = 0;
3607c478bd9Sstevel@tonic-gate k = 0;
3617c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++) {
3627c478bd9Sstevel@tonic-gate if (symbol[i]) {
3637c478bd9Sstevel@tonic-gate if (!cindex[i]) {
3647c478bd9Sstevel@tonic-gate cindex[i] = ccount;
3657c478bd9Sstevel@tonic-gate symbol[i] = 0;
3667c478bd9Sstevel@tonic-gate m = 1;
3677c478bd9Sstevel@tonic-gate } else
3687c478bd9Sstevel@tonic-gate k = 1;
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate /* m == 1 implies last value of ccount has been used */
3727c478bd9Sstevel@tonic-gate if (m)
3737c478bd9Sstevel@tonic-gate ccount++;
3747c478bd9Sstevel@tonic-gate if (k == 0)
3757c478bd9Sstevel@tonic-gate return; /* is now in as ccount wholly */
3767c478bd9Sstevel@tonic-gate /* intersection must be computed */
3777c478bd9Sstevel@tonic-gate for (i = 1; i < ncg; i++) {
3787c478bd9Sstevel@tonic-gate if (symbol[i]) {
3797c478bd9Sstevel@tonic-gate m = 0;
3807c478bd9Sstevel@tonic-gate j = cindex[i]; /* will be non-zero */
3817c478bd9Sstevel@tonic-gate for (k = 1; k < ncg; k++) {
3827c478bd9Sstevel@tonic-gate if (cindex[k] == j) {
3837c478bd9Sstevel@tonic-gate if (symbol[k])
3847c478bd9Sstevel@tonic-gate symbol[k] = 0;
3857c478bd9Sstevel@tonic-gate else {
3867c478bd9Sstevel@tonic-gate cindex[k] = ccount;
3877c478bd9Sstevel@tonic-gate m = 1;
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate if (m)
3927c478bd9Sstevel@tonic-gate ccount++;
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate int
usescape(int c)3987c478bd9Sstevel@tonic-gate usescape(int c)
3997c478bd9Sstevel@tonic-gate {
4007c478bd9Sstevel@tonic-gate char d;
4017c478bd9Sstevel@tonic-gate switch (c) {
4027c478bd9Sstevel@tonic-gate case 'a':
4037c478bd9Sstevel@tonic-gate c = '\a';
4047c478bd9Sstevel@tonic-gate warning("\\a is ANSI C \"alert\" character"); break;
4057c478bd9Sstevel@tonic-gate case 'v': c = '\v'; break;
4067c478bd9Sstevel@tonic-gate case 'n': c = '\n'; break;
4077c478bd9Sstevel@tonic-gate case 'r': c = '\r'; break;
4087c478bd9Sstevel@tonic-gate case 't': c = '\t'; break;
4097c478bd9Sstevel@tonic-gate case 'b': c = '\b'; break;
4107c478bd9Sstevel@tonic-gate case 'f': c = 014; break; /* form feed for ascii */
4117c478bd9Sstevel@tonic-gate case 'x': {
4127c478bd9Sstevel@tonic-gate int dd;
4137c478bd9Sstevel@tonic-gate if (digit((dd = gch())) ||
41467298654Sdamico ('A' <= dd && dd <= 'F') ||
41567298654Sdamico ('a' <= dd && dd <= 'f')) {
4167c478bd9Sstevel@tonic-gate c = 0;
4177c478bd9Sstevel@tonic-gate while (digit(dd) ||
41867298654Sdamico ('A' <= dd && dd <= 'F') ||
41967298654Sdamico ('a' <= dd && dd <= 'f')) {
4207c478bd9Sstevel@tonic-gate if (digit(dd))
4217c478bd9Sstevel@tonic-gate c = c*16 + dd - '0';
4227c478bd9Sstevel@tonic-gate else if (dd >= 'a')
4237c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'a';
4247c478bd9Sstevel@tonic-gate else
4257c478bd9Sstevel@tonic-gate c = c*16 + 10 + dd - 'A';
4267c478bd9Sstevel@tonic-gate if (!digit(peek) &&
42767298654Sdamico !('A' <= peek && peek <= 'F') &&
42867298654Sdamico !('a' <= peek && peek <= 'f'))
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate dd = gch();
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate } else
4347c478bd9Sstevel@tonic-gate c = 'x';
4357c478bd9Sstevel@tonic-gate break;
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3':
4387c478bd9Sstevel@tonic-gate case '4': case '5': case '6': case '7':
4397c478bd9Sstevel@tonic-gate c -= '0';
4407c478bd9Sstevel@tonic-gate while ('0' <= (d = gch()) && d <= '7') {
4417c478bd9Sstevel@tonic-gate c = c * 8 + (d-'0');
4427c478bd9Sstevel@tonic-gate if (!('0' <= peek && peek <= '7')) break;
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate break;
4467c478bd9Sstevel@tonic-gate }
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate if (handleeuc && !isascii(c)) {
4497c478bd9Sstevel@tonic-gate char tmpchar = c & 0x00ff;
4501dd08564Sab (void) mbtowc((wchar_t *)&c, &tmpchar, sizeof (tmpchar));
4517c478bd9Sstevel@tonic-gate }
4527c478bd9Sstevel@tonic-gate return (c);
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate int
lookup(CHR * s,CHR ** t)4567c478bd9Sstevel@tonic-gate lookup(CHR *s, CHR **t)
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate int i;
4597c478bd9Sstevel@tonic-gate i = 0;
4607c478bd9Sstevel@tonic-gate while (*t) {
4617c478bd9Sstevel@tonic-gate if (scomp(s, *t) == 0)
4627c478bd9Sstevel@tonic-gate return (i);
4637c478bd9Sstevel@tonic-gate i++;
4647c478bd9Sstevel@tonic-gate t++;
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate return (-1);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate void
cpycom(CHR * p)4707c478bd9Sstevel@tonic-gate cpycom(CHR *p)
4717c478bd9Sstevel@tonic-gate {
4727c478bd9Sstevel@tonic-gate static CHR *t;
4737c478bd9Sstevel@tonic-gate static int c;
4747c478bd9Sstevel@tonic-gate t = p;
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate if (sargv[optind] == NULL)
4777c478bd9Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline);
4787c478bd9Sstevel@tonic-gate else
4797c478bd9Sstevel@tonic-gate (void) fprintf(fout,
48067298654Sdamico "\n# line %d \"%s\"\n", yyline, sargv[optind]);
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4837c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4847c478bd9Sstevel@tonic-gate while (*t) {
4857c478bd9Sstevel@tonic-gate while (*t == '*') {
4867c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4877c478bd9Sstevel@tonic-gate if (*t == '/')
4887c478bd9Sstevel@tonic-gate goto backcall;
4897c478bd9Sstevel@tonic-gate }
4907c478bd9Sstevel@tonic-gate /*
4917c478bd9Sstevel@tonic-gate * FIX BUG #1058428, not parsing comments correctly
4927c478bd9Sstevel@tonic-gate * that span more than one line
4937c478bd9Sstevel@tonic-gate */
494e207f0deSToomas Soome if (*t != 0)
4957c478bd9Sstevel@tonic-gate (void) putc(*t++, fout);
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
498*55855f50SToomas Soome while ((c = gch()) != 0) {
4997c478bd9Sstevel@tonic-gate while (c == '*') {
5007c478bd9Sstevel@tonic-gate (void) putc((char)c, fout);
5017c478bd9Sstevel@tonic-gate if ((c = gch()) == '/') {
50267298654Sdamico while ((c = gch()) == ' ' || c == '\t')
5031dd08564Sab ;
5047c478bd9Sstevel@tonic-gate if (!space(c))
5057c478bd9Sstevel@tonic-gate error("unacceptable statement");
5067c478bd9Sstevel@tonic-gate prev = '\n';
5077c478bd9Sstevel@tonic-gate goto backcall;
5087c478bd9Sstevel@tonic-gate }
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate (void) putc((char)c, fout);
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate error("unexpected EOF inside comment");
5137c478bd9Sstevel@tonic-gate backcall:
5147c478bd9Sstevel@tonic-gate (void) putc('/', fout);
5157c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate /*
5197c478bd9Sstevel@tonic-gate * copy C action to the next ; or closing
5207c478bd9Sstevel@tonic-gate */
5217c478bd9Sstevel@tonic-gate int
cpyact(void)5227c478bd9Sstevel@tonic-gate cpyact(void)
5237c478bd9Sstevel@tonic-gate {
5247c478bd9Sstevel@tonic-gate int brac, c, mth;
5257c478bd9Sstevel@tonic-gate static int sw, savline;
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate brac = 0;
5287c478bd9Sstevel@tonic-gate sw = TRUE;
5297c478bd9Sstevel@tonic-gate savline = yyline;
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate if (sargv[optind] == NULL)
5327c478bd9Sstevel@tonic-gate (void) fprintf(fout, "\n# line %d\n", yyline);
5337c478bd9Sstevel@tonic-gate else
5347c478bd9Sstevel@tonic-gate (void) fprintf(fout,
53567298654Sdamico "\n# line %d \"%s\"\n", yyline, sargv[optind]);
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate while (!eof) {
5387c478bd9Sstevel@tonic-gate c = gch();
5397c478bd9Sstevel@tonic-gate swt:
5407c478bd9Sstevel@tonic-gate switch (c) {
5417c478bd9Sstevel@tonic-gate case '|':
5427c478bd9Sstevel@tonic-gate if (brac == 0 && sw == TRUE) {
5437c478bd9Sstevel@tonic-gate if (peek == '|')
5447c478bd9Sstevel@tonic-gate (void) gch(); /* eat up an extra '|' */
5457c478bd9Sstevel@tonic-gate return (0);
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate break;
5487c478bd9Sstevel@tonic-gate case ';':
5497c478bd9Sstevel@tonic-gate if (brac == 0) {
5507c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5517c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
5527c478bd9Sstevel@tonic-gate return (1);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate break;
5557c478bd9Sstevel@tonic-gate case '{':
5567c478bd9Sstevel@tonic-gate brac++;
5577c478bd9Sstevel@tonic-gate savline = yyline;
5587c478bd9Sstevel@tonic-gate break;
5597c478bd9Sstevel@tonic-gate case '}':
5607c478bd9Sstevel@tonic-gate brac--;
5617c478bd9Sstevel@tonic-gate if (brac == 0) {
5627c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5637c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
5647c478bd9Sstevel@tonic-gate return (1);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate break;
5677c478bd9Sstevel@tonic-gate case '/':
5687c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5697c478bd9Sstevel@tonic-gate c = gch();
5707c478bd9Sstevel@tonic-gate if (c != '*')
5717c478bd9Sstevel@tonic-gate goto swt;
5727c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5737c478bd9Sstevel@tonic-gate savline = yyline;
574*55855f50SToomas Soome while ((c = gch()) != 0) {
5757c478bd9Sstevel@tonic-gate while (c == '*') {
5767c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5777c478bd9Sstevel@tonic-gate if ((c = gch()) == '/') {
5787c478bd9Sstevel@tonic-gate (void) putc('/', fout);
5797c478bd9Sstevel@tonic-gate while ((c = gch()) == ' ' ||
58067298654Sdamico c == '\t' || c == '\n')
5817c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5827c478bd9Sstevel@tonic-gate goto swt;
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate (void) putc((char)c, fout);
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate yyline = savline;
5887c478bd9Sstevel@tonic-gate error("EOF inside comment");
5897c478bd9Sstevel@tonic-gate /* NOTREACHED */
5907c478bd9Sstevel@tonic-gate break;
5917c478bd9Sstevel@tonic-gate case '\'': /* character constant */
5927c478bd9Sstevel@tonic-gate case '"': /* character string */
5937c478bd9Sstevel@tonic-gate mth = c;
5947c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
595*55855f50SToomas Soome while ((c = gch()) != 0) {
5967c478bd9Sstevel@tonic-gate if (c == '\\') {
5977c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
5987c478bd9Sstevel@tonic-gate c = gch();
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate else
6017c478bd9Sstevel@tonic-gate if (c == mth)
6027c478bd9Sstevel@tonic-gate goto loop;
6037c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
6047c478bd9Sstevel@tonic-gate if (c == '\n') {
6057c478bd9Sstevel@tonic-gate yyline--;
6067c478bd9Sstevel@tonic-gate error(
6077c478bd9Sstevel@tonic-gate "Non-terminated string or character constant");
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate error("EOF in string or character constant");
6117c478bd9Sstevel@tonic-gate /* NOTREACHED */
6127c478bd9Sstevel@tonic-gate break;
6137c478bd9Sstevel@tonic-gate case '\0':
6147c478bd9Sstevel@tonic-gate yyline = savline;
6157c478bd9Sstevel@tonic-gate error("Action does not terminate");
6167c478bd9Sstevel@tonic-gate /* NOTREACHED */
6177c478bd9Sstevel@tonic-gate break;
6187c478bd9Sstevel@tonic-gate default:
6197c478bd9Sstevel@tonic-gate break; /* usual character */
6207c478bd9Sstevel@tonic-gate }
6217c478bd9Sstevel@tonic-gate loop:
6227c478bd9Sstevel@tonic-gate if (c != ' ' && c != '\t' && c != '\n')
6237c478bd9Sstevel@tonic-gate sw = FALSE;
6247c478bd9Sstevel@tonic-gate (void) putwc(c, fout);
6257c478bd9Sstevel@tonic-gate if (peek == '\n' && !brac && copy_line) {
6267c478bd9Sstevel@tonic-gate (void) putc('\n', fout);
6277c478bd9Sstevel@tonic-gate return (1);
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate error("Premature EOF");
6317c478bd9Sstevel@tonic-gate return (0);
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate int
gch(void)6357c478bd9Sstevel@tonic-gate gch(void)
6367c478bd9Sstevel@tonic-gate {
6377c478bd9Sstevel@tonic-gate int c;
6387c478bd9Sstevel@tonic-gate prev = pres;
6397c478bd9Sstevel@tonic-gate c = pres = peek;
6407c478bd9Sstevel@tonic-gate peek = pushptr > pushc ? *--pushptr : getwc(fin);
6417c478bd9Sstevel@tonic-gate while (peek == EOF) {
6427c478bd9Sstevel@tonic-gate if (no_input) {
6437c478bd9Sstevel@tonic-gate if (!yyline)
6447c478bd9Sstevel@tonic-gate error("Cannot read from -- %s",
64567298654Sdamico sargv[optind]);
6467c478bd9Sstevel@tonic-gate if (optind < sargc-1) {
6477c478bd9Sstevel@tonic-gate yyline = 0;
6487c478bd9Sstevel@tonic-gate if (fin != stdin)
6497c478bd9Sstevel@tonic-gate (void) fclose(fin);
6507c478bd9Sstevel@tonic-gate fin = fopen(sargv[++optind], "r");
6517c478bd9Sstevel@tonic-gate if (fin == NULL)
6527c478bd9Sstevel@tonic-gate error("Cannot open file -- %s",
65367298654Sdamico sargv[optind]);
6547c478bd9Sstevel@tonic-gate peek = getwc(fin);
6557c478bd9Sstevel@tonic-gate } else
6567c478bd9Sstevel@tonic-gate break;
6577c478bd9Sstevel@tonic-gate } else {
6587c478bd9Sstevel@tonic-gate if (fin != stdin)
6597c478bd9Sstevel@tonic-gate (void) fclose(fin);
6607c478bd9Sstevel@tonic-gate if (!yyline)
6617c478bd9Sstevel@tonic-gate error("Cannot read from -- standard input");
6627c478bd9Sstevel@tonic-gate else
6637c478bd9Sstevel@tonic-gate break;
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate if (c == EOF) {
6677c478bd9Sstevel@tonic-gate eof = TRUE;
6687c478bd9Sstevel@tonic-gate return (0);
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate if (c == '\n')
6717c478bd9Sstevel@tonic-gate yyline++;
6727c478bd9Sstevel@tonic-gate return (c);
6737c478bd9Sstevel@tonic-gate }
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate int
mn2(int a,int d,int c)6767c478bd9Sstevel@tonic-gate mn2(int a, int d, int c)
6777c478bd9Sstevel@tonic-gate {
6787c478bd9Sstevel@tonic-gate if (tptr >= treesize) {
6797c478bd9Sstevel@tonic-gate tptr++;
6807c478bd9Sstevel@tonic-gate error("Parse tree too big %s",
68167298654Sdamico (treesize == TREESIZE ? "\nTry using %e num" : ""));
6827c478bd9Sstevel@tonic-gate }
6837c478bd9Sstevel@tonic-gate if (d >= treesize) {
6847c478bd9Sstevel@tonic-gate error("Parse error");
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate name[tptr] = a;
6877c478bd9Sstevel@tonic-gate left[tptr] = d;
6887c478bd9Sstevel@tonic-gate right[tptr] = c;
6897c478bd9Sstevel@tonic-gate parent[tptr] = 0;
6907c478bd9Sstevel@tonic-gate nullstr[tptr] = 0;
6917c478bd9Sstevel@tonic-gate switch (a) {
6927c478bd9Sstevel@tonic-gate case RSTR:
6937c478bd9Sstevel@tonic-gate parent[d] = tptr;
6947c478bd9Sstevel@tonic-gate break;
6957c478bd9Sstevel@tonic-gate case BAR:
6967c478bd9Sstevel@tonic-gate case RNEWE:
6977c478bd9Sstevel@tonic-gate if (nullstr[d] || nullstr[c])
6987c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
6997c478bd9Sstevel@tonic-gate parent[d] = parent[c] = tptr;
7007c478bd9Sstevel@tonic-gate break;
7017c478bd9Sstevel@tonic-gate case RCAT:
7027c478bd9Sstevel@tonic-gate case DIV:
7037c478bd9Sstevel@tonic-gate if (nullstr[d] && nullstr[c])
7047c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7057c478bd9Sstevel@tonic-gate parent[d] = parent[c] = tptr;
7067c478bd9Sstevel@tonic-gate break;
7077c478bd9Sstevel@tonic-gate /* XCU4: add RXSCON */
7087c478bd9Sstevel@tonic-gate case RXSCON:
7097c478bd9Sstevel@tonic-gate case RSCON:
7107c478bd9Sstevel@tonic-gate parent[d] = tptr;
7117c478bd9Sstevel@tonic-gate nullstr[tptr] = nullstr[d];
7127c478bd9Sstevel@tonic-gate break;
7137c478bd9Sstevel@tonic-gate #ifdef DEBUG
7147c478bd9Sstevel@tonic-gate default:
7157c478bd9Sstevel@tonic-gate warning("bad switch mn2 %d %d", a, d);
7167c478bd9Sstevel@tonic-gate break;
7177c478bd9Sstevel@tonic-gate #endif
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate return (tptr++);
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate int
mn1(int a,int d)7237c478bd9Sstevel@tonic-gate mn1(int a, int d)
7247c478bd9Sstevel@tonic-gate {
7257c478bd9Sstevel@tonic-gate if (tptr >= treesize) {
7267c478bd9Sstevel@tonic-gate tptr++;
7277c478bd9Sstevel@tonic-gate error("Parse tree too big %s",
72867298654Sdamico (treesize == TREESIZE ? "\nTry using %e num" : ""));
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate name[tptr] = a;
7317c478bd9Sstevel@tonic-gate left[tptr] = d;
7327c478bd9Sstevel@tonic-gate parent[tptr] = 0;
7337c478bd9Sstevel@tonic-gate nullstr[tptr] = 0;
7347c478bd9Sstevel@tonic-gate switch (a) {
7357c478bd9Sstevel@tonic-gate case RCCL:
7367c478bd9Sstevel@tonic-gate case RNCCL:
7377c478bd9Sstevel@tonic-gate if (slength((CHR *)d) == 0)
7387c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7397c478bd9Sstevel@tonic-gate break;
7407c478bd9Sstevel@tonic-gate case STAR:
7417c478bd9Sstevel@tonic-gate case QUEST:
7427c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7437c478bd9Sstevel@tonic-gate parent[d] = tptr;
7447c478bd9Sstevel@tonic-gate break;
7457c478bd9Sstevel@tonic-gate case PLUS:
7467c478bd9Sstevel@tonic-gate case CARAT:
7477c478bd9Sstevel@tonic-gate nullstr[tptr] = nullstr[d];
7487c478bd9Sstevel@tonic-gate parent[d] = tptr;
7497c478bd9Sstevel@tonic-gate break;
7507c478bd9Sstevel@tonic-gate case S2FINAL:
7517c478bd9Sstevel@tonic-gate nullstr[tptr] = TRUE;
7527c478bd9Sstevel@tonic-gate break;
7537c478bd9Sstevel@tonic-gate #ifdef DEBUG
7547c478bd9Sstevel@tonic-gate case FINAL:
7557c478bd9Sstevel@tonic-gate case S1FINAL:
7567c478bd9Sstevel@tonic-gate break;
7577c478bd9Sstevel@tonic-gate default:
7587c478bd9Sstevel@tonic-gate warning("bad switch mn1 %d %d", a, d);
7597c478bd9Sstevel@tonic-gate break;
7607c478bd9Sstevel@tonic-gate #endif
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate return (tptr++);
7637c478bd9Sstevel@tonic-gate }
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate int
mn0(int a)7667c478bd9Sstevel@tonic-gate mn0(int a)
7677c478bd9Sstevel@tonic-gate {
7687c478bd9Sstevel@tonic-gate if (tptr >= treesize) {
7697c478bd9Sstevel@tonic-gate tptr++;
7707c478bd9Sstevel@tonic-gate error("Parse tree too big %s",
77167298654Sdamico (treesize == TREESIZE ? "\nTry using %e num" : ""));
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate
7747c478bd9Sstevel@tonic-gate name[tptr] = a;
7757c478bd9Sstevel@tonic-gate parent[tptr] = 0;
7767c478bd9Sstevel@tonic-gate nullstr[tptr] = 0;
7777c478bd9Sstevel@tonic-gate if (ISOPERATOR(a)) {
7787c478bd9Sstevel@tonic-gate switch (a) {
7797c478bd9Sstevel@tonic-gate case DOT: break;
7807c478bd9Sstevel@tonic-gate case RNULLS: nullstr[tptr] = TRUE; break;
7817c478bd9Sstevel@tonic-gate #ifdef DEBUG
7827c478bd9Sstevel@tonic-gate default:
7837c478bd9Sstevel@tonic-gate warning("bad switch mn0 %d", a);
7847c478bd9Sstevel@tonic-gate break;
7857c478bd9Sstevel@tonic-gate #endif
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate }
7887c478bd9Sstevel@tonic-gate return (tptr++);
7897c478bd9Sstevel@tonic-gate }
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate void
munput(int t,CHR * p)7927c478bd9Sstevel@tonic-gate munput(int t, CHR *p)
7937c478bd9Sstevel@tonic-gate {
7947c478bd9Sstevel@tonic-gate int i, j;
7957c478bd9Sstevel@tonic-gate if (t == 'c') {
7967c478bd9Sstevel@tonic-gate *pushptr++ = peek;
7977c478bd9Sstevel@tonic-gate peek = *p;
7987c478bd9Sstevel@tonic-gate } else if (t == 's') {
7997c478bd9Sstevel@tonic-gate *pushptr++ = peek;
8007c478bd9Sstevel@tonic-gate peek = p[0];
8017c478bd9Sstevel@tonic-gate i = slength(p);
8027c478bd9Sstevel@tonic-gate for (j = i - 1; j >= 1; j--)
8037c478bd9Sstevel@tonic-gate *pushptr++ = p[j];
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate if (pushptr >= pushc + TOKENSIZE)
8067c478bd9Sstevel@tonic-gate error("Too many characters pushed");
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate int
dupl(int n)8107c478bd9Sstevel@tonic-gate dupl(int n)
8117c478bd9Sstevel@tonic-gate {
8127c478bd9Sstevel@tonic-gate /* duplicate the subtree whose root is n, return ptr to it */
8137c478bd9Sstevel@tonic-gate int i;
8147c478bd9Sstevel@tonic-gate i = name[n];
8157c478bd9Sstevel@tonic-gate if (!ISOPERATOR(i))
8167c478bd9Sstevel@tonic-gate return (mn0(i));
8177c478bd9Sstevel@tonic-gate switch (i) {
8187c478bd9Sstevel@tonic-gate case DOT:
8197c478bd9Sstevel@tonic-gate case RNULLS:
8207c478bd9Sstevel@tonic-gate return (mn0(i));
8217c478bd9Sstevel@tonic-gate case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL:
8227c478bd9Sstevel@tonic-gate return (mn1(i, left[n]));
8237c478bd9Sstevel@tonic-gate case STAR: case QUEST: case PLUS: case CARAT:
8247c478bd9Sstevel@tonic-gate return (mn1(i, dupl(left[n])));
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate /* XCU4: add RXSCON */
8277c478bd9Sstevel@tonic-gate case RSTR: case RSCON: case RXSCON:
8287c478bd9Sstevel@tonic-gate return (mn2(i, dupl(left[n]), right[n]));
8297c478bd9Sstevel@tonic-gate case BAR: case RNEWE: case RCAT: case DIV:
8307c478bd9Sstevel@tonic-gate return (mn2(i, dupl(left[n]), dupl(right[n])));
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate return (0);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate
8357c478bd9Sstevel@tonic-gate #ifdef DEBUG
8367c478bd9Sstevel@tonic-gate void
allprint(CHR c)8377c478bd9Sstevel@tonic-gate allprint(CHR c)
8387c478bd9Sstevel@tonic-gate {
8397c478bd9Sstevel@tonic-gate switch (c) {
8407c478bd9Sstevel@tonic-gate case 014:
8417c478bd9Sstevel@tonic-gate (void) printf("\\f");
8427c478bd9Sstevel@tonic-gate charc++;
8437c478bd9Sstevel@tonic-gate break;
8447c478bd9Sstevel@tonic-gate case '\n':
8457c478bd9Sstevel@tonic-gate (void) printf("\\n");
8467c478bd9Sstevel@tonic-gate charc++;
8477c478bd9Sstevel@tonic-gate break;
8487c478bd9Sstevel@tonic-gate case '\t':
8497c478bd9Sstevel@tonic-gate (void) printf("\\t");
8507c478bd9Sstevel@tonic-gate charc++;
8517c478bd9Sstevel@tonic-gate break;
8527c478bd9Sstevel@tonic-gate case '\b':
8537c478bd9Sstevel@tonic-gate (void) printf("\\b");
8547c478bd9Sstevel@tonic-gate charc++;
8557c478bd9Sstevel@tonic-gate break;
8567c478bd9Sstevel@tonic-gate case ' ':
8577c478bd9Sstevel@tonic-gate (void) printf("\\_");
8587c478bd9Sstevel@tonic-gate break;
8597c478bd9Sstevel@tonic-gate default:
8607c478bd9Sstevel@tonic-gate if (!iswprint(c)) {
8617c478bd9Sstevel@tonic-gate printf("\\x%-2x", c); /* up to fashion. */
8627c478bd9Sstevel@tonic-gate charc += 3;
8637c478bd9Sstevel@tonic-gate } else
8647c478bd9Sstevel@tonic-gate (void) putwc(c, stdout);
8657c478bd9Sstevel@tonic-gate break;
8667c478bd9Sstevel@tonic-gate }
8677c478bd9Sstevel@tonic-gate charc++;
8687c478bd9Sstevel@tonic-gate }
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate void
strpt(CHR * s)8717c478bd9Sstevel@tonic-gate strpt(CHR *s)
8727c478bd9Sstevel@tonic-gate {
8737c478bd9Sstevel@tonic-gate charc = 0;
8747c478bd9Sstevel@tonic-gate while (*s) {
8757c478bd9Sstevel@tonic-gate allprint(*s++);
8767c478bd9Sstevel@tonic-gate if (charc > LINESIZE) {
8777c478bd9Sstevel@tonic-gate charc = 0;
8787c478bd9Sstevel@tonic-gate (void) printf("\n\t");
8797c478bd9Sstevel@tonic-gate }
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate void
sect1dump(void)8847c478bd9Sstevel@tonic-gate sect1dump(void)
8857c478bd9Sstevel@tonic-gate {
8867c478bd9Sstevel@tonic-gate int i;
8877c478bd9Sstevel@tonic-gate (void) printf("Sect 1:\n");
8887c478bd9Sstevel@tonic-gate if (def[0]) {
8897c478bd9Sstevel@tonic-gate (void) printf("str trans\n");
8907c478bd9Sstevel@tonic-gate i = -1;
8917c478bd9Sstevel@tonic-gate while (def[++i])
8927c478bd9Sstevel@tonic-gate (void) printf("%ws\t%ws\n", def[i], subs[i]);
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate if (sname[0]) {
8957c478bd9Sstevel@tonic-gate (void) printf("start names\n");
8967c478bd9Sstevel@tonic-gate i = -1;
8977c478bd9Sstevel@tonic-gate while (sname[++i])
8987c478bd9Sstevel@tonic-gate (void) printf("%ws\n", sname[i]);
8997c478bd9Sstevel@tonic-gate }
9007c478bd9Sstevel@tonic-gate if (chset == TRUE) {
9017c478bd9Sstevel@tonic-gate (void) printf("char set changed\n");
9027c478bd9Sstevel@tonic-gate for (i = 1; i < NCH; i++) {
9037c478bd9Sstevel@tonic-gate if (i != ctable[i]) {
9047c478bd9Sstevel@tonic-gate allprint(i);
9057c478bd9Sstevel@tonic-gate (void) putchar(' ');
9067c478bd9Sstevel@tonic-gate iswprint(ctable[i]) ?
90767298654Sdamico (void) putwc(ctable[i], stdout) :
90867298654Sdamico (void) printf("%d", ctable[i]);
9097c478bd9Sstevel@tonic-gate (void) putchar('\n');
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate }
9137c478bd9Sstevel@tonic-gate }
9147c478bd9Sstevel@tonic-gate
9157c478bd9Sstevel@tonic-gate void
sect2dump(void)9167c478bd9Sstevel@tonic-gate sect2dump(void)
9177c478bd9Sstevel@tonic-gate {
9187c478bd9Sstevel@tonic-gate (void) printf("Sect 2:\n");
9197c478bd9Sstevel@tonic-gate treedump();
9207c478bd9Sstevel@tonic-gate }
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate void
treedump(void)9237c478bd9Sstevel@tonic-gate treedump(void)
9247c478bd9Sstevel@tonic-gate {
9257c478bd9Sstevel@tonic-gate int t;
9267c478bd9Sstevel@tonic-gate CHR *p;
9277c478bd9Sstevel@tonic-gate (void) printf("treedump %d nodes:\n", tptr);
9287c478bd9Sstevel@tonic-gate for (t = 0; t < tptr; t++) {
9297c478bd9Sstevel@tonic-gate (void) printf("%4d ", t);
9307c478bd9Sstevel@tonic-gate parent[t] ? (void) printf("p=%4d", parent[t]) :
93167298654Sdamico (void) printf(" ");
9327c478bd9Sstevel@tonic-gate (void) printf(" ");
9337c478bd9Sstevel@tonic-gate if (!ISOPERATOR(name[t])) {
9347c478bd9Sstevel@tonic-gate allprint(name[t]);
9357c478bd9Sstevel@tonic-gate } else
9367c478bd9Sstevel@tonic-gate switch (name[t]) {
9377c478bd9Sstevel@tonic-gate case RSTR:
9387c478bd9Sstevel@tonic-gate (void) printf("%d ", left[t]);
9397c478bd9Sstevel@tonic-gate allprint(right[t]);
9407c478bd9Sstevel@tonic-gate break;
9417c478bd9Sstevel@tonic-gate case RCCL:
9427c478bd9Sstevel@tonic-gate (void) printf("ccl ");
9437c478bd9Sstevel@tonic-gate strpt(left[t]);
9447c478bd9Sstevel@tonic-gate break;
9457c478bd9Sstevel@tonic-gate case RNCCL:
9467c478bd9Sstevel@tonic-gate (void) printf("nccl ");
9477c478bd9Sstevel@tonic-gate strpt(left[t]);
9487c478bd9Sstevel@tonic-gate break;
9497c478bd9Sstevel@tonic-gate case DIV:
9507c478bd9Sstevel@tonic-gate (void) printf("/ %d %d", left[t], right[t]);
9517c478bd9Sstevel@tonic-gate break;
9527c478bd9Sstevel@tonic-gate case BAR:
9537c478bd9Sstevel@tonic-gate (void) printf("| %d %d", left[t], right[t]);
9547c478bd9Sstevel@tonic-gate break;
9557c478bd9Sstevel@tonic-gate case RCAT:
9567c478bd9Sstevel@tonic-gate (void) printf("cat %d %d", left[t], right[t]);
9577c478bd9Sstevel@tonic-gate break;
9587c478bd9Sstevel@tonic-gate case PLUS:
9597c478bd9Sstevel@tonic-gate (void) printf("+ %d", left[t]);
9607c478bd9Sstevel@tonic-gate break;
9617c478bd9Sstevel@tonic-gate case STAR:
9627c478bd9Sstevel@tonic-gate (void) printf("* %d", left[t]);
9637c478bd9Sstevel@tonic-gate break;
9647c478bd9Sstevel@tonic-gate case CARAT:
9657c478bd9Sstevel@tonic-gate (void) printf("^ %d", left[t]);
9667c478bd9Sstevel@tonic-gate break;
9677c478bd9Sstevel@tonic-gate case QUEST:
9687c478bd9Sstevel@tonic-gate (void) printf("? %d", left[t]);
9697c478bd9Sstevel@tonic-gate break;
9707c478bd9Sstevel@tonic-gate case RNULLS:
9717c478bd9Sstevel@tonic-gate (void) printf("nullstring");
9727c478bd9Sstevel@tonic-gate break;
9737c478bd9Sstevel@tonic-gate case FINAL:
9747c478bd9Sstevel@tonic-gate (void) printf("final %d", left[t]);
9757c478bd9Sstevel@tonic-gate break;
9767c478bd9Sstevel@tonic-gate case S1FINAL:
9777c478bd9Sstevel@tonic-gate (void) printf("s1final %d", left[t]);
9787c478bd9Sstevel@tonic-gate break;
9797c478bd9Sstevel@tonic-gate case S2FINAL:
9807c478bd9Sstevel@tonic-gate (void) printf("s2final %d", left[t]);
9817c478bd9Sstevel@tonic-gate break;
9827c478bd9Sstevel@tonic-gate case RNEWE:
9837c478bd9Sstevel@tonic-gate (void) printf("new %d %d", left[t], right[t]);
9847c478bd9Sstevel@tonic-gate break;
9857c478bd9Sstevel@tonic-gate
9867c478bd9Sstevel@tonic-gate /* XCU4: add RXSCON */
9877c478bd9Sstevel@tonic-gate case RXSCON:
9887c478bd9Sstevel@tonic-gate p = (CHR *)right[t];
9897c478bd9Sstevel@tonic-gate (void) printf("exstart %s", sname[*p++-1]);
9907c478bd9Sstevel@tonic-gate while (*p)
9917c478bd9Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]);
9927c478bd9Sstevel@tonic-gate (void) printf(" %d", left[t]);
9937c478bd9Sstevel@tonic-gate break;
9947c478bd9Sstevel@tonic-gate case RSCON:
9957c478bd9Sstevel@tonic-gate p = (CHR *)right[t];
9967c478bd9Sstevel@tonic-gate (void) printf("start %s", sname[*p++-1]);
9977c478bd9Sstevel@tonic-gate while (*p)
9987c478bd9Sstevel@tonic-gate (void) printf(", %ws", sname[*p++-1]);
9997c478bd9Sstevel@tonic-gate (void) printf(" %d", left[t]);
10007c478bd9Sstevel@tonic-gate break;
10017c478bd9Sstevel@tonic-gate case DOT:
10027c478bd9Sstevel@tonic-gate printf("dot");
10037c478bd9Sstevel@tonic-gate break;
10047c478bd9Sstevel@tonic-gate default:
10057c478bd9Sstevel@tonic-gate (void) printf(
10067c478bd9Sstevel@tonic-gate "unknown %d %d %d", name[t], left[t], right[t]);
10077c478bd9Sstevel@tonic-gate break;
10087c478bd9Sstevel@tonic-gate }
10097c478bd9Sstevel@tonic-gate if (nullstr[t])
10107c478bd9Sstevel@tonic-gate (void) printf("\t(null poss.)");
10117c478bd9Sstevel@tonic-gate (void) putchar('\n');
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate }
10147c478bd9Sstevel@tonic-gate #endif
1015