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