]>
git.saurik.com Git - bison.git/blob - src/getargs.c
1 /* Parse command line arguments for bison.
2 Copyright 1984, 1986, 1989, 1992, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 Bison is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 Bison is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bison; see the file COPYING. If not, write to the Free
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 int locations_flag
= 0;
32 int no_lines_flag
= 0;
33 int no_parser_flag
= 0;
34 int report_flag
= report_none
;
35 int token_table_flag
= 0;
36 int yacc_flag
= 0; /* for -y */
38 int trace_flag
= trace_none
;
40 const char *skeleton
= NULL
;
41 const char *include
= NULL
;
43 extern char *program_name
;
46 /*---------------------.
47 | --trace's handling. |
48 `---------------------*/
50 static const char * const trace_args
[] =
52 /* In a series of synonyms, present the most meaningful first, so
53 that argmatch_valid be more readable. */
55 "scan - scanner traces",
56 "parse - parser traces",
57 "automaton - contruction of the automaton",
58 "bitsets - use of bitsets",
59 "grammar - reading, reducing of the grammar",
60 "resource - memory consumption (where available)",
61 "sets - grammar sets: firsts, nullable etc.",
62 "time - time consumption",
63 "tools - m4 invocation and preserve the temporary file",
64 "all - all of the above",
68 static const int trace_types
[] =
85 trace_argmatch (char *args
)
87 ARGMATCH_ASSERT (trace_args
, trace_types
);
90 args
= strtok (args
, ",");
93 int trace
= XARGMATCH ("--trace", args
,
94 trace_args
, trace_types
);
95 if (trace
== trace_none
)
96 trace_flag
= trace_none
;
100 while ((args
= strtok (NULL
, ",")));
103 trace_flag
= trace_all
;
107 /*----------------------.
108 | --report's handling. |
109 `----------------------*/
111 static const char * const report_args
[] =
113 /* In a series of synonyms, present the most meaningful first, so
114 that argmatch_valid be more readable. */
117 "itemset", "itemsets",
118 "lookahead", "lookaheads",
124 static const int report_types
[] =
127 report_states
, report_states
,
128 report_states
| report_itemsets
, report_states
| report_itemsets
,
129 report_states
| report_lookaheads
, report_states
| report_lookaheads
,
130 report_states
| report_solved_conflicts
,
136 report_argmatch (char *args
)
138 ARGMATCH_ASSERT (report_args
, report_types
);
139 args
= strtok (args
, ",");
142 int report
= XARGMATCH ("--report", args
,
143 report_args
, report_types
);
144 if (report
== report_none
)
145 report_flag
= report_none
;
147 report_flag
|= report
;
149 while ((args
= strtok (NULL
, ",")));
152 /*---------------------------.
153 | Display the help message. |
154 `---------------------------*/
159 /* Some efforts were made to ease the translators' task, please
162 GNU bison generates parsers for LALR(1) grammars.\n"), stream
);
165 fprintf (stream
, _("\
166 Usage: %s [OPTION]... FILE\n"), program_name
);
170 If a long option shows an argument as mandatory, then it is mandatory\n\
171 for the equivalent short option also. Similarly for optional arguments.\n"),
177 -h, --help display this help and exit\n\
178 -V, --version output version information and exit\n\
179 -y, --yacc emulate POSIX yacc\n"), stream
);
184 -S, --skeleton=FILE specify the skeleton to use\n\
185 -t, --debug instrument the parser for debugging\n\
186 --locations enable locations computation\n\
187 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
188 -l, --no-lines don't generate `#line' directives\n\
189 -n, --no-parser generate the tables only\n\
190 -k, --token-table include a table of token names\n\
196 -d, --defines also produce a header file\n\
197 -r, --report=THINGS also produce details on the automaton\n\
198 -v, --verbose same as `--report=state'\n\
199 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
200 -o, --output=FILE leave output to FILE\n\
201 -g, --graph also produce a VCG description of the automaton\n\
206 THINGS is a list of comma separated words that can include:\n\
207 `state' describe the states\n\
208 `itemset' complete the core item sets with their closure\n\
209 `lookahead' explicitly associate lookaheads to items\n\
210 `solved' describe shift/reduce conflicts solving\n\
211 `all' include all the above information\n\
212 `none' disable the report\n\
217 Report bugs to <bug-bison@gnu.org>.\n"), stream
);
221 /*------------------------------.
222 | Display the version message. |
223 `------------------------------*/
226 version (FILE *stream
)
228 /* Some efforts were made to ease the translators' task, please
230 fprintf (stream
, _("bison (GNU Bison) %s"), VERSION
);
232 fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stream
);
236 _("Copyright (C) %d Free Software Foundation, Inc.\n"), 2002);
239 This is free software; see the source for copying conditions. There is NO\n\
240 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
246 /*----------------------.
247 | Process the options. |
248 `----------------------*/
250 /* Shorts options. */
251 const char *short_options
= "yvegdhr:ltknVo:b:p:S:T::";
253 static struct option
const long_options
[] =
255 /* Operation modes. */
256 { "help", no_argument
, 0, 'h' },
257 { "version", no_argument
, 0, 'V' },
260 { "name-prefix", required_argument
, 0, 'p' },
261 { "include", required_argument
, 0, 'I' },
264 { "file-prefix", required_argument
, 0, 'b' },
265 { "output", required_argument
, 0, 'o' },
266 { "output-file", required_argument
, 0, 'o' },
267 { "graph", optional_argument
, 0, 'g' },
268 { "report", required_argument
, 0, 'r' },
269 { "verbose", no_argument
, 0, 'v' },
272 { "trace", optional_argument
, 0, 'T' },
274 /* FIXME: semantic parsers will output an `include' of an
275 output file: be sure that the naem included is indeed the name of
276 the output file. */ /* FIXME Should we activate this options ?
278 { "output", required_argument
, 0, 'o' },
279 { "file-prefix", required_argument
, 0, 'b' },
280 { "name-prefix", required_argument
, 0, 'p' },
283 * Percent and command line declarations.
287 { "defines", optional_argument
, 0, 'd' },
289 /* Operation modes. */
290 { "fixed-output-files", no_argument
, 0, 'y' },
291 { "yacc", no_argument
, 0, 'y' },
294 { "debug", no_argument
, 0, 't' },
295 { "locations", no_argument
, &locations_flag
, 1 },
296 { "no-lines", no_argument
, 0, 'l' },
297 { "no-parser", no_argument
, 0, 'n' },
298 { "raw", no_argument
, 0, 0 },
299 { "skeleton", required_argument
, 0, 'S' },
300 { "token-table", no_argument
, 0, 'k' },
305 /* Under DOS, there is no difference on the case. This can be
306 troublesome when looking for `.tab' etc. */
308 # define AS_FILE_NAME(File) (strlwr (File), (File))
310 # define AS_FILE_NAME(File) (File)
314 getargs (int argc
, char *argv
[])
318 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
, NULL
)) != EOF
)
322 /* Certain long options cause getopt_long to return 0. */
338 /* Here, the -g and --graph=FILE options are differentiated. */
340 spec_graph_file
= AS_FILE_NAME (optarg
);
344 report_flag
|= report_states
;
348 skeleton
= AS_FILE_NAME (optarg
);
352 include
= AS_FILE_NAME (optarg
);
356 /* Here, the -d and --defines options are differentiated. */
359 spec_defines_file
= AS_FILE_NAME (optarg
);
367 token_table_flag
= 1;
379 spec_outfile
= AS_FILE_NAME (optarg
);
383 spec_file_prefix
= AS_FILE_NAME (optarg
);
387 spec_name_prefix
= optarg
;
391 report_argmatch (optarg
);
395 trace_argmatch (optarg
);
399 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
406 fprintf (stderr
, _("%s: no grammar file given\n"), program_name
);
409 if (optind
< argc
- 1)
410 fprintf (stderr
, _("%s: extra arguments ignored after `%s'\n"),
411 program_name
, argv
[optind
]);
413 infile
= argv
[optind
];