main2.c revision 1.3 1 /* $NetBSD: main2.c,v 1.3 1998/02/22 15:40:41 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 #ifndef lint
36 __RCSID("$NetBSD: main2.c,v 1.3 1998/02/22 15:40:41 christos Exp $");
37 #endif
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <unistd.h>
43
44 #include "lint2.h"
45
46 /* warnings for symbols which are declared but not defined or used */
47 int xflag;
48
49 /*
50 * warnings for symbols which are used and not defined or defined
51 * and not used
52 */
53 int uflag = 1;
54
55 /* Create a lint library in the current directory with name libname. */
56 int Cflag;
57 const char *libname;
58
59 int pflag;
60
61 /*
62 * warnings for (tentative) definitions of the same name in more then
63 * one translation unit
64 */
65 int sflag;
66
67 int tflag;
68
69 /*
70 * If a complaint stems from a included file, print the name of the included
71 * file instead of the name spezified at the command line followed by '?'
72 */
73 int Hflag;
74
75 int hflag;
76
77 /* Print full path names, not only the last component */
78 int Fflag;
79
80 /*
81 * List of libraries (from -l flag). These libraries are read after all
82 * other input files has been read and, for Cflag, after the new lint library
83 * has been written.
84 */
85 const char **libs;
86
87 static void usage __P((void));
88
89 int main __P((int, char *[]));
90
91 int
92 main(argc, argv)
93 int argc;
94 char *argv[];
95 {
96 int c, i;
97 size_t len;
98 char *lname;
99
100 libs = xcalloc(1, sizeof (char *));
101
102 opterr = 0;
103 while ((c = getopt(argc, argv, "hpstxuC:HFl:")) != -1) {
104 switch (c) {
105 case 's':
106 sflag = 1;
107 break;
108 case 't':
109 tflag = 1;
110 break;
111 case 'u':
112 uflag = 0;
113 break;
114 case 'x':
115 xflag = 1;
116 break;
117 case 'p':
118 pflag = 1;
119 break;
120 case 'C':
121 len = strlen(optarg);
122 lname = xmalloc(len + 10);
123 (void)sprintf(lname, "llib-l%s.ln", optarg);
124 libname = lname;
125 Cflag = 1;
126 uflag = 0;
127 break;
128 case 'H':
129 Hflag = 1;
130 break;
131 case 'h':
132 hflag = 1;
133 break;
134 case 'F':
135 Fflag = 1;
136 break;
137 case 'l':
138 for (i = 0; libs[i] != NULL; i++) ;
139 libs = xrealloc(libs, (i + 2) * sizeof (char *));
140 libs[i] = xstrdup(optarg);
141 libs[i + 1] = NULL;
142 break;
143 case '?':
144 usage();
145 }
146 }
147
148 argc -= optind;
149 argv += optind;
150
151 if (argc == 0)
152 usage();
153
154 initmem();
155
156 /* initialize hash table */
157 inithash();
158
159 inittyp();
160
161 for (i = 0; i < argc; i++)
162 readfile(argv[i]);
163
164 /* write the lint library */
165 if (Cflag) {
166 forall(mkstatic);
167 outlib(libname);
168 }
169
170 /* read additional libraries */
171 for (i = 0; libs[i] != NULL; i++)
172 readfile(libs[i]);
173
174 forall(mkstatic);
175
176 mainused();
177
178 /* perform all tests */
179 forall(chkname);
180
181 exit(0);
182 /* NOTREACHED */
183 }
184
185 static void
186 usage()
187 {
188 (void)fprintf(stderr,
189 "usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n");
190 exit(1);
191 }
192
193