]> git.saurik.com Git - bison.git/blame - src/getargs.c
Add tryclose(), which verifies that fclose was successful.
[bison.git] / src / getargs.c
CommitLineData
3d8fc6ca 1/* Parse command line arguments for bison,
6dd6d212 2 Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
3d8fc6ca
RS
3
4This file is part of Bison, the GNU Compiler Compiler.
5
6Bison is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Bison is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Bison; see the file COPYING. If not, write to
c49a8e71
JT
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
3d8fc6ca
RS
20
21
22#include <stdio.h>
23#include "getopt.h"
24#include "system.h"
25#include "files.h"
26
27int verboseflag;
28int definesflag;
29int debugflag;
30int nolinesflag;
6dd6d212
RS
31int noparserflag = 0;
32int toknumflag = 0;
33int rawtoknumflag = 0;
3d8fc6ca
RS
34char *spec_name_prefix; /* for -p. */
35char *spec_file_prefix; /* for -b. */
36extern int fixed_outfiles;/* for -y */
6dd6d212 37
d2729d44
JT
38void usage PARAMS((FILE *));
39void getargs PARAMS((int, char *[]));
40
cbd8ffc5
DM
41extern char *program_name;
42extern char *version_string;
43
d2729d44 44extern void warns PARAMS((char *, char *)); /* main.c */
3d8fc6ca
RS
45
46struct option longopts[] =
47{
48 {"debug", 0, &debugflag, 1},
49 {"defines", 0, &definesflag, 1},
50 {"file-prefix", 1, 0, 'b'},
51 {"fixed-output-files", 0, &fixed_outfiles, 1},
cbd8ffc5 52 {"help", 0, 0, 'h'},
6dd6d212 53 {"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
3d8fc6ca 54 {"no-lines", 0, &nolinesflag, 1},
6dd6d212 55 {"no-parser", 0, &noparserflag, 1},
3d8fc6ca
RS
56 {"output", 1, 0, 'o'},
57 {"output-file", 1, 0, 'o'},
6dd6d212
RS
58 {"raw", 0, &rawtoknumflag, 1},
59 {"token-table", 0, &toknumflag, 1},
3d8fc6ca
RS
60 {"verbose", 0, &verboseflag, 1},
61 {"version", 0, 0, 'V'},
62 {"yacc", 0, &fixed_outfiles, 1},
63 {0, 0, 0, 0}
64};
65
cbd8ffc5 66void
d2729d44 67usage (FILE *stream)
cbd8ffc5 68{
a083fbbf 69 fprintf (stream, _("\
6dd6d212 70Usage: %s [-dhklntvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
cbd8ffc5
DM
71 [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
72 [--verbose] [--version] [--help] [--yacc]\n\
6dd6d212 73 [--no-parser] [--token-table]\n\
cbd8ffc5 74 [--file-prefix=prefix] [--name-prefix=prefix]\n\
5c9ba631
JT
75 [--output=outfile] grammar-file\n\n\
76Report bugs to bug-bison@gnu.org\n"),
cbd8ffc5
DM
77 program_name);
78}
79
3d8fc6ca 80void
d2729d44 81getargs (int argc, char *argv[])
3d8fc6ca
RS
82{
83 register int c;
3d8fc6ca
RS
84
85 verboseflag = 0;
86 definesflag = 0;
87 debugflag = 0;
6dd6d212
RS
88 noparserflag = 0;
89 rawtoknumflag = 0;
90 toknumflag = 0;
3d8fc6ca
RS
91 fixed_outfiles = 0;
92
6dd6d212 93 while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
3d8fc6ca
RS
94 != EOF)
95 {
3d8fc6ca
RS
96 switch (c)
97 {
98 case 0:
99 /* Certain long options cause getopt_long to return 0. */
100 break;
101
102 case 'y':
103 fixed_outfiles = 1;
104 break;
105
cbd8ffc5
DM
106 case 'h':
107 usage (stdout);
108 exit (0);
109
3d8fc6ca 110 case 'V':
cbd8ffc5
DM
111 printf ("%s", version_string);
112 exit (0);
3d8fc6ca
RS
113
114 case 'v':
115 verboseflag = 1;
116 break;
117
118 case 'd':
119 definesflag = 1;
120 break;
121
122 case 'l':
123 nolinesflag = 1;
124 break;
125
6dd6d212
RS
126 case 'k':
127 toknumflag = 1;
128 break;
129
130 case 'r':
131 rawtoknumflag = 1;
132 break;
133
134 case 'n':
135 noparserflag = 1;
136 break;
137
3d8fc6ca
RS
138 case 't':
139 debugflag = 1;
140 break;
141
142 case 'o':
143 spec_outfile = optarg;
144 break;
145
146 case 'b':
147 spec_file_prefix = optarg;
148 break;
149
150 case 'p':
151 spec_name_prefix = optarg;
152 break;
153
154 default:
cbd8ffc5 155 usage (stderr);
3d8fc6ca
RS
156 exit (1);
157 }
158 }
159
160 if (optind == argc)
161 {
a083fbbf 162 fprintf(stderr, _("%s: no grammar file given\n"), program_name);
3d8fc6ca
RS
163 exit(1);
164 }
165 if (optind < argc - 1)
a083fbbf 166 fprintf(stderr, _("%s: extra arguments ignored after '%s'\n"),
6dd6d212 167 program_name, argv[optind]);
3d8fc6ca
RS
168
169 infile = argv[optind];
170}