]>
Commit | Line | Data |
---|---|---|
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 | ||
26 | int verboseflag; | |
27 | int definesflag; | |
28 | int debugflag; | |
29 | int nolinesflag; | |
6dd6d212 RS |
30 | int noparserflag = 0; |
31 | int toknumflag = 0; | |
32 | int rawtoknumflag = 0; | |
3d8fc6ca RS |
33 | char *spec_name_prefix; /* for -p. */ |
34 | char *spec_file_prefix; /* for -b. */ | |
35 | extern int fixed_outfiles;/* for -y */ | |
d2729d44 | 36 | |
cbd8ffc5 | 37 | extern char *program_name; |
cbd8ffc5 | 38 | |
d2729d44 | 39 | extern void warns PARAMS((char *, char *)); /* main.c */ |
3d8fc6ca RS |
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}, | |
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 | 64 | void |
d2729d44 | 65 | usage (FILE *stream) |
cbd8ffc5 | 66 | { |
9f306f2a AD |
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 | ||
a083fbbf | 109 | fprintf (stream, _("\ |
9f306f2a | 110 | Report bugs to <bug-bison@gnu.org>.\n"), |
cbd8ffc5 DM |
111 | program_name); |
112 | } | |
113 | ||
3d8fc6ca | 114 | void |
d2729d44 | 115 | getargs (int argc, char *argv[]) |
3d8fc6ca RS |
116 | { |
117 | register int c; | |
3d8fc6ca RS |
118 | |
119 | verboseflag = 0; | |
120 | definesflag = 0; | |
121 | debugflag = 0; | |
6dd6d212 RS |
122 | noparserflag = 0; |
123 | rawtoknumflag = 0; | |
124 | toknumflag = 0; | |
3d8fc6ca RS |
125 | fixed_outfiles = 0; |
126 | ||
6dd6d212 | 127 | while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0)) |
3d8fc6ca RS |
128 | != EOF) |
129 | { | |
3d8fc6ca RS |
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; | |
9f306f2a | 139 | |
cbd8ffc5 DM |
140 | case 'h': |
141 | usage (stdout); | |
142 | exit (0); | |
143 | ||
3d8fc6ca | 144 | case 'V': |
6ed61226 | 145 | printf ("%s\n", VERSION_STRING); |
cbd8ffc5 | 146 | exit (0); |
9f306f2a | 147 | |
3d8fc6ca RS |
148 | case 'v': |
149 | verboseflag = 1; | |
150 | break; | |
9f306f2a | 151 | |
3d8fc6ca RS |
152 | case 'd': |
153 | definesflag = 1; | |
154 | break; | |
9f306f2a | 155 | |
3d8fc6ca RS |
156 | case 'l': |
157 | nolinesflag = 1; | |
158 | break; | |
9f306f2a | 159 | |
6dd6d212 RS |
160 | case 'k': |
161 | toknumflag = 1; | |
162 | break; | |
163 | ||
164 | case 'r': | |
165 | rawtoknumflag = 1; | |
166 | break; | |
9f306f2a | 167 | |
6dd6d212 RS |
168 | case 'n': |
169 | noparserflag = 1; | |
170 | break; | |
9f306f2a | 171 | |
3d8fc6ca RS |
172 | case 't': |
173 | debugflag = 1; | |
174 | break; | |
9f306f2a | 175 | |
3d8fc6ca RS |
176 | case 'o': |
177 | spec_outfile = optarg; | |
178 | break; | |
9f306f2a | 179 | |
3d8fc6ca RS |
180 | case 'b': |
181 | spec_file_prefix = optarg; | |
182 | break; | |
9f306f2a | 183 | |
3d8fc6ca RS |
184 | case 'p': |
185 | spec_name_prefix = optarg; | |
186 | break; | |
9f306f2a | 187 | |
3d8fc6ca | 188 | default: |
cbd8ffc5 | 189 | usage (stderr); |
3d8fc6ca RS |
190 | exit (1); |
191 | } | |
192 | } | |
193 | ||
194 | if (optind == argc) | |
195 | { | |
a083fbbf | 196 | fprintf(stderr, _("%s: no grammar file given\n"), program_name); |
3d8fc6ca RS |
197 | exit(1); |
198 | } | |
199 | if (optind < argc - 1) | |
9f306f2a AD |
200 | fprintf(stderr, _("%s: extra arguments ignored after `%s'\n"), |
201 | program_name, argv[optind]); | |
3d8fc6ca RS |
202 | |
203 | infile = argv[optind]; | |
204 | } |