]>
git.saurik.com Git - bison.git/blob - src/getargs.c
4b417d59523f8fc4804c3d0a2fb0ec01c476e20f
1 /* Parse command line arguments for Bison.
3 Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006 Free Software Foundation, Inc.
6 This file is part of Bison, the GNU Compiler Compiler.
8 Bison is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 Bison is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bison; see the file COPYING. If not, write to the Free
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 /* Hack to get <getopt.h> to declare getopt with a prototype. */
31 #if lint && ! defined __GNU_LIBRARY__
32 # define __GNU_LIBRARY__
33 # define HACK_FOR___GNU_LIBRARY___PROTOTYPE 1
38 #ifdef HACK_FOR___GNU_LIBRARY___PROTOTYPE
39 # undef __GNU_LIBRARY__
40 # undef HACK_FOR___GNU_LIBRARY___PROTOTYPE
54 bool token_table_flag
;
55 bool yacc_flag
; /* for -y */
57 bool error_verbose
= false;
59 bool nondeterministic_parser
= false;
60 bool glr_parser
= false;
61 bool pure_parser
= false;
63 int report_flag
= report_none
;
64 int trace_flag
= trace_none
;
66 const char *skeleton
= NULL
;
67 const char *include
= NULL
;
69 extern char *program_name
;
72 /*----------------------.
73 | --report's handling. |
74 `----------------------*/
76 static const char * const report_args
[] =
78 /* In a series of synonyms, present the most meaningful first, so
79 that argmatch_valid be more readable. */
82 "itemset", "itemsets",
83 "lookahead", "lookaheads", "look-ahead",
89 static const int report_types
[] =
92 report_states
, report_states
,
93 report_states
| report_itemsets
, report_states
| report_itemsets
,
94 report_states
| report_lookahead_tokens
,
95 report_states
| report_lookahead_tokens
,
96 report_states
| report_lookahead_tokens
,
97 report_states
| report_solved_conflicts
,
101 ARGMATCH_VERIFY (report_args
, report_types
);
104 report_argmatch (char *args
)
106 args
= strtok (args
, ",");
109 int report
= XARGMATCH ("--report", args
,
110 report_args
, report_types
);
111 if (report
== report_none
)
112 report_flag
= report_none
;
114 report_flag
|= report
;
116 while ((args
= strtok (NULL
, ",")));
120 /*---------------------.
121 | --trace's handling. |
122 `---------------------*/
124 static const char * const trace_args
[] =
126 /* In a series of synonyms, present the most meaningful first, so
127 that argmatch_valid be more readable. */
129 "scan - grammar scanner traces",
130 "parse - grammar parser traces",
131 "automaton - construction of the automaton",
132 "bitsets - use of bitsets",
133 "grammar - reading, reducing the grammar",
134 "resource - memory consumption (where available)",
135 "sets - grammar sets: firsts, nullable etc.",
136 "tools - m4 invocation",
138 "skeleton - skeleton postprocessing",
139 "time - time consumption",
140 "all - all of the above",
144 static const int trace_types
[] =
161 ARGMATCH_VERIFY (trace_args
, trace_types
);
164 trace_argmatch (char *args
)
168 args
= strtok (args
, ",");
171 int trace
= XARGMATCH ("--trace", args
,
172 trace_args
, trace_types
);
173 if (trace
== trace_none
)
174 trace_flag
= trace_none
;
178 while ((args
= strtok (NULL
, ",")));
181 trace_flag
= trace_all
;
185 /*-------------------------------------------.
186 | Display the help message and exit STATUS. |
187 `-------------------------------------------*/
189 static void usage (int) ATTRIBUTE_NORETURN
;
195 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
199 /* Some efforts were made to ease the translators' task, please
202 GNU bison generates LALR(1) and GLR parsers.\n"), stdout
);
205 fprintf (stdout
, _("\
206 Usage: %s [OPTION]... FILE\n"), program_name
);
210 If a long option shows an argument as mandatory, then it is mandatory\n\
211 for the equivalent short option also. Similarly for optional arguments.\n"),
217 -h, --help display this help and exit\n\
218 -V, --version output version information and exit\n\
219 --print-localedir output directory containing locale-dependent data\n\
220 -y, --yacc emulate POSIX Yacc\n"), stdout
);
225 -S, --skeleton=FILE specify the skeleton to use\n\
226 -t, --debug instrument the parser for debugging\n\
227 --locations enable locations computation\n\
228 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
229 -l, --no-lines don't generate `#line' directives\n\
230 -n, --no-parser generate the tables only\n\
231 -k, --token-table include a table of token names\n\
237 -d, --defines also produce a header file\n\
238 -r, --report=THINGS also produce details on the automaton\n\
239 -v, --verbose same as `--report=state'\n\
240 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
241 -o, --output=FILE leave output to FILE\n\
242 -g, --graph also produce a VCG description of the automaton\n\
247 THINGS is a list of comma separated words that can include:\n\
248 `state' describe the states\n\
249 `itemset' complete the core item sets with their closure\n\
250 `lookahead' explicitly associate lookahead tokens to items\n\
251 `solved' describe shift/reduce conflicts solving\n\
252 `all' include all the above information\n\
253 `none' disable the report\n\
258 Report bugs to <bug-bison@gnu.org>.\n"), stdout
);
265 /*------------------------------.
266 | Display the version message. |
267 `------------------------------*/
272 /* Some efforts were made to ease the translators' task, please
274 printf (_("bison (GNU Bison) %s"), VERSION
);
276 printf ("%s", revision
);
277 fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout
);
281 _("Copyright (C) %d Free Software Foundation, Inc.\n"), 2006);
284 This is free software; see the source for copying conditions. There is NO\n\
285 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
291 /*----------------------.
292 | Process the options. |
293 `----------------------*/
295 /* Shorts options. */
296 static char const short_options
[] = "yvegdhr:ltknVo:b:p:S:T::";
298 /* Values for long options that do not have single-letter equivalents. */
301 LOCATIONS_OPTION
= CHAR_MAX
+ 1,
302 PRINT_LOCALEDIR_OPTION
305 static struct option
const long_options
[] =
307 /* Operation modes. */
308 { "help", no_argument
, 0, 'h' },
309 { "version", no_argument
, 0, 'V' },
310 { "print-localedir", no_argument
, 0, PRINT_LOCALEDIR_OPTION
},
313 { "name-prefix", required_argument
, 0, 'p' },
314 { "include", required_argument
, 0, 'I' },
317 { "file-prefix", required_argument
, 0, 'b' },
318 { "output", required_argument
, 0, 'o' },
319 { "output-file", required_argument
, 0, 'o' },
320 { "graph", optional_argument
, 0, 'g' },
321 { "report", required_argument
, 0, 'r' },
322 { "verbose", no_argument
, 0, 'v' },
325 { "trace", optional_argument
, 0, 'T' },
328 { "defines", optional_argument
, 0, 'd' },
330 /* Operation modes. */
331 { "fixed-output-files", no_argument
, 0, 'y' },
332 { "yacc", no_argument
, 0, 'y' },
335 { "debug", no_argument
, 0, 't' },
336 { "locations", no_argument
, 0, LOCATIONS_OPTION
},
337 { "no-lines", no_argument
, 0, 'l' },
338 { "no-parser", no_argument
, 0, 'n' },
339 { "raw", no_argument
, 0, 0 },
340 { "skeleton", required_argument
, 0, 'S' },
341 { "token-table", no_argument
, 0, 'k' },
346 /* Under DOS, there is no difference on the case. This can be
347 troublesome when looking for `.tab' etc. */
349 # define AS_FILE_NAME(File) (strlwr (File), (File))
351 # define AS_FILE_NAME(File) (File)
355 getargs (int argc
, char *argv
[])
359 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
, NULL
))
364 /* Certain long options cause getopt_long to return 0. */
372 usage (EXIT_SUCCESS
);
378 case PRINT_LOCALEDIR_OPTION
:
379 printf ("%s\n", LOCALEDIR
);
383 /* Here, the -g and --graph=FILE options are differentiated. */
386 spec_graph_file
= AS_FILE_NAME (optarg
);
390 report_flag
|= report_states
;
394 skeleton
= AS_FILE_NAME (optarg
);
398 include
= AS_FILE_NAME (optarg
);
402 /* Here, the -d and --defines options are differentiated. */
405 spec_defines_file
= AS_FILE_NAME (optarg
);
409 no_lines_flag
= true;
412 case LOCATIONS_OPTION
:
413 locations_flag
= true;
417 token_table_flag
= true;
421 no_parser_flag
= true;
429 spec_outfile
= AS_FILE_NAME (optarg
);
433 spec_file_prefix
= AS_FILE_NAME (optarg
);
437 spec_name_prefix
= optarg
;
441 report_argmatch (optarg
);
445 trace_argmatch (optarg
);
449 usage (EXIT_FAILURE
);
452 if (argc
- optind
!= 1)
454 if (argc
- optind
< 1)
455 error (0, 0, _("missing operand after `%s'"), argv
[argc
- 1]);
457 error (0, 0, _("extra operand `%s'"), argv
[optind
+ 1]);
458 usage (EXIT_FAILURE
);
461 current_file
= grammar_file
= uniqstr_new (argv
[optind
]);