1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <getopt.h>
- int main(int argc, char *argv[], char *envp[])
- {
- int verbose = 0;
- extern FILE *yyin;
- while (1)
- {
- int option_index;
- static struct option long_options[] =
- {
- { "verbose", no_argument, NULL, 'v'},
- { NULL, 0, NULL, 0 }
- };
- int choice = getopt_long(argc, argv, "v", long_options, &option_index);
- if (choice == -1) break;
- switch (choice)
- {
- case 'v':
- verbose++;
- break;
- }
- }
- if (optind == argc)
- {
- fprintf(stderr, "No input files specified.\n");
- return EXIT_FAILURE;
- }
- while (optind < argc)
- {
- char *filename = argv[optind++];
- yyin = fopen(filename, "r");
- if (yyin == NULL)
- {
- fprintf(stderr, "Cannot open input file: %s\n", filename);
- continue;
- }
- switch (yyparse())
- {
- case 0:
- if (verbose) fprintf(stdout, "%s: Done parsing.\n", filename);
- break;
- case 1:
- fprintf(stderr, "%s: errors encountered.", filename);
- break;
- case 2:
- fprintf(stderr, "%s: out of memory.\n", filename);
- break;
- }
- }
- return EXIT_SUCCESS;
- }
|