panos@utcsri.UUCP (Panos Economopoulos) (11/05/85)
#include <stdio.h> int curarg, /* index into argv[] for argument (file) currently * under processing */ maxarg; /* the maximum value that curarg can take */ char **g_argv; /* global (external) version of argv[] */ main(argc, argv) int argc; char *argv[]; { int nofiles; /* boolean flag */ curarg = 0 ; /* this is BEFORE processing of the first * argument (file) has begun */ maxarg = argc-1 ; g_argv = argv ; nofiles = yywrap() ; /* open first argument (file), or do * nothing if no arguments exist */ if ( maxarg>0 && nofiles ) { fprintf(stderr, "grk: all arguments were bad -- quit.\n"); exit(1); } yylex() ; /* call the LEX-scanner; IT will call yywrap() * when each end-of-file is reached */ } yywrap() { if ( curarg++ < maxarg ) /* more file(s) to be opened */ { if ( freopen(g_argv[curarg], "r", stdin) != NULL ) /* default LEX-scanner reads from standard- * input; thus, we "re-open" stdin -- the * alternative would be to redefine yyin */ return(0); /* successful opening -- else: */ fprintf(stderr, "grk: can't open %s -- discarded it.\n", g_argv[curarg] ); return(yywrap()); /* try to open the next one */ } else /* no more files to be opened */ return(1); } -- Panos Economopoulos UUCP: {decvax,linus,ihnp4,uw-beaver,allegra,utzoo}!utcsri!panos CSNET: panos@toronto