main.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * main.c
  3. *
  4. * Copyright (C) 2015 Alexander Andrejevic <theflash AT sdf DOT lonestar DOT org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>
  18. *
  19. * SPDX-License-Identifier: AGPL-3.0-or-later
  20. */
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <getopt.h>
  24. int main(int argc, char *argv[], char *envp[])
  25. {
  26. int verbose = 0;
  27. extern FILE *yyin;
  28. while (1)
  29. {
  30. int option_index;
  31. static struct option long_options[] =
  32. {
  33. { "verbose", no_argument, NULL, 'v'},
  34. { NULL, 0, NULL, 0 }
  35. };
  36. int choice = getopt_long(argc, argv, "v", long_options, &option_index);
  37. if (choice == -1) break;
  38. switch (choice)
  39. {
  40. case 'v':
  41. verbose++;
  42. break;
  43. }
  44. }
  45. if (optind == argc)
  46. {
  47. fprintf(stderr, "No input files specified.\n");
  48. return EXIT_FAILURE;
  49. }
  50. while (optind < argc)
  51. {
  52. char *filename = argv[optind++];
  53. yyin = fopen(filename, "r");
  54. if (yyin == NULL)
  55. {
  56. fprintf(stderr, "Cannot open input file: %s\n", filename);
  57. continue;
  58. }
  59. switch (yyparse())
  60. {
  61. case 0:
  62. if (verbose) fprintf(stdout, "%s: Done parsing.\n", filename);
  63. break;
  64. case 1:
  65. fprintf(stderr, "%s: errors encountered.", filename);
  66. break;
  67. case 2:
  68. fprintf(stderr, "%s: out of memory.\n", filename);
  69. break;
  70. }
  71. }
  72. return EXIT_SUCCESS;
  73. }