getargs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Parse command line arguments for bison,
  2. Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
  3. Modified (1992) from bison-1.19 by
  4. Wilfred J. Hansen (wjh+@cmu.edu)
  5. Andrew Consortium, Carnegie Mellon University
  6. This file is part of Bison, the GNU Compiler Compiler.
  7. Bison is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. Bison 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 General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with Bison; see the file COPYING. If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  18. #include <stdio.h>
  19. #include "getopt.h"
  20. #include "system.h"
  21. #include "files.h"
  22. int verboseflag;
  23. int definesflag;
  24. int debugflag;
  25. int nolinesflag;
  26. int noparserflag = 0;
  27. int toknumflag = 0;
  28. int rawtoknumflag = 0;
  29. char *spec_name_prefix; /* for -p. */
  30. char *spec_file_prefix; /* for -b. */
  31. extern int fixed_outfiles;/* for -y */
  32. extern char *program_name;
  33. extern char *version_string;
  34. extern void warns(); /* main.c */
  35. struct option longopts[] =
  36. {
  37. {"debug", 0, &debugflag, 1},
  38. {"defines", 0, &definesflag, 1},
  39. {"file-prefix", 1, 0, 'b'},
  40. {"fixed-output-files", 0, &fixed_outfiles, 1},
  41. {"help", 0, 0, 'h'},
  42. {"name-prefix", 1, 0, 'a'},
  43. {"no-lines", 0, &nolinesflag, 1},
  44. {"no-parser", 0, &noparserflag, 1},
  45. {"output", 1, 0, 'o'},
  46. {"output-file", 1, 0, 'o'},
  47. {"raw", 0, &rawtoknumflag, 1},
  48. {"token-table", 0, &toknumflag, 1},
  49. {"verbose", 0, &verboseflag, 1},
  50. {"version", 0, 0, 'V'},
  51. {"yacc", 0, &fixed_outfiles, 1},
  52. {0, 0, 0, 0}
  53. };
  54. void
  55. usage (stream)
  56. FILE *stream;
  57. {
  58. fprintf (stream, "\
  59. Usage: %s [-dhklntvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
  60. [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
  61. [--verbose] [--version] [--help] [--yacc]\n\
  62. [--no-parser] [--token-table]\n\
  63. [--file-prefix=prefix] [--name-prefix=prefix]\n\
  64. [--output=outfile] grammar-file\n",
  65. program_name);
  66. }
  67. void
  68. getargs(argc, argv)
  69. int argc;
  70. char *argv[];
  71. {
  72. register int c;
  73. verboseflag = 0;
  74. definesflag = 0;
  75. debugflag = 0;
  76. noparserflag = 0;
  77. rawtoknumflag = 0;
  78. toknumflag = 0;
  79. fixed_outfiles = 0;
  80. while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
  81. != EOF)
  82. {
  83. switch (c)
  84. {
  85. case 0:
  86. /* Certain long options cause getopt_long to return 0. */
  87. break;
  88. case 'y':
  89. fixed_outfiles = 1;
  90. break;
  91. case 'h':
  92. usage (stdout);
  93. exit (0);
  94. case 'V':
  95. printf ("%s", version_string);
  96. exit (0);
  97. case 'v':
  98. verboseflag = 1;
  99. break;
  100. case 'd':
  101. definesflag = 1;
  102. break;
  103. case 'l':
  104. nolinesflag = 1;
  105. break;
  106. case 'k':
  107. toknumflag = 1;
  108. break;
  109. case 'r':
  110. rawtoknumflag = 1;
  111. break;
  112. case 'n':
  113. noparserflag = 1;
  114. break;
  115. case 't':
  116. debugflag = 1;
  117. break;
  118. case 'o':
  119. spec_outfile = optarg;
  120. break;
  121. case 'b':
  122. spec_file_prefix = optarg;
  123. break;
  124. case 'p':
  125. spec_name_prefix = optarg;
  126. break;
  127. default:
  128. usage (stderr);
  129. exit (1);
  130. }
  131. }
  132. if (optind == argc)
  133. {
  134. fprintf(stderr, "%s: no grammar file given\n", program_name);
  135. exit(1);
  136. }
  137. if (optind < argc - 1)
  138. fprintf(stderr, "%s: extra arguments ignored after '%s'\n",
  139. program_name, argv[optind]);
  140. infile = argv[optind];
  141. }