xref: /csrg-svn/old/lex/sub1.c (revision 32766)
114493Ssam #ifndef lint
2*32766Sbostic static char sccsid[] = "@(#)sub1.c	4.3 (Berkeley) 12/04/87";
314493Ssam #endif
414493Ssam 
514493Ssam # include "ldefs.c"
614493Ssam char *
714493Ssam getl(p)	/* return next line of input, throw away trailing '\n' */
814493Ssam 	/* returns 0 if eof is had immediately */
914493Ssam   char *p;
1014493Ssam 	{
1114493Ssam 	register int c;
1214493Ssam 	register char *s, *t;
1314493Ssam 	t = s = p;
1414493Ssam 	while(((c = gch()) != 0) && c != '\n')
1514493Ssam 		*t++ = c;
1614493Ssam 	*t = 0;
1714493Ssam 	if(c == 0 && s == t) return(0);
1814493Ssam 	prev = '\n';
1914493Ssam 	pres = '\n';
2014493Ssam 	return(s);
2114493Ssam 	}
2214493Ssam space(ch)
2314493Ssam 	{
2414493Ssam 	switch(ch)
2514493Ssam 		{
2614493Ssam 		case ' ':
2714493Ssam 		case '\t':
2814493Ssam 		case '\n':
2914493Ssam 			return(1);
3014493Ssam 		}
3114493Ssam 	return(0);
3214493Ssam 	}
3314493Ssam 
3414493Ssam digit(c)
3514493Ssam {
3614493Ssam 	return(c>='0' && c <= '9');
3714493Ssam }
3814493Ssam error(s,p,d)
3914493Ssam 	{
4018033Sserge 	fprintf(errorf,"\"%s\", line %d: (Error) ",
4118033Sserge 		fptr > 0 ? sargv[fptr] : "<stdin>", yyline);
4214493Ssam 	fprintf(errorf,s,p,d);
4314493Ssam 	putc('\n',errorf);
4414493Ssam # ifdef DEBUG
4514493Ssam 	if(debug && sect != ENDSECTION) {
4614493Ssam 		sect1dump();
4714493Ssam 		sect2dump();
4814493Ssam 	}
4914493Ssam # endif
5014493Ssam 	if(
5114493Ssam # ifdef DEBUG
5214493Ssam 		debug ||
5314493Ssam # endif
5414493Ssam 		report == 1) statistics();
5514493Ssam 	exit(1);	/* error return code */
5614493Ssam 	}
5714493Ssam 
5814493Ssam warning(s,p,d)
5914493Ssam 	{
6018033Sserge 	fprintf(errorf,"\"%s\", line %d: (Warning) ",
6118033Sserge 		fptr > 0 ? sargv[fptr] : "<stdin>", yyline);
6214493Ssam 	fprintf(errorf,s,p,d);
6314493Ssam 	putc('\n',errorf);
6414493Ssam 	fflush(errorf);
6514493Ssam 	fflush(fout);
6614493Ssam 	fflush(stdout);
6714493Ssam 	}
6814493Ssam index(a,s)
6914493Ssam 	char *s;
7014493Ssam {
7114493Ssam 	register int k;
7214493Ssam 	for(k=0; s[k]; k++)
7314493Ssam 		if (s[k]== a)
7414493Ssam 			return(k);
7514493Ssam 	return(-1);
7614493Ssam 	}
7714493Ssam 
7814493Ssam alpha(c)
7914493Ssam   int c; {
8014493Ssam # ifdef ASCII
8114493Ssam return('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z');
8214493Ssam # endif
8314493Ssam # ifdef EBCDIC
8414493Ssam return(index(c,"abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") >= 0);
8514493Ssam # endif
8614493Ssam }
8714493Ssam printable(c)
8814493Ssam {
8914493Ssam # ifdef ASCII
9014493Ssam return( c>040 && c < 0177);
9114493Ssam # endif
9214493Ssam # ifdef EBCDIC
9314493Ssam return(index(c, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;:><+*)('&%!-=\"")>=0);
9414493Ssam # endif
9514493Ssam }
9614493Ssam lgate()
9714493Ssam {
9814493Ssam 	char fname[20];
9914493Ssam 	if (lgatflg) return;
10014493Ssam 	lgatflg=1;
10114493Ssam 	if(fout == NULL){
10214493Ssam 		sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c' );
10314493Ssam 		fout = fopen(fname, "w");
10414493Ssam 		}
10514493Ssam 	if(fout == NULL) error("Can't open %s",fname);
10614493Ssam 	if(ratfor) fprintf( fout, "#\n");
10714493Ssam 	phead1();
10814493Ssam 	}
10914493Ssam /* scopy(ptr to str, ptr to str) - copy first arg str to second */
11014493Ssam /* returns ptr to second arg */
11114493Ssam scopy(s,t)
11214493Ssam   char *s, *t; {
11314493Ssam 	register char *i;
11414493Ssam 	i = t;
11514493Ssam 	while(*i++ = *s++);
11614493Ssam 	return;
11714493Ssam 	}
11814493Ssam siconv(t)	/* convert string t, return integer value */
11914493Ssam   char *t; {
12014493Ssam 	register int i,sw;
12114493Ssam 	register char *s;
12214493Ssam 	s = t;
12314493Ssam 	while(!(('0' <= *s && *s <= '9') || *s == '-') && *s) s++;
12414493Ssam 	sw = 0;
12514493Ssam 	if(*s == '-'){	/* neg */
12614493Ssam 		sw = 1;
12714493Ssam 		s++;
12814493Ssam 		}
12914493Ssam 	i = 0;
13014493Ssam 	while('0' <= *s && *s <= '9')
13114493Ssam 		i = i * 10 + (*(s++)-'0');
13214493Ssam 	return(sw ? -i : i);
13314493Ssam 	}
13414493Ssam /* slength(ptr to str) - return integer length of string arg */
13514493Ssam /* excludes '\0' terminator */
13614493Ssam slength(s)
13714493Ssam   char *s; {
13814493Ssam 	register int n;
13914493Ssam 	register char *t;
14014493Ssam 	t = s;
14114493Ssam 	for (n = 0; *t++; n++);
14214493Ssam 	return(n);
14314493Ssam 	}
14414493Ssam /* scomp(x,y) - return -1 if x < y,
14514493Ssam 		0 if x == y,
14614493Ssam 		return 1 if x > y, all lexicographically */
14714493Ssam scomp(x,y)
14814493Ssam   char *x,*y; {
14914493Ssam 	register char *a,*d;
15014493Ssam 	a = x;
15114493Ssam 	d = y;
15214493Ssam 	while(*a || *d){
15314493Ssam 		if(*a > *d)
15414493Ssam 			return(1);	/* greater */
15514493Ssam 		if(*a < *d)
15614493Ssam 			return(-1);	/* less */
15714493Ssam 		a++;
15814493Ssam 		d++;
15914493Ssam 		}
16014493Ssam 	return(0);	/* equal */
16114493Ssam 	}
16214493Ssam ctrans(ss)
16314493Ssam 	char **ss;
16414493Ssam {
16514493Ssam 	register int c, k;
16614493Ssam 	if ((c = **ss) != '\\')
16714493Ssam 		return(c);
16814493Ssam 	switch(c= *++*ss)
16914493Ssam 	{
17014493Ssam 	case 'n': c = '\n'; break;
17114493Ssam 	case 't': c = '\t'; break;
17214493Ssam 	case 'r': c = '\r'; break;
17314493Ssam 	case 'b': c = '\b'; break;
17414493Ssam 	case 'f': c = 014; break;		/* form feed for ascii */
17514493Ssam 	case '\\': c = '\\'; break;
17614493Ssam 	case '0': case '1': case '2': case '3':
17714493Ssam 	case '4': case '5': case '6': case '7':
17814493Ssam 		c -= '0';
17914493Ssam 		while ((k = *(*ss+1)) >= '0' && k <= '7')
18014493Ssam 			{
18114493Ssam 			c = c*8 + k - '0';
18214493Ssam 			(*ss)++;
18314493Ssam 			}
18414493Ssam 		break;
18514493Ssam 	}
18614493Ssam 	return(c);
18714493Ssam }
18814493Ssam cclinter(sw)
18914493Ssam   int sw; {
19014493Ssam 		/* sw = 1 ==> ccl */
19114493Ssam 	register int i, j, k;
19214493Ssam 	int m;
19314493Ssam 	if(!sw){		/* is NCCL */
19414493Ssam 		for(i=1;i<NCH;i++)
19514493Ssam 			symbol[i] ^= 1;			/* reverse value */
19614493Ssam 		}
19714493Ssam 	for(i=1;i<NCH;i++)
19814493Ssam 		if(symbol[i]) break;
19914493Ssam 	if(i >= NCH) return;
20014493Ssam 	i = cindex[i];
20114493Ssam 	/* see if ccl is already in our table */
20214493Ssam 	j = 0;
20314493Ssam 	if(i){
20414493Ssam 		for(j=1;j<NCH;j++){
20514493Ssam 			if((symbol[j] && cindex[j] != i) ||
20614493Ssam 			   (!symbol[j] && cindex[j] == i)) break;
20714493Ssam 			}
20814493Ssam 		}
20914493Ssam 	if(j >= NCH) return;		/* already in */
21014493Ssam 	m = 0;
21114493Ssam 	k = 0;
21214493Ssam 	for(i=1;i<NCH;i++)
21314493Ssam 		if(symbol[i]){
21414493Ssam 			if(!cindex[i]){
21514493Ssam 				cindex[i] = ccount;
21614493Ssam 				symbol[i] = 0;
21714493Ssam 				m = 1;
21814493Ssam 				}
21914493Ssam 			else k = 1;
22014493Ssam 			}
22114493Ssam 			/* m == 1 implies last value of ccount has been used */
22214493Ssam 	if(m)ccount++;
22314493Ssam 	if(k == 0) return;	/* is now in as ccount wholly */
22414493Ssam 	/* intersection must be computed */
22514493Ssam 	for(i=1;i<NCH;i++){
22614493Ssam 		if(symbol[i]){
22714493Ssam 			m = 0;
22814493Ssam 			j = cindex[i];	/* will be non-zero */
22914493Ssam 			for(k=1;k<NCH;k++){
23014493Ssam 				if(cindex[k] == j){
23114493Ssam 					if(symbol[k]) symbol[k] = 0;
23214493Ssam 					else {
23314493Ssam 						cindex[k] = ccount;
23414493Ssam 						m = 1;
23514493Ssam 						}
23614493Ssam 					}
23714493Ssam 				}
23814493Ssam 			if(m)ccount++;
23914493Ssam 			}
24014493Ssam 		}
24114493Ssam 	return;
24214493Ssam 	}
24314493Ssam usescape(c)
24414493Ssam   int c; {
24514493Ssam 	register char d;
24614493Ssam 	switch(c){
24714493Ssam 	case 'n': c = '\n'; break;
24814493Ssam 	case 'r': c = '\r'; break;
24914493Ssam 	case 't': c = '\t'; break;
25014493Ssam 	case 'b': c = '\b'; break;
25114493Ssam 	case 'f': c = 014; break;		/* form feed for ascii */
25214493Ssam 	case '0': case '1': case '2': case '3':
25314493Ssam 	case '4': case '5': case '6': case '7':
25414493Ssam 		c -= '0';
25514493Ssam 		while('0' <= (d=gch()) && d <= '7'){
25614493Ssam 			c = c * 8 + (d-'0');
25714493Ssam 			if(!('0' <= peek && peek <= '7')) break;
25814493Ssam 			}
25914493Ssam 		break;
26014493Ssam 	}
26114493Ssam 	return(c);
26214493Ssam 	}
26314493Ssam lookup(s,t)
26414493Ssam   char *s;
26514493Ssam   char **t; {
26614493Ssam 	register int i;
26714493Ssam 	i = 0;
26814493Ssam 	while(*t){
26914493Ssam 		if(scomp(s,*t) == 0)
27014493Ssam 			return(i);
27114493Ssam 		i++;
27214493Ssam 		t++;
27314493Ssam 		}
27414493Ssam 	return(-1);
27514493Ssam 	}
27614493Ssam cpyact(){ /* copy C action to the next ; or closing } */
27714493Ssam 	register int brac, c, mth;
27814493Ssam 	int savline, sw;
27914493Ssam 
28014493Ssam 	brac = 0;
28114493Ssam 	sw = TRUE;
28214493Ssam 
28314493Ssam while(!eof){
28414493Ssam 	c = gch();
28514493Ssam swt:
28614493Ssam 	switch( c ){
28714493Ssam 
28814493Ssam case '|':	if(brac == 0 && sw == TRUE){
28914493Ssam 			if(peek == '|')gch();		/* eat up an extra '|' */
29014493Ssam 			return(0);
29114493Ssam 			}
29214493Ssam 		break;
29314493Ssam 
29414493Ssam case ';':
29514493Ssam 		if( brac == 0 ){
29614493Ssam 			putc(c,fout);
29714493Ssam 			putc('\n',fout);
29814493Ssam 			return(1);
29914493Ssam 			}
30014493Ssam 		break;
30114493Ssam 
30214493Ssam case '{':
30314493Ssam 		brac++;
30414493Ssam 		savline=yyline;
30514493Ssam 		break;
30614493Ssam 
30714493Ssam case '}':
30814493Ssam 		brac--;
30914493Ssam 		if( brac == 0 ){
31014493Ssam 			putc(c,fout);
31114493Ssam 			putc('\n',fout);
31214493Ssam 			return(1);
31314493Ssam 			}
31414493Ssam 		break;
31514493Ssam 
31614493Ssam case '/':	/* look for comments */
31714493Ssam 		putc(c,fout);
31814493Ssam 		c = gch();
31914493Ssam 		if( c != '*' ) goto swt;
32014493Ssam 
32114493Ssam 		/* it really is a comment */
32214493Ssam 
32314493Ssam 		putc(c,fout);
32414493Ssam 		savline=yyline;
32514493Ssam 		while( c=gch() ){
32614493Ssam 			if( c=='*' ){
32714493Ssam 				putc(c,fout);
32814493Ssam 				if( (c=gch()) == '/' ) goto loop;
32914493Ssam 				}
33014493Ssam 			putc(c,fout);
33114493Ssam 			}
33214493Ssam 		yyline=savline;
33314493Ssam 		error( "EOF inside comment" );
33414493Ssam 
33514493Ssam case '\'':	/* character constant */
33614493Ssam 		mth = '\'';
33714493Ssam 		goto string;
33814493Ssam 
33914493Ssam case '"':	/* character string */
34014493Ssam 		mth = '"';
34114493Ssam 
34214493Ssam 	string:
34314493Ssam 
34414493Ssam 		putc(c,fout);
34514493Ssam 		while( c=gch() ){
34614493Ssam 			if( c=='\\' ){
34714493Ssam 				putc(c,fout);
34814493Ssam 				c=gch();
34914493Ssam 				}
35014493Ssam 			else if( c==mth ) goto loop;
35114493Ssam 			putc(c,fout);
35214493Ssam 			if (c == '\n')
35314493Ssam 				{
35414493Ssam 				yyline--;
35514493Ssam 				error( "Non-terminated string or character constant");
35614493Ssam 				}
35714493Ssam 			}
35814493Ssam 		error( "EOF in string or character constant" );
35914493Ssam 
36014493Ssam case '\0':
36114493Ssam 		yyline = savline;
36214493Ssam 		error("Action does not terminate");
36314493Ssam default:
36414493Ssam 		break;		/* usual character */
36514493Ssam 		}
36614493Ssam loop:
36714493Ssam 	if(c != ' ' && c != '\t' && c != '\n') sw = FALSE;
36814493Ssam 	putc(c,fout);
36914493Ssam 	}
37014493Ssam error("Premature EOF");
37114493Ssam }
37214493Ssam gch(){
37314493Ssam 	register int c;
37418033Sserge 	static int hadeof;
37518033Sserge 
37618033Sserge 	if (hadeof) {
37718033Sserge 		hadeof = 0;
37818033Sserge 		yyline = 0;
37918033Sserge 	}
38014493Ssam 	prev = pres;
38114493Ssam 	c = pres = peek;
38214493Ssam 	peek = pushptr > pushc ? *--pushptr : getc(fin);
38314493Ssam 	if(peek == EOF && sargc > 1){
38418033Sserge 		hadeof = 1;
38514493Ssam 		fclose(fin);
38614493Ssam 		fin = fopen(sargv[++fptr],"r");
38718033Sserge 		if(fin == NULL) {
38818033Sserge 			yyline = 0;
38914493Ssam 			error("Cannot open file %s",sargv[fptr]);
39018033Sserge 		}
39114493Ssam 		peek = getc(fin);
39214493Ssam 		sargc--;
39314493Ssam 		}
39414493Ssam 	if(c == EOF) {
39514493Ssam 		eof = TRUE;
39614493Ssam 		fclose(fin);
39714493Ssam 		return(0);
39814493Ssam 		}
39914493Ssam 	if(c == '\n')yyline++;
40014493Ssam 	return(c);
40114493Ssam 	}
40214493Ssam mn2(a,d,c)
40314493Ssam   int a,d,c;
40414493Ssam 	{
40514493Ssam 	name[tptr] = a;
40614493Ssam 	left[tptr] = d;
40714493Ssam 	right[tptr] = c;
40814493Ssam 	parent[tptr] = 0;
40914493Ssam 	nullstr[tptr] = 0;
41014493Ssam 	switch(a){
41114493Ssam 	case RSTR:
41214493Ssam 		parent[d] = tptr;
41314493Ssam 		break;
41414493Ssam 	case BAR:
41514493Ssam 	case RNEWE:
41614493Ssam 		if(nullstr[d] || nullstr[c]) nullstr[tptr] = TRUE;
41714493Ssam 		parent[d] = parent[c] = tptr;
41814493Ssam 		break;
41914493Ssam 	case RCAT:
42014493Ssam 	case DIV:
42114493Ssam 		if(nullstr[d] && nullstr[c])nullstr[tptr] = TRUE;
42214493Ssam 		parent[d] = parent[c] = tptr;
42314493Ssam 		break;
42414493Ssam 	case RSCON:
42514493Ssam 		parent[d] = tptr;
42614493Ssam 		nullstr[tptr] = nullstr[d];
42714493Ssam 		break;
42814493Ssam # ifdef DEBUG
42914493Ssam 	default:
43014493Ssam 		warning("bad switch mn2 %d %d",a,d);
43114493Ssam 		break;
43214493Ssam # endif
43314493Ssam 		}
43414493Ssam 	if(tptr > treesize)
43514493Ssam 		error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
43614493Ssam 	return(tptr++);
43714493Ssam 	}
43814493Ssam mn1(a,d)
43914493Ssam   int a,d;
44014493Ssam 	{
44114493Ssam 	name[tptr] = a;
44214493Ssam 	left[tptr] = d;
44314493Ssam 	parent[tptr] = 0;
44414493Ssam 	nullstr[tptr] = 0;
44514493Ssam 	switch(a){
44614493Ssam 	case RCCL:
44714493Ssam 	case RNCCL:
44814493Ssam 		if(slength(d) == 0) nullstr[tptr] = TRUE;
44914493Ssam 		break;
45014493Ssam 	case STAR:
45114493Ssam 	case QUEST:
45214493Ssam 		nullstr[tptr] = TRUE;
45314493Ssam 		parent[d] = tptr;
45414493Ssam 		break;
45514493Ssam 	case PLUS:
45614493Ssam 	case CARAT:
45714493Ssam 		nullstr[tptr] = nullstr[d];
45814493Ssam 		parent[d] = tptr;
45914493Ssam 		break;
46014493Ssam 	case S2FINAL:
46114493Ssam 		nullstr[tptr] = TRUE;
46214493Ssam 		break;
46314493Ssam # ifdef DEBUG
46414493Ssam 	case FINAL:
46514493Ssam 	case S1FINAL:
46614493Ssam 		break;
46714493Ssam 	default:
46814493Ssam 		warning("bad switch mn1 %d %d",a,d);
46914493Ssam 		break;
47014493Ssam # endif
47114493Ssam 		}
47214493Ssam 	if(tptr > treesize)
47314493Ssam 		error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
47414493Ssam 	return(tptr++);
47514493Ssam 	}
47614493Ssam mn0(a)
47714493Ssam   int a;
47814493Ssam 	{
47914493Ssam 	name[tptr] = a;
48014493Ssam 	parent[tptr] = 0;
48114493Ssam 	nullstr[tptr] = 0;
48214493Ssam 	if(a >= NCH) switch(a){
48314493Ssam 	case RNULLS: nullstr[tptr] = TRUE; break;
48414493Ssam # ifdef DEBUG
48514493Ssam 	default:
48614493Ssam 		warning("bad switch mn0 %d",a);
48714493Ssam 		break;
48814493Ssam # endif
48914493Ssam 	}
49014493Ssam 	if(tptr > treesize)
49114493Ssam 		error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
49214493Ssam 	return(tptr++);
49314493Ssam 	}
49414493Ssam munput(t,p)	/* implementation dependent */
49514493Ssam   char *p;
49614493Ssam   int t; {
49714493Ssam 	register int i,j;
49814493Ssam 	if(t == 'c'){
49914493Ssam 		*pushptr++ = peek;		/* watch out for this */
50014493Ssam 		peek = p;
50114493Ssam 		}
50214493Ssam 	else if(t == 's'){
50314493Ssam 		*pushptr++ = peek;
50414493Ssam 		peek = p[0];
50514493Ssam 		i = slength(p);
50614493Ssam 		for(j = i-1; j>=1; j--)
50714493Ssam 			*pushptr++ = p[j];
50814493Ssam 		}
50914493Ssam # ifdef DEBUG
51014493Ssam 	else error("Unrecognized munput option %c",t);
51114493Ssam # endif
51214493Ssam 	if(pushptr >= pushc+TOKENSIZE)
51314493Ssam 		error("Too many characters pushed");
51414493Ssam 	return;
51514493Ssam 	}
51614493Ssam 
51714493Ssam dupl(n)
51814493Ssam   int n; {
51914493Ssam 	/* duplicate the subtree whose root is n, return ptr to it */
52014493Ssam 	register int i;
52114493Ssam 	i = name[n];
52214493Ssam 	if(i < NCH) return(mn0(i));
52314493Ssam 	switch(i){
52414493Ssam 	case RNULLS:
52514493Ssam 		return(mn0(i));
52614493Ssam 	case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL:
52714493Ssam 		return(mn1(i,left[n]));
52814493Ssam 	case STAR: case QUEST: case PLUS: case CARAT:
52914493Ssam 		return(mn1(i,dupl(left[n])));
53014493Ssam 	case RSTR: case RSCON:
53114493Ssam 		return(mn2(i,dupl(left[n]),right[n]));
53214493Ssam 	case BAR: case RNEWE: case RCAT: case DIV:
53314493Ssam 		return(mn2(i,dupl(left[n]),dupl(right[n])));
53414493Ssam # ifdef DEBUG
53514493Ssam 	default:
53614493Ssam 		warning("bad switch dupl %d",n);
53714493Ssam # endif
53814493Ssam 	}
53914493Ssam 	return(0);
54014493Ssam 	}
54114493Ssam # ifdef DEBUG
54214493Ssam allprint(c)
54314493Ssam   char c; {
54414493Ssam 	switch(c){
54514493Ssam 		case 014:
54614493Ssam 			printf("\\f");
54714493Ssam 			charc++;
54814493Ssam 			break;
54914493Ssam 		case '\n':
55014493Ssam 			printf("\\n");
55114493Ssam 			charc++;
55214493Ssam 			break;
55314493Ssam 		case '\t':
55414493Ssam 			printf("\\t");
55514493Ssam 			charc++;
55614493Ssam 			break;
55714493Ssam 		case '\b':
55814493Ssam 			printf("\\b");
55914493Ssam 			charc++;
56014493Ssam 			break;
56114493Ssam 		case ' ':
56214493Ssam 			printf("\\\bb");
56314493Ssam 			break;
56414493Ssam 		default:
56514493Ssam 			if(!printable(c)){
56614493Ssam 				printf("\\%-3o",c);
567*32766Sbostic 				charc += 3;
56814493Ssam 				}
56914493Ssam 			else
57014493Ssam 				putchar(c);
57114493Ssam 			break;
57214493Ssam 		}
57314493Ssam 	charc++;
57414493Ssam 	return;
57514493Ssam 	}
57614493Ssam strpt(s)
57714493Ssam   char *s; {
57814493Ssam 	charc = 0;
57914493Ssam 	while(*s){
58014493Ssam 		allprint(*s++);
58114493Ssam 		if(charc > LINESIZE){
58214493Ssam 			charc = 0;
58314493Ssam 			printf("\n\t");
58414493Ssam 			}
58514493Ssam 		}
58614493Ssam 	return;
58714493Ssam 	}
58814493Ssam sect1dump(){
58914493Ssam 	register int i;
59014493Ssam 	printf("Sect 1:\n");
59114493Ssam 	if(def[0]){
59214493Ssam 		printf("str	trans\n");
59314493Ssam 		i = -1;
59414493Ssam 		while(def[++i])
59514493Ssam 			printf("%s\t%s\n",def[i],subs[i]);
59614493Ssam 		}
59714493Ssam 	if(sname[0]){
59814493Ssam 		printf("start names\n");
59914493Ssam 		i = -1;
60014493Ssam 		while(sname[++i])
60114493Ssam 			printf("%s\n",sname[i]);
60214493Ssam 		}
60314493Ssam 	if(chset == TRUE){
60414493Ssam 		printf("char set changed\n");
60514493Ssam 		for(i=1;i<NCH;i++){
60614493Ssam 			if(i != ctable[i]){
60714493Ssam 				allprint(i);
60814493Ssam 				putchar(' ');
60914493Ssam 				printable(ctable[i]) ? putchar(ctable[i]) : printf("%d",ctable[i]);
61014493Ssam 				putchar('\n');
61114493Ssam 				}
61214493Ssam 			}
61314493Ssam 		}
61414493Ssam 	}
61514493Ssam sect2dump(){
61614493Ssam 	printf("Sect 2:\n");
61714493Ssam 	treedump();
61814493Ssam 	}
61914493Ssam treedump()
62014493Ssam 	{
62114493Ssam 	register int t;
62214493Ssam 	register char *p;
62314493Ssam 	printf("treedump %d nodes:\n",tptr);
62414493Ssam 	for(t=0;t<tptr;t++){
62514493Ssam 		printf("%4d ",t);
62614493Ssam 		parent[t] ? printf("p=%4d",parent[t]) : printf("      ");
62714493Ssam 		printf("  ");
62814493Ssam 		if(name[t] < NCH) {
62914493Ssam 				allprint(name[t]);
63014493Ssam 				}
63114493Ssam 		else switch(name[t]){
63214493Ssam 			case RSTR:
63314493Ssam 				printf("%d ",left[t]);
63414493Ssam 				allprint(right[t]);
63514493Ssam 				break;
63614493Ssam 			case RCCL:
63714493Ssam 				printf("ccl ");
63814493Ssam 				strpt(left[t]);
63914493Ssam 				break;
64014493Ssam 			case RNCCL:
64114493Ssam 				printf("nccl ");
64214493Ssam 				strpt(left[t]);
64314493Ssam 				break;
64414493Ssam 			case DIV:
64514493Ssam 				printf("/ %d %d",left[t],right[t]);
64614493Ssam 				break;
64714493Ssam 			case BAR:
64814493Ssam 				printf("| %d %d",left[t],right[t]);
64914493Ssam 				break;
65014493Ssam 			case RCAT:
65114493Ssam 				printf("cat %d %d",left[t],right[t]);
65214493Ssam 				break;
65314493Ssam 			case PLUS:
65414493Ssam 				printf("+ %d",left[t]);
65514493Ssam 				break;
65614493Ssam 			case STAR:
65714493Ssam 				printf("* %d",left[t]);
65814493Ssam 				break;
65914493Ssam 			case CARAT:
66014493Ssam 				printf("^ %d",left[t]);
66114493Ssam 				break;
66214493Ssam 			case QUEST:
66314493Ssam 				printf("? %d",left[t]);
66414493Ssam 				break;
66514493Ssam 			case RNULLS:
66614493Ssam 				printf("nullstring");
66714493Ssam 				break;
66814493Ssam 			case FINAL:
66914493Ssam 				printf("final %d",left[t]);
67014493Ssam 				break;
67114493Ssam 			case S1FINAL:
67214493Ssam 				printf("s1final %d",left[t]);
67314493Ssam 				break;
67414493Ssam 			case S2FINAL:
67514493Ssam 				printf("s2final %d",left[t]);
67614493Ssam 				break;
67714493Ssam 			case RNEWE:
67814493Ssam 				printf("new %d %d",left[t],right[t]);
67914493Ssam 				break;
68014493Ssam 			case RSCON:
68114493Ssam 				p = right[t];
68214493Ssam 				printf("start %s",sname[*p++-1]);
68314493Ssam 				while(*p)
68414493Ssam 					printf(", %s",sname[*p++-1]);
68514493Ssam 				printf(" %d",left[t]);
68614493Ssam 				break;
68714493Ssam 			default:
68814493Ssam 				printf("unknown %d %d %d",name[t],left[t],right[t]);
68914493Ssam 				break;
69014493Ssam 			}
69114493Ssam 		if(nullstr[t])printf("\t(null poss.)");
69214493Ssam 		putchar('\n');
69314493Ssam 		}
69414493Ssam 	}
69514493Ssam # endif
696