# include "ldefs.h"
uchar *
getl(uchar *p) /* return next line of input, throw away trailing '\n' */
/* returns 0 if eof is had immediately */
{
int c;
uchar *s, *t;
t = s = p;
while(((c = gch()) != 0) && c != '\n')
*t++ = c;
*t = 0;
if(c == 0 && s == t) return((uchar *)0);
prev = '\n';
pres = '\n';
return(s);
}
void
cclinter(int sw)
{
/* sw = 1 ==> ccl */
int i, j, k;
int m;
if(!sw){ /* is NCCL */
for(i=1;i<NCH;i++)
symbol[i] ^= 1; /* reverse value */
}
for(i=1;i<NCH;i++)
if(symbol[i]) break;
if(i >= NCH) return;
i = cindex[i];
/* see if ccl is already in our table */
j = 0;
if(i){
for(j=1;j<NCH;j++){
if((symbol[j] && cindex[j] != i) ||
(!symbol[j] && cindex[j] == i)) break;
}
}
if(j >= NCH) return; /* already in */
m = 0;
k = 0;
for(i=1;i<NCH;i++)
if(symbol[i]){
if(!cindex[i]){
cindex[i] = ccount;
symbol[i] = 0;
m = 1;
} else k = 1;
}
/* m == 1 implies last value of ccount has been used */
if(m)ccount++;
if(k == 0) return; /* is now in as ccount wholly */
/* intersection must be computed */
for(i=1;i<NCH;i++){
if(symbol[i]){
m = 0;
j = cindex[i]; /* will be non-zero */
for(k=1;k<NCH;k++){
if(cindex[k] == j){
if(symbol[k]) symbol[k] = 0;
else {
cindex[k] = ccount;
m = 1;
}
}
}
if(m)ccount++;
}
}
}
int
usescape(int c)
{
int d;
switch(c){
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'b': c = '\b'; break;
case 'f': c = 014; break; /* form feed for ascii */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
c -= '0';
while('0' <= (d=gch()) && d <= '7'){
c = c * 8 + (d-'0');
if(!('0' <= peek && peek <= '7')) break;
}
break;
}
return(c);
}
int
lookup(uchar *s, uchar **t)
{
int i;
i = 0;
while(*t){
if(strcmp((char *)s, *(char **)t) == 0)
return(i);
i++;
t++;
}
return(-1);
}
int
cpyact(void)
{ /* copy C action to the next ; or closing } */
int brac, c, mth;
int savline, sw;
char *savfile;
brac = 0;
sw = TRUE;
savline = 0;
savfile = "?";
while(!eof){
c = gch();
swt:
switch( c ){
case '|': if(brac == 0 && sw == TRUE){
if(peek == '|')gch(); /* eat up an extra '|' */
return(0);
}
break;
int
dupl(int n)
{
/* duplicate the subtree whose root is n, return ptr to it */
int i;
i = name[n];
if(i < NCH) return(mn0(i));
switch(i){
case RNULLS:
return(mn0(i));
case RCCL: case RNCCL:
return(mnp(i,ptr[n]));
case FINAL: case S1FINAL: case S2FINAL:
return(mn1(i,left[n]));
case STAR: case QUEST: case PLUS: case CARAT:
return(mn1(i,dupl(left[n])));
case RSTR: case RSCON:
return(mn2(i,dupl(left[n]),right[n]));
case BAR: case RNEWE: case RCAT: case DIV:
return(mn2(i,dupl(left[n]),dupl(right[n])));
# ifdef DEBUG
default:
warning("bad switch dupl %d",n);
# endif
}
return(0);
}
# ifdef DEBUG
void
allprint(int c)
{
if(c < 0)
c += 256; /* signed char */
switch(c){
case 014:
print("\\f");
charc++;
break;
case '\n':
print("\\n");
charc++;
break;
case '\t':
print("\\t");
charc++;
break;
case '\b':
print("\\b");
charc++;
break;
case ' ':
print("\\\bb");
break;
default:
if(!isprint(c)){
print("\\%-3o",c);
charc += 3;
} else
print("%c", c);
break;
}
charc++;
}