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