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