flex/examples/manual/userinit.lex
Eric S. Raymond 8d0162b80a Update all the examples to use the new API elements.
Add a fully reentrant example.  And update to TODO file.
2020-10-12 21:07:14 -04:00

30 lines
515 B
Plaintext

%{
extern FILE *yyin;
void open_input_file(void)
{
char *file_name,buffer[1024];
yyin = NULL;
while(yyin == NULL){
printf("Input file: ");
file_name = fgets(buffer,1024,stdin);
if(file_name){
file_name[strlen(file_name)-1] = '\0';
yyin = fopen(file_name,"r");
if(yyin == NULL){
printf("Unable to open \"%s\"\n",file_name);
}
} else {
printf("stdin\n");
yyin = stdin;
break;
}
}
}
%}
%option user-init = "open_input_file();"
%%