]>
git.saurik.com Git - bison.git/blob - src/getargs.c
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
29 /* Hack to get <getopt.h> to declare getopt with a prototype. */
30 #if lint && ! defined __GNU_LIBRARY__
31 # define __GNU_LIBRARY__
32 # define HACK_FOR___GNU_LIBRARY___PROTOTYPE 1
37 #ifdef HACK_FOR___GNU_LIBRARY___PROTOTYPE
38 # undef __GNU_LIBRARY__
39 # undef HACK_FOR___GNU_LIBRARY___PROTOTYPE
53 bool token_table_flag
;
54 bool yacc_flag
; /* for -y */
56 bool error_verbose
= false;
58 bool nondeterministic_parser
= false;
59 bool glr_parser
= false;
60 bool pure_parser
= false;
62 int report_flag
= report_none
;
63 int trace_flag
= trace_none
;
65 const char *skeleton
= NULL
;
66 const char *include
= NULL
;
68 extern char *program_name
;
71 /*---------------------.
72 | --trace's handling. |
73 `---------------------*/
75 static const char * const trace_args
[] =
77 /* In a series of synonyms, present the most meaningful first, so
78 that argmatch_valid be more readable. */
80 "scan - grammar scanner traces",
81 "parse - grammar parser traces",
82 "automaton - contruction of the automaton",
83 "bitsets - use of bitsets",
84 "grammar - reading, reducing of the grammar",
85 "resource - memory consumption (where available)",
86 "sets - grammar sets: firsts, nullable etc.",
87 "tools - m4 invocation",
89 "skeleton - skeleton postprocessing",
90 "time - time consumption",
91 "all - all of the above",
95 static const int trace_types
[] =
112 ARGMATCH_VERIFY (trace_args
, trace_types
);
115 trace_argmatch (char *args
)
119 args
= strtok (args
, ",");
122 int trace
= XARGMATCH ("--trace", args
,
123 trace_args
, trace_types
);
124 if (trace
== trace_none
)
125 trace_flag
= trace_none
;
129 while ((args
= strtok (NULL
, ",")));
132 trace_flag
= trace_all
;
136 /*----------------------.
137 | --report's handling. |
138 `----------------------*/
140 static const char * const report_args
[] =
142 /* In a series of synonyms, present the most meaningful first, so
143 that argmatch_valid be more readable. */
146 "itemset", "itemsets",
147 "look-ahead", "lookahead", "lookaheads",
153 static const int report_types
[] =
156 report_states
, report_states
,
157 report_states
| report_itemsets
, report_states
| report_itemsets
,
158 report_states
| report_look_ahead_tokens
,
159 report_states
| report_look_ahead_tokens
,
160 report_states
| report_look_ahead_tokens
,
161 report_states
| report_solved_conflicts
,
165 ARGMATCH_VERIFY (report_args
, report_types
);
168 report_argmatch (char *args
)
170 args
= strtok (args
, ",");
173 int report
= XARGMATCH ("--report", args
,
174 report_args
, report_types
);
175 if (report
== report_none
)
176 report_flag
= report_none
;
178 report_flag
|= report
;
180 while ((args
= strtok (NULL
, ",")));
184 /*-------------------------------------------.
185 | Display the help message and exit STATUS. |
186 `-------------------------------------------*/
188 static void usage (int) ATTRIBUTE_NORETURN
;
194 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
198 /* Some efforts were made to ease the translators' task, please
201 GNU bison generates parsers for LALR(1) or GLR grammars.\n"), stdout
);
204 fprintf (stdout
, _("\
205 Usage: %s [OPTION]... FILE\n"), program_name
);
209 If a long option shows an argument as mandatory, then it is mandatory\n\
210 for the equivalent short option also. Similarly for optional arguments.\n"),
216 -h, --help display this help and exit\n\
217 -V, --version output version information and exit\n\
218 --print-localedir output directory containing locale-dependent data\n\
219 -y, --yacc emulate POSIX yacc\n"), stdout
);
224 -S, --skeleton=FILE specify the skeleton to use\n\
225 -t, --debug instrument the parser for debugging\n\
226 --locations enable locations computation\n\
227 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
228 -l, --no-lines don't generate `#line' directives\n\
229 -n, --no-parser generate the tables only\n\
230 -k, --token-table include a table of token names\n\
236 -d, --defines also produce a header file\n\
237 -r, --report=THINGS also produce details on the automaton\n\
238 -v, --verbose same as `--report=state'\n\
239 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
240 -o, --output=FILE leave output to FILE\n\
241 -g, --graph also produce a VCG description of the automaton\n\
246 THINGS is a list of comma separated words that can include:\n\
247 `state' describe the states\n\
248 `itemset' complete the core item sets with their closure\n\
249 `look-ahead' explicitly associate look-ahead tokens to items\n\
250 `solved' describe shift/reduce conflicts solving\n\
251 `all' include all the above information\n\
252 `none' disable the report\n\
257 Report bugs to <bug-bison@gnu.org>.\n"), stdout
);
264 /*------------------------------.
265 | Display the version message. |
266 `------------------------------*/
271 /* Some efforts were made to ease the translators' task, please
273 printf (_("bison (GNU Bison) %s"), VERSION
);
275 fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout
);
279 _("Copyright (C) %d Free Software Foundation, Inc.\n"), 2006);
282 This is free software; see the source for copying conditions. There is NO\n\
283 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
289 /*----------------------.
290 | Process the options. |
291 `----------------------*/
293 /* Shorts options. */
294 static char const short_options
[] = "yvegdhr:ltknVo:b:p:S:T::";
296 /* Values for long options that do not have single-letter equivalents. */
299 LOCATIONS_OPTION
= CHAR_MAX
+ 1,
300 PRINT_LOCALEDIR_OPTION
303 static struct option
const long_options
[] =
305 /* Operation modes. */
306 { "help", no_argument
, 0, 'h' },
307 { "version", no_argument
, 0, 'V' },
308 { "print-localedir", no_argument
, 0, PRINT_LOCALEDIR_OPTION
},
311 { "name-prefix", required_argument
, 0, 'p' },
312 { "include", required_argument
, 0, 'I' },
315 { "file-prefix", required_argument
, 0, 'b' },
316 { "output", required_argument
, 0, 'o' },
317 { "output-file", required_argument
, 0, 'o' },
318 { "graph", optional_argument
, 0, 'g' },
319 { "report", required_argument
, 0, 'r' },
320 { "verbose", no_argument
, 0, 'v' },
323 { "trace", optional_argument
, 0, 'T' },
326 { "defines", optional_argument
, 0, 'd' },
328 /* Operation modes. */
329 { "fixed-output-files", no_argument
, 0, 'y' },
330 { "yacc", no_argument
, 0, 'y' },
333 { "debug", no_argument
, 0, 't' },
334 { "locations", no_argument
, 0, LOCATIONS_OPTION
},
335 { "no-lines", no_argument
, 0, 'l' },
336 { "no-parser", no_argument
, 0, 'n' },
337 { "raw", no_argument
, 0, 0 },
338 { "skeleton", required_argument
, 0, 'S' },
339 { "token-table", no_argument
, 0, 'k' },
344 /* Under DOS, there is no difference on the case. This can be
345 troublesome when looking for `.tab' etc. */
347 # define AS_FILE_NAME(File) (strlwr (File), (File))
349 # define AS_FILE_NAME(File) (File)
353 getargs (int argc
, char *argv
[])
357 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
, NULL
))
362 /* Certain long options cause getopt_long to return 0. */
370 usage (EXIT_SUCCESS
);
376 case PRINT_LOCALEDIR_OPTION
:
377 printf ("%s\n", LOCALEDIR
);
381 /* Here, the -g and --graph=FILE options are differentiated. */
384 spec_graph_file
= AS_FILE_NAME (optarg
);
388 report_flag
|= report_states
;
392 skeleton
= AS_FILE_NAME (optarg
);
396 include
= AS_FILE_NAME (optarg
);
400 /* Here, the -d and --defines options are differentiated. */
403 spec_defines_file
= AS_FILE_NAME (optarg
);
407 no_lines_flag
= true;
410 case LOCATIONS_OPTION
:
411 locations_flag
= true;
415 token_table_flag
= true;
419 no_parser_flag
= true;
427 spec_outfile
= AS_FILE_NAME (optarg
);
431 spec_file_prefix
= AS_FILE_NAME (optarg
);
435 spec_name_prefix
= optarg
;
439 report_argmatch (optarg
);
443 trace_argmatch (optarg
);
447 usage (EXIT_FAILURE
);
450 if (argc
- optind
!= 1)
452 if (argc
- optind
< 1)
453 error (0, 0, _("missing operand after `%s'"), argv
[argc
- 1]);
455 error (0, 0, _("extra operand `%s'"), argv
[optind
+ 1]);
456 usage (EXIT_FAILURE
);
459 current_file
= grammar_file
= uniqstr_new (argv
[optind
]);