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