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