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