main1.c revision 1.10 1 /* $NetBSD: main1.c,v 1.10 2001/12/13 23:56:00 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for
18 * The NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 #ifndef lint
36 __RCSID("$NetBSD: main1.c,v 1.10 2001/12/13 23:56:00 augustss Exp $");
37 #endif
38
39 #include <sys/types.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <err.h>
45 #include <errno.h>
46 #include <limits.h>
47
48 #include "lint1.h"
49
50 /* set yydebug to 1*/
51 int yflag;
52
53 /*
54 * Print warnings if an assignment of an integertype to another integertype
55 * causes an implizit narrowing conversion. If aflag is 1, these warnings
56 * are printed only if the source type is at least as wide as long. If aflag
57 * is greater than 1, they are always printed.
58 */
59 int aflag;
60
61 /* Print a warning if a break statement cannot be reached. */
62 int bflag;
63
64 /* Print warnings for pointer casts. */
65 int cflag;
66
67 /* Print various debug information. */
68 int dflag;
69
70 /* Perform stricter checking of enum types and operations on enum types. */
71 int eflag;
72
73 /* Print complete pathnames, not only the basename. */
74 int Fflag;
75
76 /* Enable some extensions of gcc */
77 int gflag;
78
79 /* Treat warnings as errors */
80 int wflag;
81
82 /*
83 * Apply a number of heuristic tests to attempt to intuit bugs, improve
84 * style, and reduce waste.
85 */
86 int hflag;
87
88 /* Attempt to check portability to other dialects of C. */
89 int pflag;
90
91 /*
92 * In case of redeclarations/redefinitions print the location of the
93 * previous declaration/definition.
94 */
95 int rflag;
96
97 /* Strict ANSI C mode. */
98 int sflag;
99
100 /* Traditional C mode. */
101 int tflag;
102
103 /*
104 * Complain about functions and external variables used and not defined,
105 * or defined and not used.
106 */
107 int uflag = 1;
108
109 /* Complain about unused function arguments. */
110 int vflag = 1;
111
112 /* Complain about structures which are never defined. */
113 int zflag = 1;
114
115 err_set msgset;
116
117 static void usage(void);
118
119 int main(int, char *[]);
120
121 int
122 main(int argc, char *argv[])
123 {
124 int c;
125 char *ptr;
126
127 ERR_ZERO(&msgset);
128 while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) {
129 switch (c) {
130 case 'a': aflag++; break;
131 case 'b': bflag = 1; break;
132 case 'c': cflag = 1; break;
133 case 'd': dflag = 1; break;
134 case 'e': eflag = 1; break;
135 case 'F': Fflag = 1; break;
136 case 'g': gflag = 1; break;
137 case 'h': hflag = 1; break;
138 case 'p': pflag = 1; break;
139 case 'r': rflag = 1; break;
140 case 's': sflag = 1; break;
141 case 't': tflag = 1; break;
142 case 'u': uflag = 0; break;
143 case 'w': wflag = 1; break;
144 case 'v': vflag = 0; break;
145 case 'y': yflag = 1; break;
146 case 'z': zflag = 0; break;
147
148 case 'm':
149 msglist();
150 return(0);
151
152 case 'X':
153 for (ptr = strtok(optarg, ","); ptr;
154 ptr = strtok(NULL, ",")) {
155 char *eptr;
156 long msg = strtol(ptr, &eptr, 0);
157 if ((msg == LONG_MIN || msg == LONG_MAX) &&
158 errno == ERANGE)
159 err(1, "invalid error message id '%s'",
160 ptr);
161 if (*eptr || ptr == eptr || msg < 0 ||
162 msg >= ERR_SETSIZE)
163 errx(1, "invalid error message id '%s'",
164 ptr);
165 ERR_SET(msg, &msgset);
166 }
167 break;
168 case '?':
169 default:
170 usage();
171 break;
172 }
173 }
174 argc -= optind;
175 argv += optind;
176
177 if (argc != 2)
178 usage();
179
180 /* open the input file */
181 if ((yyin = fopen(argv[0], "r")) == NULL)
182 err(1, "cannot open '%s'", argv[0]);
183
184 /* initialize output */
185 outopen(argv[1]);
186
187 if (yflag)
188 yydebug = 1;
189
190 initmem();
191 initdecl();
192 initscan();
193 initmtab();
194
195 yyparse();
196
197 /* Following warnings cannot be suppressed by LINTED */
198 nowarn = 0;
199
200 chkglsyms();
201
202 outclose();
203
204 return (nerr != 0);
205 }
206
207 static void
208 usage(void)
209 {
210
211 (void)fprintf(stderr,
212 "Usage: %s [-abcdeghmprstuvwyzF] [-X <id>[,<id>]... src dest\n",
213 getprogname());
214 exit(1);
215 }
216
217 void
218 norecover(void)
219 {
220
221 /* cannot recover from previous errors */
222 error(224);
223 exit(1);
224 }
225