]>
Commit | Line | Data |
---|---|---|
9f306f2a | 1 | /* Parse command line arguments for bison. |
cd5bd6ac | 2 | Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc. |
3d8fc6ca | 3 | |
9f306f2a | 4 | This file is part of Bison, the GNU Compiler Compiler. |
3d8fc6ca | 5 | |
9f306f2a AD |
6 | Bison is free software; you can redistribute it and/or modify it |
7 | under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
3d8fc6ca | 10 | |
9f306f2a AD |
11 | Bison is distributed in the hope that it will be useful, but |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License for more details. | |
3d8fc6ca | 15 | |
9f306f2a AD |
16 | You should have received a copy of the GNU General Public License |
17 | along with Bison; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
3d8fc6ca RS |
20 | |
21 | #include <stdio.h> | |
22 | #include "getopt.h" | |
23 | #include "system.h" | |
24 | #include "files.h" | |
b0ce6046 | 25 | #include "complain.h" |
ceed8467 | 26 | #include "getargs.h" |
3d8fc6ca | 27 | |
89cab50d AD |
28 | int debug_flag = 0; |
29 | int defines_flag = 0; | |
30 | int locations_flag = 0; | |
31 | int no_lines_flag = 0; | |
32 | int no_parser_flag = 0; | |
89cab50d AD |
33 | int token_table_flag = 0; |
34 | int verbose_flag = 0; | |
35 | int statistics_flag = 0; | |
36 | int yacc_flag = 0; /* for -y */ | |
d2729d44 | 37 | |
b0ce6046 AD |
38 | const char *skeleton = NULL; |
39 | ||
cbd8ffc5 | 40 | extern char *program_name; |
cd5bd6ac | 41 | const char *shortopts = "yvdhrltknVo:b:p:S:"; |
4a120d45 | 42 | static struct option longopts[] = |
3d8fc6ca | 43 | { |
447992b9 AD |
44 | /* Operation modes. */ |
45 | {"help", no_argument, 0, 'h'}, | |
46 | {"version", no_argument, 0, 'V'}, | |
47 | {"yacc", no_argument, 0, 'y'}, | |
48 | {"fixed-output-files",no_argument, 0, 'y'}, | |
49 | ||
50 | /* Parser. */ | |
cd5bd6ac AD |
51 | {"skeleton", required_argument, 0, 'S'}, |
52 | {"debug", no_argument, 0, 'd'}, | |
447992b9 AD |
53 | {"locations", no_argument, &locations_flag, 1}, |
54 | /* was 'a'; apparently unused -wjh */ | |
55 | {"name-prefix", required_argument, 0, 'p'}, | |
56 | {"no-lines", no_argument, 0, 'l'}, | |
57 | {"no-parser", no_argument, 0, 'n'}, | |
58 | {"raw", no_argument, 0, 'r'}, | |
59 | {"token-table", no_argument, 0, 'k'}, | |
447992b9 AD |
60 | |
61 | /* Output. */ | |
62 | {"defines", no_argument, 0, 'd'}, | |
63 | {"verbose", no_argument, 0, 'v'}, | |
64 | {"file-prefix", required_argument, 0, 'b'}, | |
65 | {"output-file", required_argument, 0, 'o'}, | |
66 | ||
67 | /* Hidden. */ | |
68 | {"statistics", no_argument, &statistics_flag, 1}, | |
3d8fc6ca RS |
69 | {0, 0, 0, 0} |
70 | }; | |
71 | ||
9f306f2a AD |
72 | /*---------------------------. |
73 | | Display the help message. | | |
74 | `---------------------------*/ | |
e79137ac | 75 | |
4a120d45 | 76 | static void |
d2729d44 | 77 | usage (FILE *stream) |
cbd8ffc5 | 78 | { |
9f306f2a AD |
79 | /* Some efforts were made to ease the translators' task, please |
80 | continue. */ | |
a0f6b076 AD |
81 | fputs (_("\ |
82 | GNU bison generates parsers for LALR(1) grammars.\n"), stream); | |
9f306f2a AD |
83 | putc ('\n', stream); |
84 | ||
85 | fprintf (stream, _("\ | |
86 | Usage: %s [OPTION]... FILE\n"), program_name); | |
87 | putc ('\n', stream); | |
88 | ||
89 | fputs (_("\ | |
90 | If a long option shows an argument as mandatory, then it is mandatory\n\ | |
91 | for the equivalent short option also. Similarly for optional arguments.\n"), | |
92 | stream); | |
93 | putc ('\n', stream); | |
94 | ||
a0f6b076 | 95 | fputs (_("\ |
9f306f2a AD |
96 | Operation modes:\n\ |
97 | -h, --help display this help and exit\n\ | |
98 | -V, --version output version information and exit\n\ | |
a0f6b076 | 99 | -y, --yacc emulate POSIX yacc\n"), stream); |
9f306f2a AD |
100 | putc ('\n', stream); |
101 | ||
a0f6b076 | 102 | fputs (_("\ |
9f306f2a | 103 | Parser:\n\ |
cd5bd6ac | 104 | -S, --skeleton=FILE specify the skeleton to use\n\ |
9f306f2a | 105 | -t, --debug instrument the parser for debugging\n\ |
89cab50d | 106 | --locations enable locations computation\n\ |
9f306f2a AD |
107 | -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\ |
108 | -l, --no-lines don't generate `#line' directives\n\ | |
109 | -n, --no-parser generate the tables only\n\ | |
9f306f2a | 110 | -k, --token-table include a table of token names\n\ |
a0f6b076 | 111 | "), stream); |
9f306f2a AD |
112 | putc ('\n', stream); |
113 | ||
a0f6b076 | 114 | fputs (_("\ |
9f306f2a AD |
115 | Output:\n\ |
116 | -d, --defines also produce a header file\n\ | |
117 | -v, --verbose also produce an explanation of the automaton\n\ | |
118 | -b, --file-prefix=PREFIX specify a PREFIX for output files\n\ | |
a0f6b076 | 119 | -o, --output-file=FILE leave output to FILE\n"), stream); |
9f306f2a AD |
120 | putc ('\n', stream); |
121 | ||
a0f6b076 AD |
122 | fputs (_("\ |
123 | Report bugs to <bug-bison@gnu.org>.\n"), stream); | |
cbd8ffc5 DM |
124 | } |
125 | ||
e79137ac AD |
126 | |
127 | /*------------------------------. | |
128 | | Display the version message. | | |
129 | `------------------------------*/ | |
130 | ||
131 | static void | |
132 | version (FILE *stream) | |
133 | { | |
134 | /* Some efforts were made to ease the translators' task, please | |
135 | continue. */ | |
136 | fprintf (stream, _("\ | |
137 | bison (GNU Bison) %s"), VERSION); | |
138 | putc ('\n', stream); | |
139 | putc ('\n', stream); | |
140 | ||
141 | fputs (_("\ | |
cd5bd6ac | 142 | Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.\n"), |
e79137ac AD |
143 | stream); |
144 | ||
145 | fputs (_("\ | |
146 | This is free software; see the source for copying conditions. There is NO\n\ | |
147 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ | |
148 | "), | |
149 | stream); | |
150 | } | |
151 | ||
152 | ||
153 | /*----------------------. | |
154 | | Process the options. | | |
155 | `----------------------*/ | |
156 | ||
3d8fc6ca | 157 | void |
d2729d44 | 158 | getargs (int argc, char *argv[]) |
3d8fc6ca | 159 | { |
1916f98e | 160 | int c; |
3d8fc6ca | 161 | |
cd5bd6ac AD |
162 | while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != EOF) |
163 | switch (c) | |
164 | { | |
165 | case 0: | |
166 | /* Certain long options cause getopt_long to return 0. */ | |
167 | break; | |
168 | ||
169 | case 'y': | |
170 | yacc_flag = 1; | |
171 | break; | |
172 | ||
173 | case 'h': | |
174 | usage (stdout); | |
175 | exit (0); | |
176 | ||
177 | case 'V': | |
178 | version (stdout); | |
179 | exit (0); | |
180 | ||
181 | case 'v': | |
182 | verbose_flag = 1; | |
183 | break; | |
184 | ||
185 | case 'S': | |
186 | skeleton = optarg; | |
187 | break; | |
188 | ||
189 | case 'd': | |
190 | defines_flag = 1; | |
191 | break; | |
192 | ||
193 | case 'l': | |
194 | no_lines_flag = 1; | |
195 | break; | |
196 | ||
197 | case 'k': | |
198 | token_table_flag = 1; | |
199 | break; | |
200 | ||
201 | case 'r': | |
62ab6972 | 202 | fatal (_("`%s' is no longer supported"), "--raw"); |
cd5bd6ac AD |
203 | break; |
204 | ||
205 | case 'n': | |
206 | no_parser_flag = 1; | |
207 | break; | |
208 | ||
209 | case 't': | |
210 | debug_flag = 1; | |
211 | break; | |
212 | ||
213 | case 'o': | |
214 | spec_outfile = optarg; | |
215 | break; | |
216 | ||
217 | case 'b': | |
218 | spec_file_prefix = optarg; | |
219 | break; | |
220 | ||
221 | case 'p': | |
222 | spec_name_prefix = optarg; | |
223 | break; | |
224 | ||
225 | default: | |
226 | fprintf (stderr, _("Try `%s --help' for more information.\n"), | |
227 | program_name); | |
228 | exit (1); | |
229 | } | |
3d8fc6ca RS |
230 | |
231 | if (optind == argc) | |
232 | { | |
e79137ac AD |
233 | fprintf (stderr, _("%s: no grammar file given\n"), program_name); |
234 | exit (1); | |
3d8fc6ca RS |
235 | } |
236 | if (optind < argc - 1) | |
e79137ac AD |
237 | fprintf (stderr, _("%s: extra arguments ignored after `%s'\n"), |
238 | program_name, argv[optind]); | |
3d8fc6ca RS |
239 | |
240 | infile = argv[optind]; | |
241 | } |