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