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