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