]>
git.saurik.com Git - bison.git/blob - src/getargs.c
ec861eb0541f5adc2471f78df5ea7c4492be0a03
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 | --trace's handling. |
74 `---------------------*/
76 static const char * const trace_args
[] =
78 /* In a series of synonyms, present the most meaningful first, so
79 that argmatch_valid be more readable. */
81 "scan - grammar scanner traces",
82 "parse - grammar parser traces",
83 "automaton - contruction of the automaton",
84 "bitsets - use of bitsets",
85 "grammar - reading, reducing of the grammar",
86 "resource - memory consumption (where available)",
87 "sets - grammar sets: firsts, nullable etc.",
88 "tools - m4 invocation",
90 "skeleton - skeleton postprocessing",
91 "time - time consumption",
92 "all - all of the above",
96 static const int trace_types
[] =
113 ARGMATCH_VERIFY (trace_args
, trace_types
);
116 trace_argmatch (char *args
)
120 args
= strtok (args
, ",");
123 int trace
= XARGMATCH ("--trace", args
,
124 trace_args
, trace_types
);
125 if (trace
== trace_none
)
126 trace_flag
= trace_none
;
130 while ((args
= strtok (NULL
, ",")));
133 trace_flag
= trace_all
;
137 /*----------------------.
138 | --report's handling. |
139 `----------------------*/
141 static const char * const report_args
[] =
143 /* In a series of synonyms, present the most meaningful first, so
144 that argmatch_valid be more readable. */
147 "itemset", "itemsets",
148 "lookahead", "lookaheads", "look-ahead",
154 static const int report_types
[] =
157 report_states
, report_states
,
158 report_states
| report_itemsets
, report_states
| report_itemsets
,
159 report_states
| report_lookahead_tokens
,
160 report_states
| report_lookahead_tokens
,
161 report_states
| report_lookahead_tokens
,
162 report_states
| report_solved_conflicts
,
166 ARGMATCH_VERIFY (report_args
, report_types
);
169 report_argmatch (char *args
)
171 args
= strtok (args
, ",");
174 int report
= XARGMATCH ("--report", args
,
175 report_args
, report_types
);
176 if (report
== report_none
)
177 report_flag
= report_none
;
179 report_flag
|= report
;
181 while ((args
= strtok (NULL
, ",")));
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
]);