]> git.saurik.com Git - bison.git/blob - src/getargs.c
# updates.
[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
26 int verboseflag;
27 int definesflag;
28 int debugflag;
29 int nolinesflag;
30 int noparserflag = 0;
31 int toknumflag = 0;
32 int rawtoknumflag = 0;
33 char *spec_name_prefix; /* for -p. */
34 char *spec_file_prefix; /* for -b. */
35 extern int fixed_outfiles;/* for -y */
36
37 extern char *program_name;
38
39 extern void warns PARAMS((char *, char *)); /* main.c */
40
41 struct 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 `---------------------------*/
64 void
65 usage (FILE *stream)
66 {
67 /* Some efforts were made to ease the translators' task, please
68 continue. */
69 fprintf (stream, _("\
70 GNU bison generates parsers for LALR(1) grammars.\n"));
71 putc ('\n', stream);
72
73 fprintf (stream, _("\
74 Usage: %s [OPTION]... FILE\n"), program_name);
75 putc ('\n', stream);
76
77 fputs (_("\
78 If a long option shows an argument as mandatory, then it is mandatory\n\
79 for the equivalent short option also. Similarly for optional arguments.\n"),
80 stream);
81 putc ('\n', stream);
82
83 fprintf (stream, _("\
84 Operation 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, _("\
91 Parser:\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, _("\
102 Output:\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, _("\
110 Report bugs to <bug-bison@gnu.org>.\n"),
111 program_name);
112 }
113
114 void
115 getargs (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 }