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