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