]> git.saurik.com Git - bison.git/blob - src/getargs.c
890179ec5b5c3f5a72ad95c2330bc43cbb3fad8b
[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 "getargs.h"
26
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;
32 int raw_flag = 0;
33 char *skeleton = 0;
34 int token_table_flag = 0;
35 int verbose_flag = 0;
36 int statistics_flag = 0;
37 int yacc_flag = 0; /* for -y */
38
39 extern char *program_name;
40 const char *shortopts = "yvdhrltknVo:b:p:S:";
41 static struct option longopts[] =
42 {
43 /* Operation modes. */
44 {"help", no_argument, 0, 'h'},
45 {"version", no_argument, 0, 'V'},
46 {"yacc", no_argument, 0, 'y'},
47 {"fixed-output-files",no_argument, 0, 'y'},
48
49 /* Parser. */
50 {"skeleton", required_argument, 0, 'S'},
51 {"debug", no_argument, 0, 'd'},
52 {"locations", no_argument, &locations_flag, 1},
53 /* was 'a'; apparently unused -wjh */
54 {"name-prefix", required_argument, 0, 'p'},
55 {"no-lines", no_argument, 0, 'l'},
56 {"no-parser", no_argument, 0, 'n'},
57 {"raw", no_argument, 0, 'r'},
58 {"token-table", no_argument, 0, 'k'},
59
60 /* Output. */
61 {"defines", no_argument, 0, 'd'},
62 {"verbose", no_argument, 0, 'v'},
63 {"file-prefix", required_argument, 0, 'b'},
64 {"output-file", required_argument, 0, 'o'},
65
66 /* Hidden. */
67 {"statistics", no_argument, &statistics_flag, 1},
68 {0, 0, 0, 0}
69 };
70
71 /*---------------------------.
72 | Display the help message. |
73 `---------------------------*/
74
75 static void
76 usage (FILE *stream)
77 {
78 /* Some efforts were made to ease the translators' task, please
79 continue. */
80 fputs (_("\
81 GNU bison generates parsers for LALR(1) grammars.\n"), stream);
82 putc ('\n', stream);
83
84 fprintf (stream, _("\
85 Usage: %s [OPTION]... FILE\n"), program_name);
86 putc ('\n', stream);
87
88 fputs (_("\
89 If a long option shows an argument as mandatory, then it is mandatory\n\
90 for the equivalent short option also. Similarly for optional arguments.\n"),
91 stream);
92 putc ('\n', stream);
93
94 fputs (_("\
95 Operation modes:\n\
96 -h, --help display this help and exit\n\
97 -V, --version output version information and exit\n\
98 -y, --yacc emulate POSIX yacc\n"), stream);
99 putc ('\n', stream);
100
101 fputs (_("\
102 Parser:\n\
103 -S, --skeleton=FILE specify the skeleton to use\n\
104 -t, --debug instrument the parser for debugging\n\
105 --locations enable locations computation\n\
106 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
107 -l, --no-lines don't generate `#line' directives\n\
108 -n, --no-parser generate the tables only\n\
109 -r, --raw number the tokens from 3\n\
110 -k, --token-table include a table of token names\n\
111 "), stream);
112 putc ('\n', stream);
113
114 fputs (_("\
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\
119 -o, --output-file=FILE leave output to FILE\n"), stream);
120 putc ('\n', stream);
121
122 fputs (_("\
123 Report bugs to <bug-bison@gnu.org>.\n"), stream);
124 }
125
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 (_("\
142 Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.\n"),
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
157 void
158 getargs (int argc, char *argv[])
159 {
160 int c;
161
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':
202 raw_flag = 1;
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 }
230
231 if (optind == argc)
232 {
233 fprintf (stderr, _("%s: no grammar file given\n"), program_name);
234 exit (1);
235 }
236 if (optind < argc - 1)
237 fprintf (stderr, _("%s: extra arguments ignored after `%s'\n"),
238 program_name, argv[optind]);
239
240 infile = argv[optind];
241 }