]> git.saurik.com Git - bison.git/blame - src/getargs.c
style: minor changes
[bison.git] / src / getargs.c
CommitLineData
08721544
PE
1/* Parse command line arguments for Bison.
2
7d6bad19 3 Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 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
9c4788b7 49int feature_flag = feature_caret;
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",
cc2235ac 255 "precedence - useless precedence and associativity",
c39014ae 256 "other - all other warnings",
17bd8a73
JD
257 "all - all of the above",
258 "error - warnings are errors",
7b42569e
AD
259 0
260};
261
262static const int warnings_types[] =
263{
327db05b
VS
264 Wnone,
265 Wmidrule_values,
266 Wyacc,
267 Wconflicts_sr,
268 Wconflicts_rr,
518e8830 269 Wdeprecated,
cc2235ac 270 Wprecedence,
327db05b
VS
271 Wother,
272 Wall,
273 Werror
7b42569e
AD
274};
275
276ARGMATCH_VERIFY (warnings_args, warnings_types);
273a74fa 277
0db26489
TR
278/*-----------------------.
279| --feature's handling. |
280`-----------------------*/
281
282static const char * const feature_args[] =
283{
284 "none",
285 "caret", "diagnostics-show-caret",
286 "all",
287 0
288};
289
290static const int feature_types[] =
291{
292 feature_none,
293 feature_caret, feature_caret,
294 feature_all
295};
296
297ARGMATCH_VERIFY (feature_args, feature_types);
273a74fa 298
0e575721
AD
299/*-------------------------------------------.
300| Display the help message and exit STATUS. |
301`-------------------------------------------*/
e79137ac 302
0df27e8b
PE
303static void usage (int) ATTRIBUTE_NORETURN;
304
4a120d45 305static void
0e575721 306usage (int status)
cbd8ffc5 307{
0e575721
AD
308 if (status != 0)
309 fprintf (stderr, _("Try `%s --help' for more information.\n"),
e9690142 310 program_name);
0e575721
AD
311 else
312 {
a7c09cba 313 /* For ../build-aux/cross-options.pl to work, use the format:
e9690142
JD
314 ^ -S, --long[=ARGS] (whitespace)
315 A --long option is required.
316 Otherwise, add exceptions to ../build-aux/cross-options.pl. */
a7c09cba 317
a92be413 318 printf (_("Usage: %s [OPTION]... FILE\n"), program_name);
0e575721 319 fputs (_("\
9dc3ee6d 320Generate a deterministic LR or generalized LR (GLR) parser employing\n\
af28d414
JD
321LALR(1), IELR(1), or canonical LR(1) parser tables. IELR(1) and\n\
322canonical LR(1) support is experimental.\n\
a92be413
PE
323\n\
324"), stdout);
9f306f2a 325
0e575721 326 fputs (_("\
a92be413 327Mandatory arguments to long options are mandatory for short options too.\n\
8e55b3aa
JD
328"), stdout);
329 fputs (_("\
330The same is true for optional arguments.\n\
a92be413 331"), stdout);
9f306f2a 332
0e575721 333 fputs (_("\
a92be413 334\n\
9f306f2a 335Operation modes:\n\
feeb56cd
JD
336 -h, --help display this help and exit\n\
337 -V, --version output version information and exit\n\
338 --print-localedir output directory containing locale-dependent data\n\
339 --print-datadir output directory containing skeletons and XSLT\n\
340 -y, --yacc emulate POSIX Yacc\n\
341 -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\
0db26489 342 -f, --feature[=FEATURE] activate miscellaneous features\n\
a92be413
PE
343\n\
344"), stdout);
9f306f2a 345
0e575721 346 fputs (_("\
9f306f2a 347Parser:\n\
de5ab940 348 -L, --language=LANGUAGE specify the output programming language\n\
de5ab940
JD
349 -S, --skeleton=FILE specify the skeleton to use\n\
350 -t, --debug instrument the parser for tracing\n\
351 same as `-Dparse.trace'\n\
352 --locations enable location support\n\
4b3847c3
AD
353 -D, --define=NAME[=VALUE] similar to '%define NAME \"VALUE\"'\n\
354 -F, --force-define=NAME[=VALUE] override '%define NAME \"VALUE\"'\n\
de5ab940 355 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
4b3847c3
AD
356 deprecated by '-Dapi.prefix=PREFIX'\n\
357 -l, --no-lines don't generate '#line' directives\n\
de5ab940 358 -k, --token-table include a table of token names\n\
0e575721 359"), stdout);
0db26489 360 putc ('\n', stdout);
9f306f2a 361
8e55b3aa
JD
362 /* Keep -d and --defines separate so that ../build-aux/cross-options.pl
363 * won't assume that -d also takes an argument. */
0e575721 364 fputs (_("\
9f306f2a 365Output:\n\
feeb56cd
JD
366 --defines[=FILE] also produce a header file\n\
367 -d likewise but cannot specify FILE (for POSIX Yacc)\n\
368 -r, --report=THINGS also produce details on the automaton\n\
369 --report-file=FILE write report to FILE\n\
370 -v, --verbose same as `--report=state'\n\
371 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
372 -o, --output=FILE leave output to FILE\n\
373 -g, --graph[=FILE] also output a graph of the automaton\n\
374 -x, --xml[=FILE] also output an XML report of the automaton\n\
375 (the XML schema is experimental)\n\
0e575721 376"), stdout);
0db26489 377 putc ('\n', stdout);
86eff183 378
6aeb9c57
AD
379 fputs (_("\
380Warning categories include:\n\
9503b0a4
TR
381 `midrule-values' unset or unused midrule values\n\
382 `yacc' incompatibilities with POSIX Yacc\n\
383 `conflicts-sr' S/R conflicts (enabled by default)\n\
384 `conflicts-rr' R/R conflicts (enabled by default)\n\
385 `deprecated' obsolete constructs\n\
cc2235ac 386 `precedence' useless precedence and associativity\n\
9503b0a4
TR
387 `other' all other warnings (enabled by default)\n\
388 `all' all the warnings\n\
389 `no-CATEGORY' turn off warnings in CATEGORY\n\
390 `none' turn off all the warnings\n\
391 `error[=CATEGORY]' treat warnings as errors\n\
6aeb9c57 392"), stdout);
bd526380 393 putc ('\n', stdout);
6aeb9c57 394
0e575721 395 fputs (_("\
ec3bc396
AD
396THINGS is a list of comma separated words that can include:\n\
397 `state' describe the states\n\
398 `itemset' complete the core item sets with their closure\n\
742e4900 399 `lookahead' explicitly associate lookahead tokens to items\n\
b408954b 400 `solved' describe shift/reduce conflicts solving\n\
ec3bc396
AD
401 `all' include all the above information\n\
402 `none' disable the report\n\
0e575721 403"), stdout);
0db26489
TR
404 putc ('\n', stdout);
405
406 fputs (_("\
407FEATURE is a list of comma separated words that can include:\n\
408 `caret' show errors with carets\n\
409 `all' all of the above\n\
410 `none' disable all of the above\n\
411 "), stdout);
9f306f2a 412
d740d2b5
AD
413 putc ('\n', stdout);
414 printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
415 printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL);
416 fputs (_("General help using GNU software: "
417 "<http://www.gnu.org/gethelp/>.\n"),
418 stdout);
419 /* Don't output this redundant message for English locales.
420 Note we still output for 'C' so that it gets included in the
421 man page. */
422 const char *lc_messages = setlocale (LC_MESSAGES, NULL);
6b5a7489 423 if (lc_messages && !STREQ (lc_messages, "en_"))
d740d2b5
AD
424 /* TRANSLATORS: Replace LANG_CODE in this URL with your language
425 code <http://translationproject.org/team/LANG_CODE.html> to
426 form one of the URLs at http://translationproject.org/team/.
427 Otherwise, replace the entire URL with your translation team's
428 email address. */
429 fputs (_("Report translation bugs to "
430 "<http://translationproject.org/team/>.\n"), stdout);
431 fputs (_("For complete documentation, run: info bison.\n"), stdout);
0e575721
AD
432 }
433
434 exit (status);
cbd8ffc5
DM
435}
436
e79137ac
AD
437
438/*------------------------------.
439| Display the version message. |
440`------------------------------*/
441
442static void
0e575721 443version (void)
e79137ac
AD
444{
445 /* Some efforts were made to ease the translators' task, please
446 continue. */
0e575721
AD
447 printf (_("bison (GNU Bison) %s"), VERSION);
448 putc ('\n', stdout);
449 fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout);
450 putc ('\n', stdout);
e79137ac 451
0e575721 452 fprintf (stdout,
e9690142
JD
453 _("Copyright (C) %d Free Software Foundation, Inc.\n"),
454 PACKAGE_COPYRIGHT_YEAR);
e79137ac
AD
455
456 fputs (_("\
457This is free software; see the source for copying conditions. There is NO\n\
458warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
459"),
e9690142 460 stdout);
e79137ac
AD
461}
462
463
0e021770
PE
464/*-------------------------------------.
465| --skeleton and --language handling. |
466`--------------------------------------*/
467
468void
5a893c2b 469skeleton_arg (char const *arg, int prio, location loc)
0e021770
PE
470{
471 if (prio < skeleton_prio)
472 {
473 skeleton_prio = prio;
474 skeleton = arg;
475 }
476 else if (prio == skeleton_prio)
bb8e56ff
TR
477 complain (&loc, complaint,
478 _("multiple skeleton declarations are invalid"));
0e021770
PE
479}
480
481void
5a893c2b 482language_argmatch (char const *arg, int prio, location loc)
0e021770
PE
483{
484 char const *msg;
485
486 if (prio < language_prio)
487 {
488 int i;
489 for (i = 0; valid_languages[i].language[0]; i++)
e9690142
JD
490 if (c_strcasecmp (arg, valid_languages[i].language) == 0)
491 {
492 language_prio = prio;
493 language = &valid_languages[i];
494 return;
495 }
4a9cd8f2 496 msg = _("%s: invalid language");
0e021770
PE
497 }
498 else if (language_prio == prio)
499 msg = _("multiple language declarations are invalid");
500 else
501 return;
502
bb8e56ff 503 complain (&loc, complaint, msg, quotearg_colon (arg));
0e021770
PE
504}
505
e79137ac
AD
506/*----------------------.
507| Process the options. |
508`----------------------*/
509
7020f1e9
AD
510/* Shorts options.
511 Should be computed from long_options. */
512static char const short_options[] =
58697c6d 513 "D:"
de5ab940 514 "F:"
7020f1e9
AD
515 "L:"
516 "S:"
517 "T::"
518 "V"
8e55b3aa 519 "W::"
7020f1e9
AD
520 "b:"
521 "d"
0db26489 522 "f::"
7020f1e9
AD
523 "e"
524 "g::"
525 "h"
526 "k"
527 "l"
528 "n"
529 "o:"
530 "p:"
531 "r:"
532 "t"
533 "v"
534 "x::"
535 "y"
536 ;
e2aaf4c4 537
d0829076
PE
538/* Values for long options that do not have single-letter equivalents. */
539enum
540{
f7ab6a50 541 LOCATIONS_OPTION = CHAR_MAX + 1,
d4bd2295 542 PRINT_LOCALEDIR_OPTION,
1bb2bd75
JD
543 PRINT_DATADIR_OPTION,
544 REPORT_FILE_OPTION
d0829076
PE
545};
546
e2aaf4c4
AD
547static struct option const long_options[] =
548{
549 /* Operation modes. */
e9690142
JD
550 { "help", no_argument, 0, 'h' },
551 { "version", no_argument, 0, 'V' },
552 { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
553 { "print-datadir", no_argument, 0, PRINT_DATADIR_OPTION },
7b42569e 554 { "warnings", optional_argument, 0, 'W' },
e2aaf4c4
AD
555
556 /* Parser. */
e9690142 557 { "name-prefix", required_argument, 0, 'p' },
e2aaf4c4
AD
558 { "include", required_argument, 0, 'I' },
559
560 /* Output. */
e9690142
JD
561 { "file-prefix", required_argument, 0, 'b' },
562 { "output", required_argument, 0, 'o' },
563 { "output-file", required_argument, 0, 'o' },
564 { "graph", optional_argument, 0, 'g' },
41d7a5f2 565 { "xml", optional_argument, 0, 'x' },
e9690142 566 { "report", required_argument, 0, 'r' },
1bb2bd75 567 { "report-file", required_argument, 0, REPORT_FILE_OPTION },
e9690142 568 { "verbose", no_argument, 0, 'v' },
e2aaf4c4
AD
569
570 /* Hidden. */
273a74fa 571 { "trace", optional_argument, 0, 'T' },
e2aaf4c4 572
e2aaf4c4
AD
573 /* Output. */
574 { "defines", optional_argument, 0, 'd' },
e35cd6de 575 { "feature", optional_argument, 0, 'f' },
e2aaf4c4
AD
576
577 /* Operation modes. */
578 { "fixed-output-files", no_argument, 0, 'y' },
e9690142 579 { "yacc", no_argument, 0, 'y' },
e2aaf4c4
AD
580
581 /* Parser. */
e9690142
JD
582 { "debug", no_argument, 0, 't' },
583 { "define", required_argument, 0, 'D' },
de5ab940 584 { "force-define", required_argument, 0, 'F' },
e9690142 585 { "locations", no_argument, 0, LOCATIONS_OPTION },
e2aaf4c4 586 { "no-lines", no_argument, 0, 'l' },
e2aaf4c4
AD
587 { "raw", no_argument, 0, 0 },
588 { "skeleton", required_argument, 0, 'S' },
0e021770 589 { "language", required_argument, 0, 'L' },
e2aaf4c4
AD
590 { "token-table", no_argument, 0, 'k' },
591
592 {0, 0, 0, 0}
593};
594
ae404801
AD
595/* Under DOS, there is no difference on the case. This can be
596 troublesome when looking for `.tab' etc. */
597#ifdef MSDOS
598# define AS_FILE_NAME(File) (strlwr (File), (File))
599#else
600# define AS_FILE_NAME(File) (File)
601#endif
602
58697c6d
AD
603/* Build a location for the current command line argument. */
604static
605location
d73e55e0 606command_line_location (void)
58697c6d
AD
607{
608 location res;
609 /* "<command line>" is used in GCC's messages about -D. */
a37131cc 610 boundary_set (&res.start, uniqstr_new ("<command line>"), optind - 1, -1);
58697c6d
AD
611 res.end = res.start;
612 return res;
613}
614
615
3d8fc6ca 616void
d2729d44 617getargs (int argc, char *argv[])
3d8fc6ca 618{
1916f98e 619 int c;
3d8fc6ca 620
08721544 621 while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
e9690142 622 != -1)
cd5bd6ac
AD
623 switch (c)
624 {
58697c6d
AD
625 /* ASCII Sorting for short options (i.e., upper case then
626 lower case), and then long-only options. */
627
cd5bd6ac 628 case 0:
e9690142
JD
629 /* Certain long options cause getopt_long to return 0. */
630 break;
cd5bd6ac 631
58697c6d 632 case 'D': /* -DNAME[=VALUE]. */
de5ab940 633 case 'F': /* -FNAME[=VALUE]. */
58697c6d
AD
634 {
635 char* name = optarg;
84526bf3 636 char* value = strchr (optarg, '=');
58697c6d 637 if (value)
9ce405ce 638 *value++ = 0;
a8beef7e 639 muscle_percent_define_insert (name, command_line_location (),
de5ab940
JD
640 value ? value : "",
641 c == 'D' ? MUSCLE_PERCENT_DEFINE_D
642 : MUSCLE_PERCENT_DEFINE_F);
58697c6d 643 }
e9690142 644 break;
22c2cbc0 645
8e55b3aa 646 case 'I':
e9690142
JD
647 include = AS_FILE_NAME (optarg);
648 break;
41d7a5f2 649
0e021770 650 case 'L':
e9690142
JD
651 language_argmatch (optarg, command_line_prio,
652 command_line_location ());
653 break;
0e021770 654
cd5bd6ac 655 case 'S':
e9690142
JD
656 skeleton_arg (AS_FILE_NAME (optarg), command_line_prio,
657 command_line_location ());
658 break;
cd5bd6ac 659
8e55b3aa 660 case 'T':
327db05b 661 FLAGS_ARGMATCH (trace, optarg, trace_all);
e9690142 662 break;
f6bd5427 663
8e55b3aa 664 case 'V':
e9690142
JD
665 version ();
666 exit (EXIT_SUCCESS);
8e55b3aa 667
0db26489 668 case 'f':
f3ead217 669 FLAGS_ARGMATCH (feature, optarg, feature_all);
0db26489
TR
670 break;
671
8e55b3aa 672 case 'W':
327db05b 673 FLAGS_ARGMATCH (warnings, optarg, Wall);
e9690142 674 break;
8e55b3aa
JD
675
676 case 'b':
e9690142
JD
677 spec_file_prefix = AS_FILE_NAME (optarg);
678 break;
8e55b3aa 679
58697c6d
AD
680 case 'd':
681 /* Here, the -d and --defines options are differentiated. */
682 defines_flag = true;
683 if (optarg)
0b7fba13
AD
684 {
685 free (spec_defines_file);
686 spec_defines_file = xstrdup (AS_FILE_NAME (optarg));
687 }
58697c6d
AD
688 break;
689
8e55b3aa 690 case 'g':
e9690142
JD
691 graph_flag = true;
692 if (optarg)
0b7fba13
AD
693 {
694 free (spec_graph_file);
695 spec_graph_file = xstrdup (AS_FILE_NAME (optarg));
696 }
e9690142 697 break;
cd5bd6ac 698
8e55b3aa 699 case 'h':
e9690142 700 usage (EXIT_SUCCESS);
8e55b3aa 701
7b42569e 702 case 'k':
e9690142
JD
703 token_table_flag = true;
704 break;
7b42569e 705
cd5bd6ac 706 case 'l':
e9690142
JD
707 no_lines_flag = true;
708 break;
d0829076 709
7b42569e 710 case 'o':
e9690142
JD
711 spec_outfile = AS_FILE_NAME (optarg);
712 break;
cd5bd6ac 713
7b42569e 714 case 'p':
e9690142
JD
715 spec_name_prefix = optarg;
716 break;
7b42569e
AD
717
718 case 'r':
327db05b 719 FLAGS_ARGMATCH (report, optarg, report_all);
e9690142 720 break;
7b42569e 721
cd5bd6ac 722 case 't':
fa819509 723 muscle_percent_define_insert ("parse.trace",
de5ab940
JD
724 command_line_location (), "",
725 MUSCLE_PERCENT_DEFINE_D);
e9690142 726 break;
cd5bd6ac 727
7b42569e 728 case 'v':
e9690142
JD
729 report_flag |= report_states;
730 break;
cd5bd6ac 731
8e55b3aa 732 case 'x':
e9690142
JD
733 xml_flag = true;
734 if (optarg)
0b7fba13
AD
735 {
736 free (spec_xml_file);
737 spec_xml_file = xstrdup (AS_FILE_NAME (optarg));
738 }
e9690142 739 break;
cd5bd6ac 740
8e55b3aa 741 case 'y':
1048a1c9
AD
742 warnings_flag |= Wyacc;
743 errors_flag |= Wyacc;
e9690142
JD
744 yacc_flag = true;
745 break;
ec3bc396 746
7b42569e 747 case LOCATIONS_OPTION:
bc0f5737
AD
748 muscle_percent_define_ensure ("locations",
749 command_line_location (), true);
e9690142 750 break;
273a74fa 751
7b42569e 752 case PRINT_LOCALEDIR_OPTION:
e9690142
JD
753 printf ("%s\n", LOCALEDIR);
754 exit (EXIT_SUCCESS);
7b42569e 755
d4bd2295 756 case PRINT_DATADIR_OPTION:
d9a7c07c 757 printf ("%s\n", pkgdatadir ());
e9690142 758 exit (EXIT_SUCCESS);
d4bd2295 759
8e55b3aa 760 case REPORT_FILE_OPTION:
0b7fba13 761 free (spec_verbose_file);
e9690142
JD
762 spec_verbose_file = xstrdup (AS_FILE_NAME (optarg));
763 break;
8e55b3aa 764
cd5bd6ac 765 default:
e9690142 766 usage (EXIT_FAILURE);
cd5bd6ac 767 }
3d8fc6ca 768
a4b6efd4 769 if (argc - optind != 1)
3d8fc6ca 770 {
a4b6efd4 771 if (argc - optind < 1)
4a9cd8f2 772 error (0, 0, _("%s: missing operand"), quotearg_colon (argv[argc - 1]));
a4b6efd4 773 else
4a9cd8f2 774 error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
0e575721 775 usage (EXIT_FAILURE);
3d8fc6ca 776 }
3d8fc6ca 777
d38a11a6 778 current_file = grammar_file = uniqstr_new (argv[optind]);
9fe5a457 779 MUSCLE_INSERT_C_STRING ("file_name", grammar_file);
3d8fc6ca 780}
67212941
JD
781
782void
783tr (char *s, char from, char to)
784{
785 for (; *s; s++)
786 if (*s == from)
787 *s = to;
788}