]>
Commit | Line | Data |
---|---|---|
08721544 PE |
1 | /* Parse command line arguments for Bison. |
2 | ||
c932d613 | 3 | Copyright (C) 1984, 1986, 1989, 1992, 2000-2012 Free Software |
ea0a7676 | 4 | Foundation, Inc. |
3d8fc6ca | 5 | |
9f306f2a | 6 | This file is part of Bison, the GNU Compiler Compiler. |
3d8fc6ca | 7 | |
f16b0819 PE |
8 | This program is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation, either version 3 of the License, or | |
11 | (at your option) any later version. | |
3d8fc6ca | 12 | |
f16b0819 PE |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
3d8fc6ca | 17 | |
9f306f2a | 18 | You should have received a copy of the GNU General Public License |
f16b0819 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
3d8fc6ca | 20 | |
2cec9080 | 21 | #include <config.h> |
3d8fc6ca | 22 | #include "system.h" |
d4bd2295 | 23 | #include "output.h" |
d38a11a6 PE |
24 | |
25 | #include <argmatch.h> | |
d7e0a1a7 | 26 | #include <c-strcase.h> |
3b2942e6 | 27 | #include <configmake.h> |
d38a11a6 | 28 | #include <error.h> |
f47dbf6b PE |
29 | |
30 | /* Hack to get <getopt.h> to declare getopt with a prototype. */ | |
31 | #if lint && ! defined __GNU_LIBRARY__ | |
32 | # define __GNU_LIBRARY__ | |
33 | # define HACK_FOR___GNU_LIBRARY___PROTOTYPE 1 | |
34 | #endif | |
35 | ||
d38a11a6 PE |
36 | #include <getopt.h> |
37 | ||
f47dbf6b PE |
38 | #ifdef HACK_FOR___GNU_LIBRARY___PROTOTYPE |
39 | # undef __GNU_LIBRARY__ | |
40 | # undef HACK_FOR___GNU_LIBRARY___PROTOTYPE | |
41 | #endif | |
42 | ||
a055b2f0 AD |
43 | #include <progname.h> |
44 | ||
b0ce6046 | 45 | #include "complain.h" |
ec3bc396 | 46 | #include "files.h" |
d38a11a6 | 47 | #include "getargs.h" |
23ec25b7 | 48 | #include "muscle-tab.h" |
4c787a31 | 49 | #include "quote.h" |
d38a11a6 | 50 | #include "uniqstr.h" |
3d8fc6ca | 51 | |
e0992e54 | 52 | bool debug; |
d0829076 | 53 | bool defines_flag; |
4e83ea15 | 54 | bool graph_flag; |
41d7a5f2 | 55 | bool xml_flag; |
d0829076 PE |
56 | bool locations_flag; |
57 | bool no_lines_flag; | |
d0829076 PE |
58 | bool token_table_flag; |
59 | bool yacc_flag; /* for -y */ | |
4e83ea15 AD |
60 | |
61 | bool error_verbose = false; | |
d2729d44 | 62 | |
916708d5 AD |
63 | bool nondeterministic_parser = false; |
64 | bool glr_parser = false; | |
916708d5 | 65 | |
4e83ea15 AD |
66 | int report_flag = report_none; |
67 | int trace_flag = trace_none; | |
6f8bdce2 JD |
68 | int warnings_flag = warnings_conflicts_sr | warnings_conflicts_rr |
69 | | warnings_other; | |
4e83ea15 | 70 | |
0e021770 PE |
71 | static struct bison_language const valid_languages[] = { |
72 | { "c", "c-skel.m4", ".c", ".h", true }, | |
73 | { "c++", "c++-skel.m4", ".cc", ".hh", true }, | |
8405b70c | 74 | { "java", "java-skel.m4", ".java", ".java", false }, |
0e021770 PE |
75 | { "", "", "", "", false } |
76 | }; | |
77 | ||
4b1ebc49 | 78 | int skeleton_prio = default_prio; |
b0ce6046 | 79 | const char *skeleton = NULL; |
4b1ebc49 | 80 | int language_prio = default_prio; |
0e021770 | 81 | struct bison_language const *language = &valid_languages[0]; |
f6bd5427 | 82 | const char *include = NULL; |
b0ce6046 | 83 | |
273a74fa | 84 | |
7b42569e AD |
85 | /** Decode an option's set of keys. |
86 | * | |
87 | * \param option option being decoded. | |
07c39ae9 | 88 | * \param keys array of valid subarguments. |
7b42569e | 89 | * \param values array of corresponding (int) values. |
dab96632 | 90 | * \param all the all value. |
07c39ae9 | 91 | * \param flags the flags to update |
20cc7149 | 92 | * \param args comma separated list of effective subarguments to decode. |
7b42569e AD |
93 | * If 0, then activate all the flags. |
94 | * | |
20cc7149 | 95 | * If VALUE != 0 then KEY sets flags and no-KEY clears them. |
dab96632 JD |
96 | * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all |
97 | * flags from \c all. Thus no-none = all and no-all = none. | |
7b42569e | 98 | */ |
80ac75bc PE |
99 | static void |
100 | flags_argmatch (const char *option, | |
7b42569e | 101 | const char * const keys[], const int values[], |
dab96632 | 102 | int all, int *flags, char *args) |
7b42569e AD |
103 | { |
104 | if (args) | |
105 | { | |
106 | args = strtok (args, ","); | |
ba7560e2 | 107 | while (args) |
7b42569e | 108 | { |
20cc7149 DJ |
109 | int no = strncmp (args, "no-", 3) == 0 ? 3 : 0; |
110 | int value = XARGMATCH (option, args + no, keys, values); | |
7b42569e | 111 | if (value == 0) |
dab96632 JD |
112 | { |
113 | if (no) | |
114 | *flags |= all; | |
115 | else | |
116 | *flags &= ~all; | |
117 | } | |
7b42569e | 118 | else |
dab96632 JD |
119 | { |
120 | if (no) | |
121 | *flags &= ~value; | |
122 | else | |
123 | *flags |= value; | |
124 | } | |
eb095650 | 125 | args = strtok (NULL, ","); |
7b42569e | 126 | } |
7b42569e AD |
127 | } |
128 | else | |
dab96632 | 129 | *flags |= all; |
7b42569e AD |
130 | } |
131 | ||
80ac75bc | 132 | /** Decode a set of sub arguments. |
7b42569e AD |
133 | * |
134 | * \param FlagName the flag familly to update. | |
07c39ae9 | 135 | * \param Args the effective sub arguments to decode. |
7b42569e AD |
136 | * |
137 | * \arg FlagName_args the list of keys. | |
138 | * \arg FlagName_types the list of values. | |
dab96632 | 139 | * \arg FlagName_all the all value. |
7b42569e AD |
140 | * \arg FlagName_flag the flag to update. |
141 | */ | |
142 | #define FLAGS_ARGMATCH(FlagName, Args) \ | |
143 | flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \ | |
dab96632 | 144 | FlagName ## _all, &FlagName ## _flag, Args) |
7b42569e AD |
145 | |
146 | ||
b8a41559 AD |
147 | /*----------------------. |
148 | | --report's handling. | | |
149 | `----------------------*/ | |
150 | ||
151 | static const char * const report_args[] = | |
152 | { | |
153 | /* In a series of synonyms, present the most meaningful first, so | |
154 | that argmatch_valid be more readable. */ | |
155 | "none", | |
156 | "state", "states", | |
157 | "itemset", "itemsets", | |
158 | "lookahead", "lookaheads", "look-ahead", | |
159 | "solved", | |
160 | "all", | |
161 | 0 | |
162 | }; | |
163 | ||
164 | static const int report_types[] = | |
165 | { | |
166 | report_none, | |
167 | report_states, report_states, | |
168 | report_states | report_itemsets, report_states | report_itemsets, | |
169 | report_states | report_lookahead_tokens, | |
170 | report_states | report_lookahead_tokens, | |
171 | report_states | report_lookahead_tokens, | |
172 | report_states | report_solved_conflicts, | |
173 | report_all | |
174 | }; | |
175 | ||
176 | ARGMATCH_VERIFY (report_args, report_types); | |
177 | ||
b8a41559 | 178 | |
273a74fa AD |
179 | /*---------------------. |
180 | | --trace's handling. | | |
181 | `---------------------*/ | |
182 | ||
183 | static const char * const trace_args[] = | |
184 | { | |
185 | /* In a series of synonyms, present the most meaningful first, so | |
186 | that argmatch_valid be more readable. */ | |
b8a41559 | 187 | "none - no traces", |
c5e3e510 AD |
188 | "scan - grammar scanner traces", |
189 | "parse - grammar parser traces", | |
b8a41559 | 190 | "automaton - construction of the automaton", |
273a74fa | 191 | "bitsets - use of bitsets", |
b8a41559 | 192 | "grammar - reading, reducing the grammar", |
1509d42f | 193 | "resource - memory consumption (where available)", |
273a74fa | 194 | "sets - grammar sets: firsts, nullable etc.", |
c65e5292 | 195 | "muscles - m4 definitions passed to the skeleton", |
327afc7c AD |
196 | "tools - m4 invocation", |
197 | "m4 - m4 traces", | |
c5e3e510 AD |
198 | "skeleton - skeleton postprocessing", |
199 | "time - time consumption", | |
f805dfcb | 200 | "ielr - IELR conversion", |
273a74fa AD |
201 | "all - all of the above", |
202 | 0 | |
203 | }; | |
204 | ||
205 | static const int trace_types[] = | |
206 | { | |
207 | trace_none, | |
473d0a75 AD |
208 | trace_scan, |
209 | trace_parse, | |
273a74fa AD |
210 | trace_automaton, |
211 | trace_bitsets, | |
212 | trace_grammar, | |
213 | trace_resource, | |
214 | trace_sets, | |
c65e5292 | 215 | trace_muscles, |
273a74fa | 216 | trace_tools, |
327afc7c | 217 | trace_m4, |
c5e3e510 AD |
218 | trace_skeleton, |
219 | trace_time, | |
f805dfcb | 220 | trace_ielr, |
273a74fa AD |
221 | trace_all |
222 | }; | |
223 | ||
8a6f72f3 | 224 | ARGMATCH_VERIFY (trace_args, trace_types); |
273a74fa | 225 | |
7b42569e AD |
226 | |
227 | /*------------------------. | |
228 | | --warnings's handling. | | |
229 | `------------------------*/ | |
230 | ||
231 | static const char * const warnings_args[] = | |
273a74fa | 232 | { |
7b42569e AD |
233 | /* In a series of synonyms, present the most meaningful first, so |
234 | that argmatch_valid be more readable. */ | |
17bd8a73 JD |
235 | "none - no warnings", |
236 | "midrule-values - unset or unused midrule values", | |
44c124a3 | 237 | "yacc - incompatibilities with POSIX Yacc", |
6f8bdce2 JD |
238 | "conflicts-sr - S/R conflicts", |
239 | "conflicts-rr - R/R conflicts", | |
8ffd7912 | 240 | "other - all other warnings", |
17bd8a73 JD |
241 | "all - all of the above", |
242 | "error - warnings are errors", | |
7b42569e AD |
243 | 0 |
244 | }; | |
245 | ||
246 | static const int warnings_types[] = | |
247 | { | |
248 | warnings_none, | |
17bd8a73 | 249 | warnings_midrule_values, |
7b42569e | 250 | warnings_yacc, |
6f8bdce2 JD |
251 | warnings_conflicts_sr, |
252 | warnings_conflicts_rr, | |
8ffd7912 | 253 | warnings_other, |
89eb3c76 JD |
254 | warnings_all, |
255 | warnings_error | |
7b42569e AD |
256 | }; |
257 | ||
258 | ARGMATCH_VERIFY (warnings_args, warnings_types); | |
273a74fa AD |
259 | |
260 | ||
0e575721 AD |
261 | /*-------------------------------------------. |
262 | | Display the help message and exit STATUS. | | |
263 | `-------------------------------------------*/ | |
e79137ac | 264 | |
0df27e8b PE |
265 | static void usage (int) ATTRIBUTE_NORETURN; |
266 | ||
4a120d45 | 267 | static void |
0e575721 | 268 | usage (int status) |
cbd8ffc5 | 269 | { |
0e575721 AD |
270 | if (status != 0) |
271 | fprintf (stderr, _("Try `%s --help' for more information.\n"), | |
272 | program_name); | |
273 | else | |
274 | { | |
72183df4 DJ |
275 | /* For ../build-aux/cross-options.pl to work, use the format: |
276 | ^ -S, --long[=ARGS] (whitespace) | |
277 | A --long option is required. | |
278 | Otherwise, add exceptions to ../build-aux/cross-options.pl. */ | |
279 | ||
a92be413 | 280 | printf (_("Usage: %s [OPTION]... FILE\n"), program_name); |
0e575721 | 281 | fputs (_("\ |
51c7ca01 | 282 | Generate a deterministic LR or generalized LR (GLR) parser employing\n\ |
d89e48b3 JD |
283 | LALR(1), IELR(1), or canonical LR(1) parser tables. IELR(1) and\n\ |
284 | canonical LR(1) support is experimental.\n\ | |
a92be413 PE |
285 | \n\ |
286 | "), stdout); | |
9f306f2a | 287 | |
0e575721 | 288 | fputs (_("\ |
a92be413 | 289 | Mandatory arguments to long options are mandatory for short options too.\n\ |
8e55b3aa JD |
290 | "), stdout); |
291 | fputs (_("\ | |
292 | The same is true for optional arguments.\n\ | |
a92be413 | 293 | "), stdout); |
9f306f2a | 294 | |
0e575721 | 295 | fputs (_("\ |
a92be413 | 296 | \n\ |
9f306f2a | 297 | Operation modes:\n\ |
620b2e36 JD |
298 | -h, --help display this help and exit\n\ |
299 | -V, --version output version information and exit\n\ | |
300 | --print-localedir output directory containing locale-dependent data\n\ | |
301 | --print-datadir output directory containing skeletons and XSLT\n\ | |
302 | -y, --yacc emulate POSIX Yacc\n\ | |
303 | -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\ | |
a92be413 PE |
304 | \n\ |
305 | "), stdout); | |
9f306f2a | 306 | |
0e575721 | 307 | fputs (_("\ |
9f306f2a | 308 | Parser:\n\ |
34d41938 JD |
309 | -L, --language=LANGUAGE specify the output programming language\n\ |
310 | (this is an experimental feature)\n\ | |
311 | -S, --skeleton=FILE specify the skeleton to use\n\ | |
312 | -t, --debug instrument the parser for debugging\n\ | |
313 | --locations enable location support\n\ | |
4b3847c3 AD |
314 | -D, --define=NAME[=VALUE] similar to '%define NAME \"VALUE\"'\n\ |
315 | -F, --force-define=NAME[=VALUE] override '%define NAME \"VALUE\"'\n\ | |
34d41938 | 316 | -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\ |
4b3847c3 AD |
317 | deprecated by '-Dapi.prefix=PREFIX'\n\ |
318 | -l, --no-lines don't generate '#line' directives\n\ | |
34d41938 | 319 | -k, --token-table include a table of token names\n\ |
a92be413 | 320 | \n\ |
0e575721 | 321 | "), stdout); |
9f306f2a | 322 | |
8e55b3aa JD |
323 | /* Keep -d and --defines separate so that ../build-aux/cross-options.pl |
324 | * won't assume that -d also takes an argument. */ | |
0e575721 | 325 | fputs (_("\ |
9f306f2a | 326 | Output:\n\ |
620b2e36 JD |
327 | --defines[=FILE] also produce a header file\n\ |
328 | -d likewise but cannot specify FILE (for POSIX Yacc)\n\ | |
329 | -r, --report=THINGS also produce details on the automaton\n\ | |
330 | --report-file=FILE write report to FILE\n\ | |
331 | -v, --verbose same as `--report=state'\n\ | |
332 | -b, --file-prefix=PREFIX specify a PREFIX for output files\n\ | |
333 | -o, --output=FILE leave output to FILE\n\ | |
334 | -g, --graph[=FILE] also output a graph of the automaton\n\ | |
335 | -x, --xml[=FILE] also output an XML report of the automaton\n\ | |
336 | (the XML schema is experimental)\n\ | |
a92be413 | 337 | \n\ |
0e575721 | 338 | "), stdout); |
86eff183 | 339 | |
6aeb9c57 AD |
340 | fputs (_("\ |
341 | Warning categories include:\n\ | |
342 | `midrule-values' unset or unused midrule values\n\ | |
44c124a3 | 343 | `yacc' incompatibilities with POSIX Yacc\n\ |
6f8bdce2 JD |
344 | `conflicts-sr' S/R conflicts (enabled by default)\n\ |
345 | `conflicts-rr' R/R conflicts (enabled by default)\n\ | |
8ffd7912 | 346 | `other' all other warnings (enabled by default)\n\ |
6aeb9c57 AD |
347 | `all' all the warnings\n\ |
348 | `no-CATEGORY' turn off warnings in CATEGORY\n\ | |
349 | `none' turn off all the warnings\n\ | |
350 | `error' treat warnings as errors\n\ | |
66f0441d | 351 | \n\ |
6aeb9c57 AD |
352 | "), stdout); |
353 | ||
0e575721 | 354 | fputs (_("\ |
ec3bc396 AD |
355 | THINGS is a list of comma separated words that can include:\n\ |
356 | `state' describe the states\n\ | |
357 | `itemset' complete the core item sets with their closure\n\ | |
742e4900 | 358 | `lookahead' explicitly associate lookahead tokens to items\n\ |
b408954b | 359 | `solved' describe shift/reduce conflicts solving\n\ |
ec3bc396 AD |
360 | `all' include all the above information\n\ |
361 | `none' disable the report\n\ | |
0e575721 | 362 | "), stdout); |
9f306f2a | 363 | |
d740d2b5 AD |
364 | putc ('\n', stdout); |
365 | printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT); | |
366 | printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL); | |
367 | fputs (_("General help using GNU software: " | |
368 | "<http://www.gnu.org/gethelp/>.\n"), | |
369 | stdout); | |
370 | /* Don't output this redundant message for English locales. | |
371 | Note we still output for 'C' so that it gets included in the | |
372 | man page. */ | |
373 | const char *lc_messages = setlocale (LC_MESSAGES, NULL); | |
374 | if (lc_messages && strcmp (lc_messages, "en_")) | |
375 | /* TRANSLATORS: Replace LANG_CODE in this URL with your language | |
376 | code <http://translationproject.org/team/LANG_CODE.html> to | |
377 | form one of the URLs at http://translationproject.org/team/. | |
378 | Otherwise, replace the entire URL with your translation team's | |
379 | email address. */ | |
380 | fputs (_("Report translation bugs to " | |
381 | "<http://translationproject.org/team/>.\n"), stdout); | |
382 | fputs (_("For complete documentation, run: info bison.\n"), stdout); | |
0e575721 AD |
383 | } |
384 | ||
385 | exit (status); | |
cbd8ffc5 DM |
386 | } |
387 | ||
e79137ac AD |
388 | |
389 | /*------------------------------. | |
390 | | Display the version message. | | |
391 | `------------------------------*/ | |
392 | ||
393 | static void | |
0e575721 | 394 | version (void) |
e79137ac AD |
395 | { |
396 | /* Some efforts were made to ease the translators' task, please | |
397 | continue. */ | |
0e575721 AD |
398 | printf (_("bison (GNU Bison) %s"), VERSION); |
399 | putc ('\n', stdout); | |
400 | fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout); | |
401 | putc ('\n', stdout); | |
e79137ac | 402 | |
0e575721 | 403 | fprintf (stdout, |
a005a9c4 AD |
404 | _("Copyright (C) %d Free Software Foundation, Inc.\n"), |
405 | PACKAGE_COPYRIGHT_YEAR); | |
e79137ac AD |
406 | |
407 | fputs (_("\ | |
408 | This is free software; see the source for copying conditions. There is NO\n\ | |
409 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ | |
410 | "), | |
0e575721 | 411 | stdout); |
e79137ac AD |
412 | } |
413 | ||
414 | ||
0e021770 PE |
415 | /*-------------------------------------. |
416 | | --skeleton and --language handling. | | |
417 | `--------------------------------------*/ | |
418 | ||
419 | void | |
e186a284 | 420 | skeleton_arg (char const *arg, int prio, location loc) |
0e021770 PE |
421 | { |
422 | if (prio < skeleton_prio) | |
423 | { | |
424 | skeleton_prio = prio; | |
425 | skeleton = arg; | |
426 | } | |
427 | else if (prio == skeleton_prio) | |
c8bf65f0 | 428 | complain_at (loc, _("multiple skeleton declarations are invalid")); |
0e021770 PE |
429 | } |
430 | ||
431 | void | |
e186a284 | 432 | language_argmatch (char const *arg, int prio, location loc) |
0e021770 PE |
433 | { |
434 | char const *msg; | |
435 | ||
436 | if (prio < language_prio) | |
437 | { | |
438 | int i; | |
439 | for (i = 0; valid_languages[i].language[0]; i++) | |
abf3f74b JM |
440 | if (c_strcasecmp (arg, valid_languages[i].language) == 0) |
441 | { | |
442 | language_prio = prio; | |
443 | language = &valid_languages[i]; | |
444 | return; | |
445 | } | |
4c787a31 | 446 | msg = _("%s: invalid language"); |
0e021770 PE |
447 | } |
448 | else if (language_prio == prio) | |
449 | msg = _("multiple language declarations are invalid"); | |
450 | else | |
451 | return; | |
452 | ||
4c787a31 | 453 | complain_at (loc, msg, quotearg_colon (arg)); |
0e021770 PE |
454 | } |
455 | ||
e79137ac AD |
456 | /*----------------------. |
457 | | Process the options. | | |
458 | `----------------------*/ | |
459 | ||
7020f1e9 AD |
460 | /* Shorts options. |
461 | Should be computed from long_options. */ | |
462 | static char const short_options[] = | |
e14c6831 | 463 | "D:" |
34d41938 | 464 | "F:" |
7020f1e9 AD |
465 | "L:" |
466 | "S:" | |
467 | "T::" | |
468 | "V" | |
8e55b3aa | 469 | "W::" |
7020f1e9 AD |
470 | "b:" |
471 | "d" | |
472 | "e" | |
473 | "g::" | |
474 | "h" | |
475 | "k" | |
476 | "l" | |
477 | "n" | |
478 | "o:" | |
479 | "p:" | |
480 | "r:" | |
481 | "t" | |
482 | "v" | |
483 | "x::" | |
484 | "y" | |
485 | ; | |
e2aaf4c4 | 486 | |
d0829076 PE |
487 | /* Values for long options that do not have single-letter equivalents. */ |
488 | enum | |
489 | { | |
f7ab6a50 | 490 | LOCATIONS_OPTION = CHAR_MAX + 1, |
d4bd2295 | 491 | PRINT_LOCALEDIR_OPTION, |
1bb2bd75 JD |
492 | PRINT_DATADIR_OPTION, |
493 | REPORT_FILE_OPTION | |
d0829076 PE |
494 | }; |
495 | ||
e2aaf4c4 AD |
496 | static struct option const long_options[] = |
497 | { | |
498 | /* Operation modes. */ | |
7b42569e AD |
499 | { "help", no_argument, 0, 'h' }, |
500 | { "version", no_argument, 0, 'V' }, | |
501 | { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION }, | |
d4bd2295 | 502 | { "print-datadir", no_argument, 0, PRINT_DATADIR_OPTION }, |
7b42569e | 503 | { "warnings", optional_argument, 0, 'W' }, |
e2aaf4c4 AD |
504 | |
505 | /* Parser. */ | |
506 | { "name-prefix", required_argument, 0, 'p' }, | |
507 | { "include", required_argument, 0, 'I' }, | |
508 | ||
509 | /* Output. */ | |
510 | { "file-prefix", required_argument, 0, 'b' }, | |
511 | { "output", required_argument, 0, 'o' }, | |
512 | { "output-file", required_argument, 0, 'o' }, | |
513 | { "graph", optional_argument, 0, 'g' }, | |
41d7a5f2 | 514 | { "xml", optional_argument, 0, 'x' }, |
e2aaf4c4 | 515 | { "report", required_argument, 0, 'r' }, |
1bb2bd75 | 516 | { "report-file", required_argument, 0, REPORT_FILE_OPTION }, |
e2aaf4c4 AD |
517 | { "verbose", no_argument, 0, 'v' }, |
518 | ||
519 | /* Hidden. */ | |
273a74fa | 520 | { "trace", optional_argument, 0, 'T' }, |
e2aaf4c4 | 521 | |
e2aaf4c4 AD |
522 | /* Output. */ |
523 | { "defines", optional_argument, 0, 'd' }, | |
524 | ||
525 | /* Operation modes. */ | |
526 | { "fixed-output-files", no_argument, 0, 'y' }, | |
527 | { "yacc", no_argument, 0, 'y' }, | |
528 | ||
529 | /* Parser. */ | |
530 | { "debug", no_argument, 0, 't' }, | |
e14c6831 | 531 | { "define", required_argument, 0, 'D' }, |
34d41938 | 532 | { "force-define", required_argument, 0, 'F' }, |
d0829076 | 533 | { "locations", no_argument, 0, LOCATIONS_OPTION }, |
e2aaf4c4 | 534 | { "no-lines", no_argument, 0, 'l' }, |
e2aaf4c4 AD |
535 | { "raw", no_argument, 0, 0 }, |
536 | { "skeleton", required_argument, 0, 'S' }, | |
0e021770 | 537 | { "language", required_argument, 0, 'L' }, |
e2aaf4c4 AD |
538 | { "token-table", no_argument, 0, 'k' }, |
539 | ||
540 | {0, 0, 0, 0} | |
541 | }; | |
542 | ||
ae404801 AD |
543 | /* Under DOS, there is no difference on the case. This can be |
544 | troublesome when looking for `.tab' etc. */ | |
545 | #ifdef MSDOS | |
546 | # define AS_FILE_NAME(File) (strlwr (File), (File)) | |
547 | #else | |
548 | # define AS_FILE_NAME(File) (File) | |
549 | #endif | |
550 | ||
e14c6831 AD |
551 | /* Build a location for the current command line argument. */ |
552 | static | |
553 | location | |
6f5be1ab | 554 | command_line_location (void) |
e14c6831 AD |
555 | { |
556 | location res; | |
557 | /* "<command line>" is used in GCC's messages about -D. */ | |
558 | boundary_set (&res.start, uniqstr_new ("<command line>"), optind, -1); | |
559 | res.end = res.start; | |
560 | return res; | |
561 | } | |
562 | ||
563 | ||
3d8fc6ca | 564 | void |
d2729d44 | 565 | getargs (int argc, char *argv[]) |
3d8fc6ca | 566 | { |
1916f98e | 567 | int c; |
3d8fc6ca | 568 | |
08721544 PE |
569 | while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) |
570 | != -1) | |
cd5bd6ac AD |
571 | switch (c) |
572 | { | |
e14c6831 AD |
573 | /* ASCII Sorting for short options (i.e., upper case then |
574 | lower case), and then long-only options. */ | |
575 | ||
cd5bd6ac AD |
576 | case 0: |
577 | /* Certain long options cause getopt_long to return 0. */ | |
578 | break; | |
579 | ||
e14c6831 | 580 | case 'D': /* -DNAME[=VALUE]. */ |
34d41938 | 581 | case 'F': /* -FNAME[=VALUE]. */ |
e14c6831 AD |
582 | { |
583 | char* name = optarg; | |
d143e9c3 | 584 | char* value = mbschr (optarg, '='); |
e14c6831 | 585 | if (value) |
c4eb1e84 | 586 | *value++ = 0; |
10fa0146 | 587 | muscle_percent_define_insert (name, command_line_location (), |
34d41938 JD |
588 | value ? value : "", |
589 | c == 'D' ? MUSCLE_PERCENT_DEFINE_D | |
590 | : MUSCLE_PERCENT_DEFINE_F); | |
e14c6831 | 591 | } |
22c2cbc0 AD |
592 | break; |
593 | ||
8e55b3aa JD |
594 | case 'I': |
595 | include = AS_FILE_NAME (optarg); | |
41d7a5f2 PE |
596 | break; |
597 | ||
0e021770 | 598 | case 'L': |
e186a284 AD |
599 | language_argmatch (optarg, command_line_prio, |
600 | command_line_location ()); | |
0e021770 PE |
601 | break; |
602 | ||
cd5bd6ac | 603 | case 'S': |
e186a284 AD |
604 | skeleton_arg (AS_FILE_NAME (optarg), command_line_prio, |
605 | command_line_location ()); | |
cd5bd6ac AD |
606 | break; |
607 | ||
8e55b3aa JD |
608 | case 'T': |
609 | FLAGS_ARGMATCH (trace, optarg); | |
f6bd5427 MA |
610 | break; |
611 | ||
8e55b3aa JD |
612 | case 'V': |
613 | version (); | |
614 | exit (EXIT_SUCCESS); | |
615 | ||
616 | case 'W': | |
dab96632 | 617 | FLAGS_ARGMATCH (warnings, optarg); |
8e55b3aa JD |
618 | break; |
619 | ||
620 | case 'b': | |
621 | spec_file_prefix = AS_FILE_NAME (optarg); | |
622 | break; | |
623 | ||
e14c6831 AD |
624 | case 'd': |
625 | /* Here, the -d and --defines options are differentiated. */ | |
626 | defines_flag = true; | |
627 | if (optarg) | |
0b7fba13 AD |
628 | { |
629 | free (spec_defines_file); | |
630 | spec_defines_file = xstrdup (AS_FILE_NAME (optarg)); | |
631 | } | |
e14c6831 AD |
632 | break; |
633 | ||
8e55b3aa JD |
634 | case 'g': |
635 | graph_flag = true; | |
636 | if (optarg) | |
0b7fba13 AD |
637 | { |
638 | free (spec_graph_file); | |
639 | spec_graph_file = xstrdup (AS_FILE_NAME (optarg)); | |
640 | } | |
cd5bd6ac AD |
641 | break; |
642 | ||
8e55b3aa JD |
643 | case 'h': |
644 | usage (EXIT_SUCCESS); | |
645 | ||
7b42569e AD |
646 | case 'k': |
647 | token_table_flag = true; | |
648 | break; | |
649 | ||
cd5bd6ac | 650 | case 'l': |
d0829076 PE |
651 | no_lines_flag = true; |
652 | break; | |
653 | ||
7b42569e AD |
654 | case 'o': |
655 | spec_outfile = AS_FILE_NAME (optarg); | |
cd5bd6ac AD |
656 | break; |
657 | ||
7b42569e AD |
658 | case 'p': |
659 | spec_name_prefix = optarg; | |
660 | break; | |
661 | ||
662 | case 'r': | |
663 | FLAGS_ARGMATCH (report, optarg); | |
664 | break; | |
665 | ||
cd5bd6ac | 666 | case 't': |
e0992e54 | 667 | debug = true; |
cd5bd6ac AD |
668 | break; |
669 | ||
7b42569e AD |
670 | case 'v': |
671 | report_flag |= report_states; | |
cd5bd6ac AD |
672 | break; |
673 | ||
8e55b3aa JD |
674 | case 'x': |
675 | xml_flag = true; | |
676 | if (optarg) | |
0b7fba13 AD |
677 | { |
678 | free (spec_xml_file); | |
679 | spec_xml_file = xstrdup (AS_FILE_NAME (optarg)); | |
680 | } | |
cd5bd6ac AD |
681 | break; |
682 | ||
8e55b3aa JD |
683 | case 'y': |
684 | yacc_flag = true; | |
ec3bc396 AD |
685 | break; |
686 | ||
7b42569e AD |
687 | case LOCATIONS_OPTION: |
688 | locations_flag = true; | |
273a74fa AD |
689 | break; |
690 | ||
7b42569e AD |
691 | case PRINT_LOCALEDIR_OPTION: |
692 | printf ("%s\n", LOCALEDIR); | |
693 | exit (EXIT_SUCCESS); | |
694 | ||
d4bd2295 JD |
695 | case PRINT_DATADIR_OPTION: |
696 | printf ("%s\n", compute_pkgdatadir ()); | |
697 | exit (EXIT_SUCCESS); | |
698 | ||
8e55b3aa | 699 | case REPORT_FILE_OPTION: |
0b7fba13 | 700 | free (spec_verbose_file); |
8e55b3aa JD |
701 | spec_verbose_file = xstrdup (AS_FILE_NAME (optarg)); |
702 | break; | |
703 | ||
cd5bd6ac | 704 | default: |
0df27e8b | 705 | usage (EXIT_FAILURE); |
cd5bd6ac | 706 | } |
3d8fc6ca | 707 | |
a4b6efd4 | 708 | if (argc - optind != 1) |
3d8fc6ca | 709 | { |
a4b6efd4 | 710 | if (argc - optind < 1) |
4c787a31 | 711 | error (0, 0, _("%s: missing operand"), quotearg_colon (argv[argc - 1])); |
a4b6efd4 | 712 | else |
4c787a31 | 713 | error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); |
0e575721 | 714 | usage (EXIT_FAILURE); |
3d8fc6ca | 715 | } |
3d8fc6ca | 716 | |
d38a11a6 | 717 | current_file = grammar_file = uniqstr_new (argv[optind]); |
75c21b61 | 718 | MUSCLE_INSERT_C_STRING ("file_name", grammar_file); |
3d8fc6ca | 719 | } |
812775a0 JD |
720 | |
721 | void | |
722 | tr (char *s, char from, char to) | |
723 | { | |
724 | for (; *s; s++) | |
725 | if (*s == from) | |
726 | *s = to; | |
727 | } |