]>
git.saurik.com Git - bison.git/blob - src/getargs.c
69e6f20f9edaa8334c141204d5f007217068b576
1 /* Parse command line arguments for Bison.
3 Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003
4 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., 59 Temple Place - Suite 330, Boston, MA
28 /* Hack to get <getopt.h> to declare getopt with a prototype. */
29 #if lint && ! defined __GNU_LIBRARY__
30 # define __GNU_LIBRARY__
31 # define HACK_FOR___GNU_LIBRARY___PROTOTYPE 1
36 #ifdef HACK_FOR___GNU_LIBRARY___PROTOTYPE
37 # undef __GNU_LIBRARY__
38 # undef HACK_FOR___GNU_LIBRARY___PROTOTYPE
48 int locations_flag
= 0;
49 int no_lines_flag
= 0;
50 int no_parser_flag
= 0;
51 int report_flag
= report_none
;
52 int token_table_flag
= 0;
53 int yacc_flag
= 0; /* for -y */
55 int trace_flag
= trace_none
;
57 const char *skeleton
= NULL
;
58 const char *include
= NULL
;
60 extern char *program_name
;
63 /*---------------------.
64 | --trace's handling. |
65 `---------------------*/
67 static const char * const trace_args
[] =
69 /* In a series of synonyms, present the most meaningful first, so
70 that argmatch_valid be more readable. */
72 "scan - grammar scanner traces",
73 "parse - grammar parser traces",
74 "automaton - contruction of the automaton",
75 "bitsets - use of bitsets",
76 "grammar - reading, reducing of the grammar",
77 "resource - memory consumption (where available)",
78 "sets - grammar sets: firsts, nullable etc.",
79 "tools - m4 invocation and preserve the temporary file",
80 "skeleton - skeleton postprocessing",
81 "time - time consumption",
82 "all - all of the above",
86 static const int trace_types
[] =
104 trace_argmatch (char *args
)
106 verify (trace_constraint
, ARGMATCH_CONSTRAINT (trace_args
, trace_types
));
109 args
= strtok (args
, ",");
112 int trace
= XARGMATCH ("--trace", args
,
113 trace_args
, trace_types
);
114 if (trace
== trace_none
)
115 trace_flag
= trace_none
;
119 while ((args
= strtok (NULL
, ",")));
122 trace_flag
= trace_all
;
126 /*----------------------.
127 | --report's handling. |
128 `----------------------*/
130 static const char * const report_args
[] =
132 /* In a series of synonyms, present the most meaningful first, so
133 that argmatch_valid be more readable. */
136 "itemset", "itemsets",
137 "lookahead", "lookaheads",
143 static const int report_types
[] =
146 report_states
, report_states
,
147 report_states
| report_itemsets
, report_states
| report_itemsets
,
148 report_states
| report_lookaheads
, report_states
| report_lookaheads
,
149 report_states
| report_solved_conflicts
,
155 report_argmatch (char *args
)
157 verify (report_constraint
, ARGMATCH_CONSTRAINT (report_args
, report_types
));
158 args
= strtok (args
, ",");
161 int report
= XARGMATCH ("--report", args
,
162 report_args
, report_types
);
163 if (report
== report_none
)
164 report_flag
= report_none
;
166 report_flag
|= report
;
168 while ((args
= strtok (NULL
, ",")));
172 /*-------------------------------------------.
173 | Display the help message and exit STATUS. |
174 `-------------------------------------------*/
176 static void usage (int) ATTRIBUTE_NORETURN
;
182 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
186 /* Some efforts were made to ease the translators' task, please
189 GNU bison generates parsers for LALR(1) grammars.\n"), stdout
);
192 fprintf (stdout
, _("\
193 Usage: %s [OPTION]... FILE\n"), program_name
);
197 If a long option shows an argument as mandatory, then it is mandatory\n\
198 for the equivalent short option also. Similarly for optional arguments.\n"),
204 -h, --help display this help and exit\n\
205 -V, --version output version information and exit\n\
206 -y, --yacc emulate POSIX yacc\n"), stdout
);
211 -S, --skeleton=FILE specify the skeleton to use\n\
212 -t, --debug instrument the parser for debugging\n\
213 --locations enable locations computation\n\
214 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
215 -l, --no-lines don't generate `#line' directives\n\
216 -n, --no-parser generate the tables only\n\
217 -k, --token-table include a table of token names\n\
223 -d, --defines also produce a header file\n\
224 -r, --report=THINGS also produce details on the automaton\n\
225 -v, --verbose same as `--report=state'\n\
226 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
227 -o, --output=FILE leave output to FILE\n\
228 -g, --graph also produce a VCG description of the automaton\n\
233 THINGS is a list of comma separated words that can include:\n\
234 `state' describe the states\n\
235 `itemset' complete the core item sets with their closure\n\
236 `lookahead' explicitly associate lookaheads to items\n\
237 `solved' describe shift/reduce conflicts solving\n\
238 `all' include all the above information\n\
239 `none' disable the report\n\
244 Report bugs to <bug-bison@gnu.org>.\n"), stdout
);
251 /*------------------------------.
252 | Display the version message. |
253 `------------------------------*/
258 /* Some efforts were made to ease the translators' task, please
260 printf (_("bison (GNU Bison) %s"), VERSION
);
262 fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout
);
266 _("Copyright (C) %d Free Software Foundation, Inc.\n"), 2003);
269 This is free software; see the source for copying conditions. There is NO\n\
270 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
276 /*----------------------.
277 | Process the options. |
278 `----------------------*/
280 /* Shorts options. */
281 const char *short_options
= "yvegdhr:ltknVo:b:p:S:T::";
283 static struct option
const long_options
[] =
285 /* Operation modes. */
286 { "help", no_argument
, 0, 'h' },
287 { "version", no_argument
, 0, 'V' },
290 { "name-prefix", required_argument
, 0, 'p' },
291 { "include", required_argument
, 0, 'I' },
294 { "file-prefix", required_argument
, 0, 'b' },
295 { "output", required_argument
, 0, 'o' },
296 { "output-file", required_argument
, 0, 'o' },
297 { "graph", optional_argument
, 0, 'g' },
298 { "report", required_argument
, 0, 'r' },
299 { "verbose", no_argument
, 0, 'v' },
302 { "trace", optional_argument
, 0, 'T' },
305 { "defines", optional_argument
, 0, 'd' },
307 /* Operation modes. */
308 { "fixed-output-files", no_argument
, 0, 'y' },
309 { "yacc", no_argument
, 0, 'y' },
312 { "debug", no_argument
, 0, 't' },
313 { "locations", no_argument
, &locations_flag
, 1 },
314 { "no-lines", no_argument
, 0, 'l' },
315 { "no-parser", no_argument
, 0, 'n' },
316 { "raw", no_argument
, 0, 0 },
317 { "skeleton", required_argument
, 0, 'S' },
318 { "token-table", no_argument
, 0, 'k' },
323 /* Under DOS, there is no difference on the case. This can be
324 troublesome when looking for `.tab' etc. */
326 # define AS_FILE_NAME(File) (strlwr (File), (File))
328 # define AS_FILE_NAME(File) (File)
332 getargs (int argc
, char *argv
[])
336 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
, NULL
))
341 /* Certain long options cause getopt_long to return 0. */
349 usage (EXIT_SUCCESS
);
356 /* Here, the -g and --graph=FILE options are differentiated. */
359 spec_graph_file
= AS_FILE_NAME (optarg
);
363 report_flag
|= report_states
;
367 skeleton
= AS_FILE_NAME (optarg
);
371 include
= AS_FILE_NAME (optarg
);
375 /* Here, the -d and --defines options are differentiated. */
378 spec_defines_file
= AS_FILE_NAME (optarg
);
386 token_table_flag
= 1;
398 spec_outfile
= AS_FILE_NAME (optarg
);
402 spec_file_prefix
= AS_FILE_NAME (optarg
);
406 spec_name_prefix
= optarg
;
410 report_argmatch (optarg
);
414 trace_argmatch (optarg
);
418 usage (EXIT_FAILURE
);
421 if (argc
- optind
!= 1)
423 if (argc
- optind
< 1)
424 error (0, 0, _("missing operand after `%s'"), argv
[argc
- 1]);
426 error (0, 0, _("extra operand `%s'"), argv
[optind
+ 1]);
427 usage (EXIT_FAILURE
);
430 current_file
= grammar_file
= uniqstr_new (argv
[optind
]);