USG_PG3/usr/source/lexgen2/rdcomm.c
# include "../lexgen1/ldefs.c"
# define done {*string=0; return(1);}
rdcomm(string, ks)
char *string;
{
int c, stop, rule;
char classname[20], *cn, stuff[200], *s, *t;
if (gets(stuff) == 0)
return(0);
rule = !space(stuff[0]);
switch (stuff[0])
{
case 0:
done;
case '%':
switch (stuff[1])
{
case '%': return(0);
case '{':
printf(output, "%s\n",stuff+2);
while (gets(stuff) && !scomp(stuff, "%}"))
printf(output, "%s\n", stuff);
done;
default:
warning ("bad % line %s",stuff);
return(1);
}
default:
for (s=stuff; c= *s; s++)
{
if (space(c)) break;
switch (*string++ = c)
{
case '[':
case '"':
stop = (c == '[' ? ']' : '"');
while ( (*string++ = c = *++s) != stop)
if (c == '\\')
*string++ = *++s;
break;
case '\\':
*string++ = *++s;
break;
case '{':
for(cn=classname; (*cn= *++s) != '}'; cn++);
*cn=0;
string--;
cn = definition(classname,0,1);
if (cn==0)
warning("illegal name %s, ignoring",classname);
else
while(*string = *cn++)
string++;
break;
}
}
*string = 0;
}
if (c==0) return(0);
if (rule && ks==1)
head2();
if (rule)
{
if (ratfor)
printf(output, " \n%d\n", ks+30000);
else
printf(output, " \ncase %d:\n", ks);
}
while (space(*s)) s++;
if (*s == '|')
return(1);
for(t=s; *t; t++);
ungetc('\n',cin); lineno--;
while (t>s)
ungetc(*--t, cin);
cpyact();
if (rule)
printf(output, !ratfor ? "break;" : "next");
gets(stuff); /* absorb last newline */
return(1);
}