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