]> git.saurik.com Git - bison.git/blame_incremental - src/getargs.c
# updates.
[bison.git] / src / getargs.c
... / ...
CommitLineData
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
26int verboseflag;
27int definesflag;
28int debugflag;
29int nolinesflag;
30int noparserflag = 0;
31int toknumflag = 0;
32int rawtoknumflag = 0;
33char *spec_name_prefix; /* for -p. */
34char *spec_file_prefix; /* for -b. */
35extern int fixed_outfiles;/* for -y */
36
37extern char *program_name;
38
39extern void warns PARAMS((char *, char *)); /* main.c */
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},
47 {"help", 0, 0, 'h'},
48 {"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
49 {"no-lines", 0, &nolinesflag, 1},
50 {"no-parser", 0, &noparserflag, 1},
51 {"output", 1, 0, 'o'},
52 {"output-file", 1, 0, 'o'},
53 {"raw", 0, &rawtoknumflag, 1},
54 {"token-table", 0, &toknumflag, 1},
55 {"verbose", 0, &verboseflag, 1},
56 {"version", 0, 0, 'V'},
57 {"yacc", 0, &fixed_outfiles, 1},
58 {0, 0, 0, 0}
59};
60
61/*---------------------------.
62| Display the help message. |
63`---------------------------*/
64void
65usage (FILE *stream)
66{
67 /* Some efforts were made to ease the translators' task, please
68 continue. */
69 fprintf (stream, _("\
70GNU bison generates parsers for LALR(1) grammars.\n"));
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
83 fprintf (stream, _("\
84Operation modes:\n\
85 -h, --help display this help and exit\n\
86 -V, --version output version information and exit\n\
87 -y, --yacc emulate POSIX yacc\n"));
88 putc ('\n', stream);
89
90 fprintf (stream, _("\
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\
98"));
99 putc ('\n', stream);
100
101 fprintf (stream, _("\
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\
106 -o, --output-file=FILE leave output to FILE\n"));
107 putc ('\n', stream);
108
109 fprintf (stream, _("\
110Report bugs to <bug-bison@gnu.org>.\n"),
111 program_name);
112}
113
114void
115getargs (int argc, char *argv[])
116{
117 register int c;
118
119 verboseflag = 0;
120 definesflag = 0;
121 debugflag = 0;
122 noparserflag = 0;
123 rawtoknumflag = 0;
124 toknumflag = 0;
125 fixed_outfiles = 0;
126
127 while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
128 != EOF)
129 {
130 switch (c)
131 {
132 case 0:
133 /* Certain long options cause getopt_long to return 0. */
134 break;
135
136 case 'y':
137 fixed_outfiles = 1;
138 break;
139
140 case 'h':
141 usage (stdout);
142 exit (0);
143
144 case 'V':
145 printf ("%s\n", VERSION_STRING);
146 exit (0);
147
148 case 'v':
149 verboseflag = 1;
150 break;
151
152 case 'd':
153 definesflag = 1;
154 break;
155
156 case 'l':
157 nolinesflag = 1;
158 break;
159
160 case 'k':
161 toknumflag = 1;
162 break;
163
164 case 'r':
165 rawtoknumflag = 1;
166 break;
167
168 case 'n':
169 noparserflag = 1;
170 break;
171
172 case 't':
173 debugflag = 1;
174 break;
175
176 case 'o':
177 spec_outfile = optarg;
178 break;
179
180 case 'b':
181 spec_file_prefix = optarg;
182 break;
183
184 case 'p':
185 spec_name_prefix = optarg;
186 break;
187
188 default:
189 usage (stderr);
190 exit (1);
191 }
192 }
193
194 if (optind == argc)
195 {
196 fprintf(stderr, _("%s: no grammar file given\n"), program_name);
197 exit(1);
198 }
199 if (optind < argc - 1)
200 fprintf(stderr, _("%s: extra arguments ignored after `%s'\n"),
201 program_name, argv[optind]);
202
203 infile = argv[optind];
204}