main1.c revision 1.23 1 /* $NetBSD: main1.c,v 1.23 2014/04/18 01:18:54 christos 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 #if HAVE_NBTOOL_CONFIG_H
35 #include "nbtool_config.h"
36 #endif
37
38 #include <sys/cdefs.h>
39 #if defined(__RCSID) && !defined(lint)
40 __RCSID("$NetBSD: main1.c,v 1.23 2014/04/18 01:18:54 christos Exp $");
41 #endif
42
43 #include <sys/types.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <stdlib.h>
47 #include <unistd.h>
48 #include <errno.h>
49 #include <limits.h>
50 #include <signal.h>
51
52 #include "lint1.h"
53
54 /* set yydebug to 1*/
55 int yflag;
56
57 /*
58 * Print warnings if an assignment of an integertype to another integertype
59 * causes an implicit narrowing conversion. If aflag is 1, these warnings
60 * are printed only if the source type is at least as wide as long. If aflag
61 * is greater than 1, they are always printed.
62 */
63 int aflag;
64
65 /* Print a warning if a break statement cannot be reached. */
66 int bflag;
67
68 /* Print warnings for pointer casts. */
69 int cflag;
70
71 /* Print various debug information. */
72 int dflag;
73
74 /* Perform stricter checking of enum types and operations on enum types. */
75 int eflag;
76
77 /* Print complete pathnames, not only the basename. */
78 int Fflag;
79
80 /* Enable some extensions of gcc */
81 int gflag;
82
83 /* Treat warnings as errors */
84 int wflag;
85
86 /*
87 * Apply a number of heuristic tests to attempt to intuit bugs, improve
88 * style, and reduce waste.
89 */
90 int hflag;
91
92 /* Attempt to check portability to other dialects of C. */
93 int pflag;
94
95 /*
96 * In case of redeclarations/redefinitions print the location of the
97 * previous declaration/definition.
98 */
99 int rflag;
100
101 /* Strict ANSI C mode. */
102 int sflag;
103
104 /* Traditional C mode. */
105 int tflag;
106
107 /* Enable C9X extensions */
108 int Sflag;
109
110 /* Picky flag */
111 int Pflag;
112
113 /*
114 * Complain about functions and external variables used and not defined,
115 * or defined and not used.
116 */
117 int uflag = 1;
118
119 /* Complain about unused function arguments. */
120 int vflag = 1;
121
122 /* Complain about structures which are never defined. */
123 int zflag = 1;
124
125 err_set msgset;
126
127 sig_atomic_t fpe;
128
129 static void usage(void);
130
131 #ifdef __NetBSD__
132 static const char builtins[] =
133 "int __builtin_isinf(long double);\n"
134 "int __builtin_isnan(long double);\n"
135 "int __builtin_copysign(long double, long double);\n"
136 ;
137 #endif
138
139 /*ARGSUSED*/
140 static void
141 sigfpe(int s)
142 {
143 fpe = 1;
144 }
145
146 int
147 main(int argc, char *argv[])
148 {
149 int c;
150 char *ptr;
151
152 setprogname(argv[0]);
153
154 ERR_ZERO(&msgset);
155 while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFPSX:")) != -1) {
156 switch (c) {
157 case 'a': aflag++; break;
158 case 'b': bflag = 1; break;
159 case 'c': cflag = 1; break;
160 case 'd': dflag = 1; break;
161 case 'e': eflag = 1; break;
162 case 'F': Fflag = 1; break;
163 case 'g': gflag = 1; break;
164 case 'h': hflag = 1; break;
165 case 'p': pflag = 1; break;
166 case 'P': Pflag = 1; break;
167 case 'r': rflag = 1; break;
168 case 's': sflag = 1; break;
169 case 'S': Sflag = 1; break;
170 case 't': tflag = 1; break;
171 case 'u': uflag = 0; break;
172 case 'w': wflag = 1; break;
173 case 'v': vflag = 0; break;
174 case 'y': yflag = 1; break;
175 case 'z': zflag = 0; break;
176
177 case 'm':
178 msglist();
179 return(0);
180
181 case 'X':
182 for (ptr = strtok(optarg, ","); ptr;
183 ptr = strtok(NULL, ",")) {
184 char *eptr;
185 long msg;
186
187 errno = 0;
188 msg = strtol(ptr, &eptr, 0);
189 if ((msg == TARG_LONG_MIN || msg == TARG_LONG_MAX) &&
190 errno == ERANGE)
191 err(1, "invalid error message id '%s'",
192 ptr);
193 if (*eptr || ptr == eptr || msg < 0 ||
194 msg >= ERR_SETSIZE)
195 errx(1, "invalid error message id '%s'",
196 ptr);
197 ERR_SET(msg, &msgset);
198 }
199 break;
200 case '?':
201 default:
202 usage();
203 break;
204 }
205 }
206 argc -= optind;
207 argv += optind;
208
209 if (argc != 2)
210 usage();
211
212
213 /* initialize output */
214 outopen(argv[1]);
215
216 if (yflag)
217 yydebug = 1;
218
219 (void)signal(SIGFPE, sigfpe);
220 initmem();
221 initdecl();
222 initscan();
223 initmtab();
224
225 #ifdef __NetBSD__
226 if ((yyin = fmemopen(__UNCONST(builtins), sizeof(builtins) - 1, "r"))
227 == NULL)
228 err(1, "cannot open builtins");
229 yyparse();
230 #endif
231 /* open the input file */
232 if ((yyin = fopen(argv[0], "r")) == NULL)
233 err(1, "cannot open '%s'", argv[0]);
234 yyparse();
235
236 /* Following warnings cannot be suppressed by LINTED */
237 lwarn = LWARN_ALL;
238 #ifdef DEBUG
239 printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, lwarn);
240 #endif
241
242 chkglsyms();
243
244 outclose();
245
246 return (nerr != 0);
247 }
248
249 static void
250 usage(void)
251 {
252 (void)fprintf(stderr,
253 "Usage: %s [-abcdeghmprstuvwyzFS] [-X <id>[,<id>]... src dest\n",
254 getprogname());
255 exit(1);
256 }
257
258 void
259 norecover(void)
260 {
261 /* cannot recover from previous errors */
262 error(224);
263 exit(1);
264 }
265