Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / xlint / lint1 / main1.c
1 /*      $NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo 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 #ifndef lint
35 static char rcsid[] = "$NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $";
36 #endif
37
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <err.h>
42
43 #include "lint1.h"
44
45 /* set yydebug to 1*/
46 int     yflag;
47
48 /*
49  * Print warnings if an assignment of an integertype to another integertype
50  * causes an implizit narrowing conversion. If aflag is 1, these warnings
51  * are printed only if the source type is at least as wide as long. If aflag
52  * is greather then 1, they are always printed.
53  */
54 int     aflag;
55
56 /* Print a warning if a break statement cannot be reached. */
57 int     bflag;
58
59 /* Print warnings for pointer casts. */
60 int     cflag;
61
62 /* Print various debug information. */
63 int     dflag;
64
65 /* Perform stricter checking of enum types and operations on enum types. */
66 int     eflag;
67
68 /* Print complete pathnames, not only the basename. */
69 int     Fflag;
70
71 /* Enable some extensions of gcc */
72 int     gflag;
73
74 /*
75  * Apply a number of heuristic tests to attempt to intuit bugs, improve
76  * style, and reduce waste.
77  */
78 int     hflag;
79
80 /* Attempt to check portability to other dialects of C. */
81 int     pflag;
82
83 /*
84  * In case of redeclarations/redefinitions print the location of the
85  * previous declaration/definition.
86  */
87 int     rflag;
88
89 /* Strict ANSI C mode. */
90 int     sflag;
91
92 /* Traditional C mode. */
93 int     tflag;
94
95 /*
96  * Complain about functions and external variables used and not defined,
97  * or defined and not used.
98  */
99 int     uflag = 1;
100
101 /* Complain about unused function arguments. */
102 int     vflag = 1;
103
104 /* Complain about structures which are never defined. */
105 int     zflag = 1;
106
107 static  void    usage __P((void));
108
109 int
110 main(argc, argv)
111         int     argc;
112         char    *argv[];
113 {
114         int     c;
115
116         while ((c = getopt(argc, argv, "abcdeghprstuvyzF")) != -1) {
117                 switch (c) {
118                 case 'a':       aflag++;        break;
119                 case 'b':       bflag = 1;      break;
120                 case 'c':       cflag = 1;      break;
121                 case 'd':       dflag = 1;      break;
122                 case 'e':       eflag = 1;      break;
123                 case 'F':       Fflag = 1;      break;
124                 case 'g':       gflag = 1;      break;
125                 case 'h':       hflag = 1;      break;
126                 case 'p':       pflag = 1;      break;
127                 case 'r':       rflag = 1;      break;
128                 case 's':       sflag = 1;      break;
129                 case 't':       tflag = 1;      break;
130                 case 'u':       uflag = 0;      break;
131                 case 'v':       vflag = 0;      break;
132                 case 'y':       yflag = 1;      break;
133                 case 'z':       zflag = 0;      break;
134                 case '?':       usage();
135                 }
136         }
137         argc -= optind;
138         argv += optind;
139
140         if (argc != 2)
141                 usage();
142
143         /* open the input file */
144         if ((yyin = fopen(argv[0], "r")) == NULL)
145                 err(1, "cannot open '%s'", argv[0]);
146
147         /* initialize output */
148         outopen(argv[1]);
149
150         if (yflag)
151                 yydebug = 1;
152
153         initmem();
154         initdecl();
155         initscan();
156         initmtab();
157
158         yyparse();
159
160         /* Following warnings cannot be suppressed by LINTED */
161         nowarn = 0;
162
163         chkglsyms();
164
165         outclose();
166
167         return (nerr != 0);
168 }
169
170 static void
171 usage()
172 {
173         (void)fprintf(stderr, "usage: lint1 [-abcdeghprstuvyzF] src dest\n");
174         exit(1);
175 }
176         
177 void
178 norecover()
179 {
180         /* cannot recover from previous errors */
181         error(224);
182         exit(1);
183 }