# include "../lexgen1/ldefs.c"
extern cin, lineno, lgatflg;
defrd()
{
	int c, savline;
	char line[200], *cp;
	static char lcomm[20];
while(1)
	{
	switch(c=getchar())
		{
		case '%':
			switch(c=getchar())
			{
			case '%':
				lgate();
				gets(line);
				return;
			case '+':
				if (lgatflg)
					warning("too late to change file name");
				gets(label=lcomm);
				while(space(*label)) label++;
				continue;
			case '{':
				lgate();
				savline = lineno;
				while (gets(line) && !scomp(line,"%}"))
					printf(output,"%s\n",line);
				if (line[0] == '%')
					continue;
				lineno=savline;
				error("Non-terminated copy");
			case 't': case 'T':
				/* character table */
				usrtab();
				continue;
			case 's': case 'S':
				defst();
				continue;
			case 'r': case 'R':
				c = 'r';
			case 'c': case 'C':
				if (lgatflg)
					warning("too late to specify host language");
				ratfor = (c== 'r');
				continue;
			}
			warning("undefined control  line %%%c\n",c);
			break;
		case ' ':
		case '\t':
			lgate();
			while (space(c=getchar()));
			ungetc(c, cin);
			cpyact();
			cputc('\n',output);
			while (getchar() != '\n');
			break;
		case '\0':
			error("unexpected EOF");
		case '\n':
			continue;
		default:
			ungetc(c, cin);
			defclass();
			break;
		}
	}
}
int lgatflg 0;
lgate()
{
	char fname[20];
if (lgatflg) return;
lgatflg=1;
printf(-1, fname, "lex.%s.%c", label, ratfor? 'r' : 'c');
output = copen(fname, 'w');
printf( output, "#\n");
if (!ratfor)printf(output,"#");
printf(output, "define YYLMAX 200\n"); /* must go out first*/
}
