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