minix/external/bsd/flex/dist/examples/manual/cat.lex

46 lines
849 B
Text
Raw Normal View History

2012-06-06 16:10:32 +02:00
/*
* cat.lex: A demonstration of YY_NEW_FILE.
*/
%{
#include <stdio.h>
char **names = NULL;
int current = 1;
%}
%%
<<EOF>> {
current += 1;
if(names[current] != NULL){
yyin = fopen(names[current],"r");
if(yyin == NULL){
fprintf(stderr,"cat: unable to open %s\n",
names[current]);
yyterminate();
}
YY_NEW_FILE;
} else {
yyterminate();
}
}
%%
int main(int argc, char **argv)
{
if(argc < 2){
fprintf(stderr,"Usage: cat files....\n");
exit(1);
}
names = argv;
yyin = fopen(names[current],"r");
if(yyin == NULL){
fprintf(stderr,"cat: unable to open %s\n",
names[current]);
yyterminate();
}
yylex();
}