]>
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
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
36 int locations_flag
= 0;
37 int no_lines_flag
= 0;
38 int no_parser_flag
= 0;
39 int report_flag
= report_none
;
40 int token_table_flag
= 0;
41 int yacc_flag
= 0; /* for -y */
43 int trace_flag
= trace_none
;
45 const char *skeleton
= NULL
;
46 const char *include
= NULL
;
48 extern char *program_name
;
51 /*---------------------.
52 | --trace's handling. |
53 `---------------------*/
55 static const char * const trace_args
[] =
57 /* In a series of synonyms, present the most meaningful first, so
58 that argmatch_valid be more readable. */
60 "scan - grammar scanner traces",
61 "parse - grammar parser traces",
62 "automaton - contruction of the automaton",
63 "bitsets - use of bitsets",
64 "grammar - reading, reducing of the grammar",
65 "resource - memory consumption (where available)",
66 "sets - grammar sets: firsts, nullable etc.",
67 "tools - m4 invocation and preserve the temporary file",
68 "skeleton - skeleton postprocessing",
69 "time - time consumption",
70 "all - all of the above",
74 static const int trace_types
[] =
92 trace_argmatch (char *args
)
94 verify (trace_constraint
, ARGMATCH_CONSTRAINT (trace_args
, trace_types
));
97 args
= strtok (args
, ",");
100 int trace
= XARGMATCH ("--trace", args
,
101 trace_args
, trace_types
);
102 if (trace
== trace_none
)
103 trace_flag
= trace_none
;
107 while ((args
= strtok (NULL
, ",")));
110 trace_flag
= trace_all
;
114 /*----------------------.
115 | --report's handling. |
116 `----------------------*/
118 static const char * const report_args
[] =
120 /* In a series of synonyms, present the most meaningful first, so
121 that argmatch_valid be more readable. */
124 "itemset", "itemsets",
125 "lookahead", "lookaheads",
131 static const int report_types
[] =
134 report_states
, report_states
,
135 report_states
| report_itemsets
, report_states
| report_itemsets
,
136 report_states
| report_lookaheads
, report_states
| report_lookaheads
,
137 report_states
| report_solved_conflicts
,
143 report_argmatch (char *args
)
145 verify (report_constraint
, ARGMATCH_CONSTRAINT (report_args
, report_types
));
146 args
= strtok (args
, ",");
149 int report
= XARGMATCH ("--report", args
,
150 report_args
, report_types
);
151 if (report
== report_none
)
152 report_flag
= report_none
;
154 report_flag
|= report
;
156 while ((args
= strtok (NULL
, ",")));
160 /*-------------------------------------------.
161 | Display the help message and exit STATUS. |
162 `-------------------------------------------*/
164 static void usage (int) ATTRIBUTE_NORETURN
;
170 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
174 /* Some efforts were made to ease the translators' task, please
177 GNU bison generates parsers for LALR(1) grammars.\n"), stdout
);
180 fprintf (stdout
, _("\
181 Usage: %s [OPTION]... FILE\n"), program_name
);
185 If a long option shows an argument as mandatory, then it is mandatory\n\
186 for the equivalent short option also. Similarly for optional arguments.\n"),
192 -h, --help display this help and exit\n\
193 -V, --version output version information and exit\n\
194 -y, --yacc emulate POSIX yacc\n"), stdout
);
199 -S, --skeleton=FILE specify the skeleton to use\n\
200 -t, --debug instrument the parser for debugging\n\
201 --locations enable locations computation\n\
202 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
203 -l, --no-lines don't generate `#line' directives\n\
204 -n, --no-parser generate the tables only\n\
205 -k, --token-table include a table of token names\n\
211 -d, --defines also produce a header file\n\
212 -r, --report=THINGS also produce details on the automaton\n\
213 -v, --verbose same as `--report=state'\n\
214 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
215 -o, --output=FILE leave output to FILE\n\
216 -g, --graph also produce a VCG description of the automaton\n\
221 THINGS is a list of comma separated words that can include:\n\
222 `state' describe the states\n\
223 `itemset' complete the core item sets with their closure\n\
224 `lookahead' explicitly associate lookaheads to items\n\
225 `solved' describe shift/reduce conflicts solving\n\
226 `all' include all the above information\n\
227 `none' disable the report\n\
232 Report bugs to <bug-bison@gnu.org>.\n"), stdout
);
239 /*------------------------------.
240 | Display the version message. |
241 `------------------------------*/
246 /* Some efforts were made to ease the translators' task, please
248 printf (_("bison (GNU Bison) %s"), VERSION
);
250 fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout
);
254 _("Copyright (C) %d Free Software Foundation, Inc.\n"), 2002);
257 This is free software; see the source for copying conditions. There is NO\n\
258 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
264 /*----------------------.
265 | Process the options. |
266 `----------------------*/
268 /* Shorts options. */
269 const char *short_options
= "yvegdhr:ltknVo:b:p:S:T::";
271 static struct option
const long_options
[] =
273 /* Operation modes. */
274 { "help", no_argument
, 0, 'h' },
275 { "version", no_argument
, 0, 'V' },
278 { "name-prefix", required_argument
, 0, 'p' },
279 { "include", required_argument
, 0, 'I' },
282 { "file-prefix", required_argument
, 0, 'b' },
283 { "output", required_argument
, 0, 'o' },
284 { "output-file", required_argument
, 0, 'o' },
285 { "graph", optional_argument
, 0, 'g' },
286 { "report", required_argument
, 0, 'r' },
287 { "verbose", no_argument
, 0, 'v' },
290 { "trace", optional_argument
, 0, 'T' },
293 { "defines", optional_argument
, 0, 'd' },
295 /* Operation modes. */
296 { "fixed-output-files", no_argument
, 0, 'y' },
297 { "yacc", no_argument
, 0, 'y' },
300 { "debug", no_argument
, 0, 't' },
301 { "locations", no_argument
, &locations_flag
, 1 },
302 { "no-lines", no_argument
, 0, 'l' },
303 { "no-parser", no_argument
, 0, 'n' },
304 { "raw", no_argument
, 0, 0 },
305 { "skeleton", required_argument
, 0, 'S' },
306 { "token-table", no_argument
, 0, 'k' },
311 /* Under DOS, there is no difference on the case. This can be
312 troublesome when looking for `.tab' etc. */
314 # define AS_FILE_NAME(File) (strlwr (File), (File))
316 # define AS_FILE_NAME(File) (File)
320 getargs (int argc
, char *argv
[])
324 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
, NULL
))
329 /* Certain long options cause getopt_long to return 0. */
337 usage (EXIT_SUCCESS
);
344 /* Here, the -g and --graph=FILE options are differentiated. */
346 spec_graph_file
= AS_FILE_NAME (optarg
);
350 report_flag
|= report_states
;
354 skeleton
= AS_FILE_NAME (optarg
);
358 include
= AS_FILE_NAME (optarg
);
362 /* Here, the -d and --defines options are differentiated. */
365 spec_defines_file
= AS_FILE_NAME (optarg
);
373 token_table_flag
= 1;
385 spec_outfile
= AS_FILE_NAME (optarg
);
389 spec_file_prefix
= AS_FILE_NAME (optarg
);
393 spec_name_prefix
= optarg
;
397 report_argmatch (optarg
);
401 trace_argmatch (optarg
);
405 usage (EXIT_FAILURE
);
408 if (argc
- optind
!= 1)
410 if (argc
- optind
< 1)
411 error (0, 0, _("missing operand after `%s'"), argv
[argc
- 1]);
413 error (0, 0, _("extra operand `%s'"), argv
[optind
+ 1]);
414 usage (EXIT_FAILURE
);
417 current_file
= grammar_file
= uniqstr_new (argv
[optind
]);