xref: /csrg-svn/old/lex/sub1.c (revision 14493)
1*14493Ssam #ifndef lint
2*14493Ssam static char sccsid[] = "@(#)sub1.c	4.1 (Berkeley) 08/11/83";
3*14493Ssam #endif
4*14493Ssam 
5*14493Ssam # include "ldefs.c"
6*14493Ssam char *
7*14493Ssam getl(p)	/* return next line of input, throw away trailing '\n' */
8*14493Ssam 	/* returns 0 if eof is had immediately */
9*14493Ssam   char *p;
10*14493Ssam 	{
11*14493Ssam 	register int c;
12*14493Ssam 	register char *s, *t;
13*14493Ssam 	t = s = p;
14*14493Ssam 	while(((c = gch()) != 0) && c != '\n')
15*14493Ssam 		*t++ = c;
16*14493Ssam 	*t = 0;
17*14493Ssam 	if(c == 0 && s == t) return(0);
18*14493Ssam 	prev = '\n';
19*14493Ssam 	pres = '\n';
20*14493Ssam 	return(s);
21*14493Ssam 	}
22*14493Ssam space(ch)
23*14493Ssam 	{
24*14493Ssam 	switch(ch)
25*14493Ssam 		{
26*14493Ssam 		case ' ':
27*14493Ssam 		case '\t':
28*14493Ssam 		case '\n':
29*14493Ssam 			return(1);
30*14493Ssam 		}
31*14493Ssam 	return(0);
32*14493Ssam 	}
33*14493Ssam 
34*14493Ssam digit(c)
35*14493Ssam {
36*14493Ssam 	return(c>='0' && c <= '9');
37*14493Ssam }
38*14493Ssam error(s,p,d)
39*14493Ssam 	{
40*14493Ssam 	if(!eof)fprintf(errorf,"%d: ",yyline);
41*14493Ssam 	fprintf(errorf,"(Error) ");
42*14493Ssam 	fprintf(errorf,s,p,d);
43*14493Ssam 	putc('\n',errorf);
44*14493Ssam # ifdef DEBUG
45*14493Ssam 	if(debug && sect != ENDSECTION) {
46*14493Ssam 		sect1dump();
47*14493Ssam 		sect2dump();
48*14493Ssam 	}
49*14493Ssam # endif
50*14493Ssam 	if(
51*14493Ssam # ifdef DEBUG
52*14493Ssam 		debug ||
53*14493Ssam # endif
54*14493Ssam 		report == 1) statistics();
55*14493Ssam 	exit(1);	/* error return code */
56*14493Ssam 	}
57*14493Ssam 
58*14493Ssam warning(s,p,d)
59*14493Ssam 	{
60*14493Ssam 	if(!eof)fprintf(errorf,"%d: ",yyline);
61*14493Ssam 	fprintf(errorf,"(Warning) ");
62*14493Ssam 	fprintf(errorf,s,p,d);
63*14493Ssam 	putc('\n',errorf);
64*14493Ssam 	fflush(errorf);
65*14493Ssam 	fflush(fout);
66*14493Ssam 	fflush(stdout);
67*14493Ssam 	}
68*14493Ssam index(a,s)
69*14493Ssam 	char *s;
70*14493Ssam {
71*14493Ssam 	register int k;
72*14493Ssam 	for(k=0; s[k]; k++)
73*14493Ssam 		if (s[k]== a)
74*14493Ssam 			return(k);
75*14493Ssam 	return(-1);
76*14493Ssam 	}
77*14493Ssam 
78*14493Ssam alpha(c)
79*14493Ssam   int c; {
80*14493Ssam # ifdef ASCII
81*14493Ssam return('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z');
82*14493Ssam # endif
83*14493Ssam # ifdef EBCDIC
84*14493Ssam return(index(c,"abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") >= 0);
85*14493Ssam # endif
86*14493Ssam }
87*14493Ssam printable(c)
88*14493Ssam {
89*14493Ssam # ifdef ASCII
90*14493Ssam return( c>040 && c < 0177);
91*14493Ssam # endif
92*14493Ssam # ifdef EBCDIC
93*14493Ssam return(index(c, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;:><+*)('&%!-=\"")>=0);
94*14493Ssam # endif
95*14493Ssam }
96*14493Ssam lgate()
97*14493Ssam {
98*14493Ssam 	char fname[20];
99*14493Ssam 	if (lgatflg) return;
100*14493Ssam 	lgatflg=1;
101*14493Ssam 	if(fout == NULL){
102*14493Ssam 		sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c' );
103*14493Ssam 		fout = fopen(fname, "w");
104*14493Ssam 		}
105*14493Ssam 	if(fout == NULL) error("Can't open %s",fname);
106*14493Ssam 	if(ratfor) fprintf( fout, "#\n");
107*14493Ssam 	phead1();
108*14493Ssam 	}
109*14493Ssam /* scopy(ptr to str, ptr to str) - copy first arg str to second */
110*14493Ssam /* returns ptr to second arg */
111*14493Ssam scopy(s,t)
112*14493Ssam   char *s, *t; {
113*14493Ssam 	register char *i;
114*14493Ssam 	i = t;
115*14493Ssam 	while(*i++ = *s++);
116*14493Ssam 	return;
117*14493Ssam 	}
118*14493Ssam siconv(t)	/* convert string t, return integer value */
119*14493Ssam   char *t; {
120*14493Ssam 	register int i,sw;
121*14493Ssam 	register char *s;
122*14493Ssam 	s = t;
123*14493Ssam 	while(!(('0' <= *s && *s <= '9') || *s == '-') && *s) s++;
124*14493Ssam 	sw = 0;
125*14493Ssam 	if(*s == '-'){	/* neg */
126*14493Ssam 		sw = 1;
127*14493Ssam 		s++;
128*14493Ssam 		}
129*14493Ssam 	i = 0;
130*14493Ssam 	while('0' <= *s && *s <= '9')
131*14493Ssam 		i = i * 10 + (*(s++)-'0');
132*14493Ssam 	return(sw ? -i : i);
133*14493Ssam 	}
134*14493Ssam /* slength(ptr to str) - return integer length of string arg */
135*14493Ssam /* excludes '\0' terminator */
136*14493Ssam slength(s)
137*14493Ssam   char *s; {
138*14493Ssam 	register int n;
139*14493Ssam 	register char *t;
140*14493Ssam 	t = s;
141*14493Ssam 	for (n = 0; *t++; n++);
142*14493Ssam 	return(n);
143*14493Ssam 	}
144*14493Ssam /* scomp(x,y) - return -1 if x < y,
145*14493Ssam 		0 if x == y,
146*14493Ssam 		return 1 if x > y, all lexicographically */
147*14493Ssam scomp(x,y)
148*14493Ssam   char *x,*y; {
149*14493Ssam 	register char *a,*d;
150*14493Ssam 	a = x;
151*14493Ssam 	d = y;
152*14493Ssam 	while(*a || *d){
153*14493Ssam 		if(*a > *d)
154*14493Ssam 			return(1);	/* greater */
155*14493Ssam 		if(*a < *d)
156*14493Ssam 			return(-1);	/* less */
157*14493Ssam 		a++;
158*14493Ssam 		d++;
159*14493Ssam 		}
160*14493Ssam 	return(0);	/* equal */
161*14493Ssam 	}
162*14493Ssam ctrans(ss)
163*14493Ssam 	char **ss;
164*14493Ssam {
165*14493Ssam 	register int c, k;
166*14493Ssam 	if ((c = **ss) != '\\')
167*14493Ssam 		return(c);
168*14493Ssam 	switch(c= *++*ss)
169*14493Ssam 	{
170*14493Ssam 	case 'n': c = '\n'; break;
171*14493Ssam 	case 't': c = '\t'; break;
172*14493Ssam 	case 'r': c = '\r'; break;
173*14493Ssam 	case 'b': c = '\b'; break;
174*14493Ssam 	case 'f': c = 014; break;		/* form feed for ascii */
175*14493Ssam 	case '\\': c = '\\'; break;
176*14493Ssam 	case '0': case '1': case '2': case '3':
177*14493Ssam 	case '4': case '5': case '6': case '7':
178*14493Ssam 		c -= '0';
179*14493Ssam 		while ((k = *(*ss+1)) >= '0' && k <= '7')
180*14493Ssam 			{
181*14493Ssam 			c = c*8 + k - '0';
182*14493Ssam 			(*ss)++;
183*14493Ssam 			}
184*14493Ssam 		break;
185*14493Ssam 	}
186*14493Ssam 	return(c);
187*14493Ssam }
188*14493Ssam cclinter(sw)
189*14493Ssam   int sw; {
190*14493Ssam 		/* sw = 1 ==> ccl */
191*14493Ssam 	register int i, j, k;
192*14493Ssam 	int m;
193*14493Ssam 	if(!sw){		/* is NCCL */
194*14493Ssam 		for(i=1;i<NCH;i++)
195*14493Ssam 			symbol[i] ^= 1;			/* reverse value */
196*14493Ssam 		}
197*14493Ssam 	for(i=1;i<NCH;i++)
198*14493Ssam 		if(symbol[i]) break;
199*14493Ssam 	if(i >= NCH) return;
200*14493Ssam 	i = cindex[i];
201*14493Ssam 	/* see if ccl is already in our table */
202*14493Ssam 	j = 0;
203*14493Ssam 	if(i){
204*14493Ssam 		for(j=1;j<NCH;j++){
205*14493Ssam 			if((symbol[j] && cindex[j] != i) ||
206*14493Ssam 			   (!symbol[j] && cindex[j] == i)) break;
207*14493Ssam 			}
208*14493Ssam 		}
209*14493Ssam 	if(j >= NCH) return;		/* already in */
210*14493Ssam 	m = 0;
211*14493Ssam 	k = 0;
212*14493Ssam 	for(i=1;i<NCH;i++)
213*14493Ssam 		if(symbol[i]){
214*14493Ssam 			if(!cindex[i]){
215*14493Ssam 				cindex[i] = ccount;
216*14493Ssam 				symbol[i] = 0;
217*14493Ssam 				m = 1;
218*14493Ssam 				}
219*14493Ssam 			else k = 1;
220*14493Ssam 			}
221*14493Ssam 			/* m == 1 implies last value of ccount has been used */
222*14493Ssam 	if(m)ccount++;
223*14493Ssam 	if(k == 0) return;	/* is now in as ccount wholly */
224*14493Ssam 	/* intersection must be computed */
225*14493Ssam 	for(i=1;i<NCH;i++){
226*14493Ssam 		if(symbol[i]){
227*14493Ssam 			m = 0;
228*14493Ssam 			j = cindex[i];	/* will be non-zero */
229*14493Ssam 			for(k=1;k<NCH;k++){
230*14493Ssam 				if(cindex[k] == j){
231*14493Ssam 					if(symbol[k]) symbol[k] = 0;
232*14493Ssam 					else {
233*14493Ssam 						cindex[k] = ccount;
234*14493Ssam 						m = 1;
235*14493Ssam 						}
236*14493Ssam 					}
237*14493Ssam 				}
238*14493Ssam 			if(m)ccount++;
239*14493Ssam 			}
240*14493Ssam 		}
241*14493Ssam 	return;
242*14493Ssam 	}
243*14493Ssam usescape(c)
244*14493Ssam   int c; {
245*14493Ssam 	register char d;
246*14493Ssam 	switch(c){
247*14493Ssam 	case 'n': c = '\n'; break;
248*14493Ssam 	case 'r': c = '\r'; break;
249*14493Ssam 	case 't': c = '\t'; break;
250*14493Ssam 	case 'b': c = '\b'; break;
251*14493Ssam 	case 'f': c = 014; break;		/* form feed for ascii */
252*14493Ssam 	case '0': case '1': case '2': case '3':
253*14493Ssam 	case '4': case '5': case '6': case '7':
254*14493Ssam 		c -= '0';
255*14493Ssam 		while('0' <= (d=gch()) && d <= '7'){
256*14493Ssam 			c = c * 8 + (d-'0');
257*14493Ssam 			if(!('0' <= peek && peek <= '7')) break;
258*14493Ssam 			}
259*14493Ssam 		break;
260*14493Ssam 	}
261*14493Ssam 	return(c);
262*14493Ssam 	}
263*14493Ssam lookup(s,t)
264*14493Ssam   char *s;
265*14493Ssam   char **t; {
266*14493Ssam 	register int i;
267*14493Ssam 	i = 0;
268*14493Ssam 	while(*t){
269*14493Ssam 		if(scomp(s,*t) == 0)
270*14493Ssam 			return(i);
271*14493Ssam 		i++;
272*14493Ssam 		t++;
273*14493Ssam 		}
274*14493Ssam 	return(-1);
275*14493Ssam 	}
276*14493Ssam cpyact(){ /* copy C action to the next ; or closing } */
277*14493Ssam 	register int brac, c, mth;
278*14493Ssam 	int savline, sw;
279*14493Ssam 
280*14493Ssam 	brac = 0;
281*14493Ssam 	sw = TRUE;
282*14493Ssam 
283*14493Ssam while(!eof){
284*14493Ssam 	c = gch();
285*14493Ssam swt:
286*14493Ssam 	switch( c ){
287*14493Ssam 
288*14493Ssam case '|':	if(brac == 0 && sw == TRUE){
289*14493Ssam 			if(peek == '|')gch();		/* eat up an extra '|' */
290*14493Ssam 			return(0);
291*14493Ssam 			}
292*14493Ssam 		break;
293*14493Ssam 
294*14493Ssam case ';':
295*14493Ssam 		if( brac == 0 ){
296*14493Ssam 			putc(c,fout);
297*14493Ssam 			putc('\n',fout);
298*14493Ssam 			return(1);
299*14493Ssam 			}
300*14493Ssam 		break;
301*14493Ssam 
302*14493Ssam case '{':
303*14493Ssam 		brac++;
304*14493Ssam 		savline=yyline;
305*14493Ssam 		break;
306*14493Ssam 
307*14493Ssam case '}':
308*14493Ssam 		brac--;
309*14493Ssam 		if( brac == 0 ){
310*14493Ssam 			putc(c,fout);
311*14493Ssam 			putc('\n',fout);
312*14493Ssam 			return(1);
313*14493Ssam 			}
314*14493Ssam 		break;
315*14493Ssam 
316*14493Ssam case '/':	/* look for comments */
317*14493Ssam 		putc(c,fout);
318*14493Ssam 		c = gch();
319*14493Ssam 		if( c != '*' ) goto swt;
320*14493Ssam 
321*14493Ssam 		/* it really is a comment */
322*14493Ssam 
323*14493Ssam 		putc(c,fout);
324*14493Ssam 		savline=yyline;
325*14493Ssam 		while( c=gch() ){
326*14493Ssam 			if( c=='*' ){
327*14493Ssam 				putc(c,fout);
328*14493Ssam 				if( (c=gch()) == '/' ) goto loop;
329*14493Ssam 				}
330*14493Ssam 			putc(c,fout);
331*14493Ssam 			}
332*14493Ssam 		yyline=savline;
333*14493Ssam 		error( "EOF inside comment" );
334*14493Ssam 
335*14493Ssam case '\'':	/* character constant */
336*14493Ssam 		mth = '\'';
337*14493Ssam 		goto string;
338*14493Ssam 
339*14493Ssam case '"':	/* character string */
340*14493Ssam 		mth = '"';
341*14493Ssam 
342*14493Ssam 	string:
343*14493Ssam 
344*14493Ssam 		putc(c,fout);
345*14493Ssam 		while( c=gch() ){
346*14493Ssam 			if( c=='\\' ){
347*14493Ssam 				putc(c,fout);
348*14493Ssam 				c=gch();
349*14493Ssam 				}
350*14493Ssam 			else if( c==mth ) goto loop;
351*14493Ssam 			putc(c,fout);
352*14493Ssam 			if (c == '\n')
353*14493Ssam 				{
354*14493Ssam 				yyline--;
355*14493Ssam 				error( "Non-terminated string or character constant");
356*14493Ssam 				}
357*14493Ssam 			}
358*14493Ssam 		error( "EOF in string or character constant" );
359*14493Ssam 
360*14493Ssam case '\0':
361*14493Ssam 		yyline = savline;
362*14493Ssam 		error("Action does not terminate");
363*14493Ssam default:
364*14493Ssam 		break;		/* usual character */
365*14493Ssam 		}
366*14493Ssam loop:
367*14493Ssam 	if(c != ' ' && c != '\t' && c != '\n') sw = FALSE;
368*14493Ssam 	putc(c,fout);
369*14493Ssam 	}
370*14493Ssam error("Premature EOF");
371*14493Ssam }
372*14493Ssam gch(){
373*14493Ssam 	register int c;
374*14493Ssam 	prev = pres;
375*14493Ssam 	c = pres = peek;
376*14493Ssam 	peek = pushptr > pushc ? *--pushptr : getc(fin);
377*14493Ssam 	if(peek == EOF && sargc > 1){
378*14493Ssam 		fclose(fin);
379*14493Ssam 		fin = fopen(sargv[++fptr],"r");
380*14493Ssam 		if(fin == NULL)
381*14493Ssam 			error("Cannot open file %s",sargv[fptr]);
382*14493Ssam 		peek = getc(fin);
383*14493Ssam 		sargc--;
384*14493Ssam 		sargv++;
385*14493Ssam 		}
386*14493Ssam 	if(c == EOF) {
387*14493Ssam 		eof = TRUE;
388*14493Ssam 		fclose(fin);
389*14493Ssam 		return(0);
390*14493Ssam 		}
391*14493Ssam 	if(c == '\n')yyline++;
392*14493Ssam 	return(c);
393*14493Ssam 	}
394*14493Ssam mn2(a,d,c)
395*14493Ssam   int a,d,c;
396*14493Ssam 	{
397*14493Ssam 	name[tptr] = a;
398*14493Ssam 	left[tptr] = d;
399*14493Ssam 	right[tptr] = c;
400*14493Ssam 	parent[tptr] = 0;
401*14493Ssam 	nullstr[tptr] = 0;
402*14493Ssam 	switch(a){
403*14493Ssam 	case RSTR:
404*14493Ssam 		parent[d] = tptr;
405*14493Ssam 		break;
406*14493Ssam 	case BAR:
407*14493Ssam 	case RNEWE:
408*14493Ssam 		if(nullstr[d] || nullstr[c]) nullstr[tptr] = TRUE;
409*14493Ssam 		parent[d] = parent[c] = tptr;
410*14493Ssam 		break;
411*14493Ssam 	case RCAT:
412*14493Ssam 	case DIV:
413*14493Ssam 		if(nullstr[d] && nullstr[c])nullstr[tptr] = TRUE;
414*14493Ssam 		parent[d] = parent[c] = tptr;
415*14493Ssam 		break;
416*14493Ssam 	case RSCON:
417*14493Ssam 		parent[d] = tptr;
418*14493Ssam 		nullstr[tptr] = nullstr[d];
419*14493Ssam 		break;
420*14493Ssam # ifdef DEBUG
421*14493Ssam 	default:
422*14493Ssam 		warning("bad switch mn2 %d %d",a,d);
423*14493Ssam 		break;
424*14493Ssam # endif
425*14493Ssam 		}
426*14493Ssam 	if(tptr > treesize)
427*14493Ssam 		error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
428*14493Ssam 	return(tptr++);
429*14493Ssam 	}
430*14493Ssam mn1(a,d)
431*14493Ssam   int a,d;
432*14493Ssam 	{
433*14493Ssam 	name[tptr] = a;
434*14493Ssam 	left[tptr] = d;
435*14493Ssam 	parent[tptr] = 0;
436*14493Ssam 	nullstr[tptr] = 0;
437*14493Ssam 	switch(a){
438*14493Ssam 	case RCCL:
439*14493Ssam 	case RNCCL:
440*14493Ssam 		if(slength(d) == 0) nullstr[tptr] = TRUE;
441*14493Ssam 		break;
442*14493Ssam 	case STAR:
443*14493Ssam 	case QUEST:
444*14493Ssam 		nullstr[tptr] = TRUE;
445*14493Ssam 		parent[d] = tptr;
446*14493Ssam 		break;
447*14493Ssam 	case PLUS:
448*14493Ssam 	case CARAT:
449*14493Ssam 		nullstr[tptr] = nullstr[d];
450*14493Ssam 		parent[d] = tptr;
451*14493Ssam 		break;
452*14493Ssam 	case S2FINAL:
453*14493Ssam 		nullstr[tptr] = TRUE;
454*14493Ssam 		break;
455*14493Ssam # ifdef DEBUG
456*14493Ssam 	case FINAL:
457*14493Ssam 	case S1FINAL:
458*14493Ssam 		break;
459*14493Ssam 	default:
460*14493Ssam 		warning("bad switch mn1 %d %d",a,d);
461*14493Ssam 		break;
462*14493Ssam # endif
463*14493Ssam 		}
464*14493Ssam 	if(tptr > treesize)
465*14493Ssam 		error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
466*14493Ssam 	return(tptr++);
467*14493Ssam 	}
468*14493Ssam mn0(a)
469*14493Ssam   int a;
470*14493Ssam 	{
471*14493Ssam 	name[tptr] = a;
472*14493Ssam 	parent[tptr] = 0;
473*14493Ssam 	nullstr[tptr] = 0;
474*14493Ssam 	if(a >= NCH) switch(a){
475*14493Ssam 	case RNULLS: nullstr[tptr] = TRUE; break;
476*14493Ssam # ifdef DEBUG
477*14493Ssam 	default:
478*14493Ssam 		warning("bad switch mn0 %d",a);
479*14493Ssam 		break;
480*14493Ssam # endif
481*14493Ssam 	}
482*14493Ssam 	if(tptr > treesize)
483*14493Ssam 		error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
484*14493Ssam 	return(tptr++);
485*14493Ssam 	}
486*14493Ssam munput(t,p)	/* implementation dependent */
487*14493Ssam   char *p;
488*14493Ssam   int t; {
489*14493Ssam 	register int i,j;
490*14493Ssam 	if(t == 'c'){
491*14493Ssam 		*pushptr++ = peek;		/* watch out for this */
492*14493Ssam 		peek = p;
493*14493Ssam 		}
494*14493Ssam 	else if(t == 's'){
495*14493Ssam 		*pushptr++ = peek;
496*14493Ssam 		peek = p[0];
497*14493Ssam 		i = slength(p);
498*14493Ssam 		for(j = i-1; j>=1; j--)
499*14493Ssam 			*pushptr++ = p[j];
500*14493Ssam 		}
501*14493Ssam # ifdef DEBUG
502*14493Ssam 	else error("Unrecognized munput option %c",t);
503*14493Ssam # endif
504*14493Ssam 	if(pushptr >= pushc+TOKENSIZE)
505*14493Ssam 		error("Too many characters pushed");
506*14493Ssam 	return;
507*14493Ssam 	}
508*14493Ssam 
509*14493Ssam dupl(n)
510*14493Ssam   int n; {
511*14493Ssam 	/* duplicate the subtree whose root is n, return ptr to it */
512*14493Ssam 	register int i;
513*14493Ssam 	i = name[n];
514*14493Ssam 	if(i < NCH) return(mn0(i));
515*14493Ssam 	switch(i){
516*14493Ssam 	case RNULLS:
517*14493Ssam 		return(mn0(i));
518*14493Ssam 	case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL:
519*14493Ssam 		return(mn1(i,left[n]));
520*14493Ssam 	case STAR: case QUEST: case PLUS: case CARAT:
521*14493Ssam 		return(mn1(i,dupl(left[n])));
522*14493Ssam 	case RSTR: case RSCON:
523*14493Ssam 		return(mn2(i,dupl(left[n]),right[n]));
524*14493Ssam 	case BAR: case RNEWE: case RCAT: case DIV:
525*14493Ssam 		return(mn2(i,dupl(left[n]),dupl(right[n])));
526*14493Ssam # ifdef DEBUG
527*14493Ssam 	default:
528*14493Ssam 		warning("bad switch dupl %d",n);
529*14493Ssam # endif
530*14493Ssam 	}
531*14493Ssam 	return(0);
532*14493Ssam 	}
533*14493Ssam # ifdef DEBUG
534*14493Ssam allprint(c)
535*14493Ssam   char c; {
536*14493Ssam 	switch(c){
537*14493Ssam 		case 014:
538*14493Ssam 			printf("\\f");
539*14493Ssam 			charc++;
540*14493Ssam 			break;
541*14493Ssam 		case '\n':
542*14493Ssam 			printf("\\n");
543*14493Ssam 			charc++;
544*14493Ssam 			break;
545*14493Ssam 		case '\t':
546*14493Ssam 			printf("\\t");
547*14493Ssam 			charc++;
548*14493Ssam 			break;
549*14493Ssam 		case '\b':
550*14493Ssam 			printf("\\b");
551*14493Ssam 			charc++;
552*14493Ssam 			break;
553*14493Ssam 		case ' ':
554*14493Ssam 			printf("\\\bb");
555*14493Ssam 			break;
556*14493Ssam 		default:
557*14493Ssam 			if(!printable(c)){
558*14493Ssam 				printf("\\%-3o",c);
559*14493Ssam 				charc =+ 3;
560*14493Ssam 				}
561*14493Ssam 			else
562*14493Ssam 				putchar(c);
563*14493Ssam 			break;
564*14493Ssam 		}
565*14493Ssam 	charc++;
566*14493Ssam 	return;
567*14493Ssam 	}
568*14493Ssam strpt(s)
569*14493Ssam   char *s; {
570*14493Ssam 	charc = 0;
571*14493Ssam 	while(*s){
572*14493Ssam 		allprint(*s++);
573*14493Ssam 		if(charc > LINESIZE){
574*14493Ssam 			charc = 0;
575*14493Ssam 			printf("\n\t");
576*14493Ssam 			}
577*14493Ssam 		}
578*14493Ssam 	return;
579*14493Ssam 	}
580*14493Ssam sect1dump(){
581*14493Ssam 	register int i;
582*14493Ssam 	printf("Sect 1:\n");
583*14493Ssam 	if(def[0]){
584*14493Ssam 		printf("str	trans\n");
585*14493Ssam 		i = -1;
586*14493Ssam 		while(def[++i])
587*14493Ssam 			printf("%s\t%s\n",def[i],subs[i]);
588*14493Ssam 		}
589*14493Ssam 	if(sname[0]){
590*14493Ssam 		printf("start names\n");
591*14493Ssam 		i = -1;
592*14493Ssam 		while(sname[++i])
593*14493Ssam 			printf("%s\n",sname[i]);
594*14493Ssam 		}
595*14493Ssam 	if(chset == TRUE){
596*14493Ssam 		printf("char set changed\n");
597*14493Ssam 		for(i=1;i<NCH;i++){
598*14493Ssam 			if(i != ctable[i]){
599*14493Ssam 				allprint(i);
600*14493Ssam 				putchar(' ');
601*14493Ssam 				printable(ctable[i]) ? putchar(ctable[i]) : printf("%d",ctable[i]);
602*14493Ssam 				putchar('\n');
603*14493Ssam 				}
604*14493Ssam 			}
605*14493Ssam 		}
606*14493Ssam 	}
607*14493Ssam sect2dump(){
608*14493Ssam 	printf("Sect 2:\n");
609*14493Ssam 	treedump();
610*14493Ssam 	}
611*14493Ssam treedump()
612*14493Ssam 	{
613*14493Ssam 	register int t;
614*14493Ssam 	register char *p;
615*14493Ssam 	printf("treedump %d nodes:\n",tptr);
616*14493Ssam 	for(t=0;t<tptr;t++){
617*14493Ssam 		printf("%4d ",t);
618*14493Ssam 		parent[t] ? printf("p=%4d",parent[t]) : printf("      ");
619*14493Ssam 		printf("  ");
620*14493Ssam 		if(name[t] < NCH) {
621*14493Ssam 				allprint(name[t]);
622*14493Ssam 				}
623*14493Ssam 		else switch(name[t]){
624*14493Ssam 			case RSTR:
625*14493Ssam 				printf("%d ",left[t]);
626*14493Ssam 				allprint(right[t]);
627*14493Ssam 				break;
628*14493Ssam 			case RCCL:
629*14493Ssam 				printf("ccl ");
630*14493Ssam 				strpt(left[t]);
631*14493Ssam 				break;
632*14493Ssam 			case RNCCL:
633*14493Ssam 				printf("nccl ");
634*14493Ssam 				strpt(left[t]);
635*14493Ssam 				break;
636*14493Ssam 			case DIV:
637*14493Ssam 				printf("/ %d %d",left[t],right[t]);
638*14493Ssam 				break;
639*14493Ssam 			case BAR:
640*14493Ssam 				printf("| %d %d",left[t],right[t]);
641*14493Ssam 				break;
642*14493Ssam 			case RCAT:
643*14493Ssam 				printf("cat %d %d",left[t],right[t]);
644*14493Ssam 				break;
645*14493Ssam 			case PLUS:
646*14493Ssam 				printf("+ %d",left[t]);
647*14493Ssam 				break;
648*14493Ssam 			case STAR:
649*14493Ssam 				printf("* %d",left[t]);
650*14493Ssam 				break;
651*14493Ssam 			case CARAT:
652*14493Ssam 				printf("^ %d",left[t]);
653*14493Ssam 				break;
654*14493Ssam 			case QUEST:
655*14493Ssam 				printf("? %d",left[t]);
656*14493Ssam 				break;
657*14493Ssam 			case RNULLS:
658*14493Ssam 				printf("nullstring");
659*14493Ssam 				break;
660*14493Ssam 			case FINAL:
661*14493Ssam 				printf("final %d",left[t]);
662*14493Ssam 				break;
663*14493Ssam 			case S1FINAL:
664*14493Ssam 				printf("s1final %d",left[t]);
665*14493Ssam 				break;
666*14493Ssam 			case S2FINAL:
667*14493Ssam 				printf("s2final %d",left[t]);
668*14493Ssam 				break;
669*14493Ssam 			case RNEWE:
670*14493Ssam 				printf("new %d %d",left[t],right[t]);
671*14493Ssam 				break;
672*14493Ssam 			case RSCON:
673*14493Ssam 				p = right[t];
674*14493Ssam 				printf("start %s",sname[*p++-1]);
675*14493Ssam 				while(*p)
676*14493Ssam 					printf(", %s",sname[*p++-1]);
677*14493Ssam 				printf(" %d",left[t]);
678*14493Ssam 				break;
679*14493Ssam 			default:
680*14493Ssam 				printf("unknown %d %d %d",name[t],left[t],right[t]);
681*14493Ssam 				break;
682*14493Ssam 			}
683*14493Ssam 		if(nullstr[t])printf("\t(null poss.)");
684*14493Ssam 		putchar('\n');
685*14493Ssam 		}
686*14493Ssam 	}
687*14493Ssam # endif
688