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