]> git.saurik.com Git - bison.git/blame - src/getargs.c
Clean the error reporting functions.
[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"
25
26int verboseflag;
27int definesflag;
28int debugflag;
29int nolinesflag;
6dd6d212
RS
30int noparserflag = 0;
31int toknumflag = 0;
32int rawtoknumflag = 0;
3d8fc6ca
RS
33char *spec_name_prefix; /* for -p. */
34char *spec_file_prefix; /* for -b. */
35extern int fixed_outfiles;/* for -y */
d2729d44 36
cbd8ffc5 37extern char *program_name;
cbd8ffc5 38
d2729d44 39extern void warns PARAMS((char *, char *)); /* main.c */
3d8fc6ca
RS
40
41struct option longopts[] =
42{
43 {"debug", 0, &debugflag, 1},
44 {"defines", 0, &definesflag, 1},
45 {"file-prefix", 1, 0, 'b'},
46 {"fixed-output-files", 0, &fixed_outfiles, 1},
cbd8ffc5 47 {"help", 0, 0, 'h'},
6dd6d212 48 {"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
3d8fc6ca 49 {"no-lines", 0, &nolinesflag, 1},
6dd6d212 50 {"no-parser", 0, &noparserflag, 1},
3d8fc6ca
RS
51 {"output", 1, 0, 'o'},
52 {"output-file", 1, 0, 'o'},
6dd6d212
RS
53 {"raw", 0, &rawtoknumflag, 1},
54 {"token-table", 0, &toknumflag, 1},
3d8fc6ca
RS
55 {"verbose", 0, &verboseflag, 1},
56 {"version", 0, 0, 'V'},
57 {"yacc", 0, &fixed_outfiles, 1},
58 {0, 0, 0, 0}
59};
60
9f306f2a
AD
61/*---------------------------.
62| Display the help message. |
63`---------------------------*/
cbd8ffc5 64void
d2729d44 65usage (FILE *stream)
cbd8ffc5 66{
9f306f2a
AD
67 /* Some efforts were made to ease the translators' task, please
68 continue. */
a0f6b076
AD
69 fputs (_("\
70GNU bison generates parsers for LALR(1) grammars.\n"), stream);
9f306f2a
AD
71 putc ('\n', stream);
72
73 fprintf (stream, _("\
74Usage: %s [OPTION]... FILE\n"), program_name);
75 putc ('\n', stream);
76
77 fputs (_("\
78If a long option shows an argument as mandatory, then it is mandatory\n\
79for the equivalent short option also. Similarly for optional arguments.\n"),
80 stream);
81 putc ('\n', stream);
82
a0f6b076 83 fputs (_("\
9f306f2a
AD
84Operation modes:\n\
85 -h, --help display this help and exit\n\
86 -V, --version output version information and exit\n\
a0f6b076 87 -y, --yacc emulate POSIX yacc\n"), stream);
9f306f2a
AD
88 putc ('\n', stream);
89
a0f6b076 90 fputs (_("\
9f306f2a
AD
91Parser:\n\
92 -t, --debug instrument the parser for debugging\n\
93 -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
94 -l, --no-lines don't generate `#line' directives\n\
95 -n, --no-parser generate the tables only\n\
96 -r, --raw number the tokens from 3\n\
97 -k, --token-table include a table of token names\n\
a0f6b076 98"), stream);
9f306f2a
AD
99 putc ('\n', stream);
100
a0f6b076 101 fputs (_("\
9f306f2a
AD
102Output:\n\
103 -d, --defines also produce a header file\n\
104 -v, --verbose also produce an explanation of the automaton\n\
105 -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
a0f6b076 106 -o, --output-file=FILE leave output to FILE\n"), stream);
9f306f2a
AD
107 putc ('\n', stream);
108
a0f6b076
AD
109 fputs (_("\
110Report bugs to <bug-bison@gnu.org>.\n"), stream);
cbd8ffc5
DM
111}
112
3d8fc6ca 113void
d2729d44 114getargs (int argc, char *argv[])
3d8fc6ca
RS
115{
116 register int c;
3d8fc6ca
RS
117
118 verboseflag = 0;
119 definesflag = 0;
120 debugflag = 0;
6dd6d212
RS
121 noparserflag = 0;
122 rawtoknumflag = 0;
123 toknumflag = 0;
3d8fc6ca
RS
124 fixed_outfiles = 0;
125
6dd6d212 126 while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
3d8fc6ca
RS
127 != EOF)
128 {
3d8fc6ca
RS
129 switch (c)
130 {
131 case 0:
132 /* Certain long options cause getopt_long to return 0. */
133 break;
134
135 case 'y':
136 fixed_outfiles = 1;
137 break;
9f306f2a 138
cbd8ffc5
DM
139 case 'h':
140 usage (stdout);
141 exit (0);
142
3d8fc6ca 143 case 'V':
6ed61226 144 printf ("%s\n", VERSION_STRING);
cbd8ffc5 145 exit (0);
9f306f2a 146
3d8fc6ca
RS
147 case 'v':
148 verboseflag = 1;
149 break;
9f306f2a 150
3d8fc6ca
RS
151 case 'd':
152 definesflag = 1;
153 break;
9f306f2a 154
3d8fc6ca
RS
155 case 'l':
156 nolinesflag = 1;
157 break;
9f306f2a 158
6dd6d212
RS
159 case 'k':
160 toknumflag = 1;
161 break;
162
163 case 'r':
164 rawtoknumflag = 1;
165 break;
9f306f2a 166
6dd6d212
RS
167 case 'n':
168 noparserflag = 1;
169 break;
9f306f2a 170
3d8fc6ca
RS
171 case 't':
172 debugflag = 1;
173 break;
9f306f2a 174
3d8fc6ca
RS
175 case 'o':
176 spec_outfile = optarg;
177 break;
9f306f2a 178
3d8fc6ca
RS
179 case 'b':
180 spec_file_prefix = optarg;
181 break;
9f306f2a 182
3d8fc6ca
RS
183 case 'p':
184 spec_name_prefix = optarg;
185 break;
9f306f2a 186
3d8fc6ca 187 default:
cbd8ffc5 188 usage (stderr);
3d8fc6ca
RS
189 exit (1);
190 }
191 }
192
193 if (optind == argc)
194 {
a083fbbf 195 fprintf(stderr, _("%s: no grammar file given\n"), program_name);
3d8fc6ca
RS
196 exit(1);
197 }
198 if (optind < argc - 1)
9f306f2a
AD
199 fprintf(stderr, _("%s: extra arguments ignored after `%s'\n"),
200 program_name, argv[optind]);
3d8fc6ca
RS
201
202 infile = argv[optind];
203}