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