libm: Fix typos in Makefile comments.
[dragonfly.git] / usr.bin / xlint / lint2 / main2.c
blobc2ddb7cb42f0ff190e0e0e29420c6a8d5b5cd176
1 /* $NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $ */
3 /*
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
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.
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.
33 * $NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $
34 * $DragonFly: src/usr.bin/xlint/lint2/main2.c,v 1.6 2004/07/07 12:24:01 asmodai Exp $
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
42 #include "lint2.h"
44 /* warnings for symbols which are declared but not defined or used */
45 int xflag;
48 * warnings for symbols which are used and not defined or defined
49 * and not used
51 int uflag = 1;
53 /* Create a lint library in the current directory with name libname. */
54 int Cflag;
55 const char *libname;
57 int pflag;
60 * warnings for (tentative) definitions of the same name in more then
61 * one translation unit
63 int sflag;
65 int tflag;
68 * If a complaint stems from a included file, print the name of the included
69 * file instead of the name spezified at the command line followed by '?'
71 int Hflag;
73 int hflag;
75 /* Print full path names, not only the last component */
76 int Fflag;
79 * List of libraries (from -l flag). These libraries are read after all
80 * other input files has been read and, for Cflag, after the new lint library
81 * has been written.
83 const char **libs;
85 static void usage(void);
88 int
89 main(int argc, char *argv[])
91 int c, i;
92 size_t len;
93 char *lname;
95 libs = xcalloc(1, sizeof (char *));
97 opterr = 0;
98 while ((c = getopt(argc, argv, "hpstxuC:HFl:")) != -1) {
99 switch (c) {
100 case 's':
101 sflag = 1;
102 break;
103 case 't':
104 tflag = 1;
105 break;
106 case 'u':
107 uflag = 0;
108 break;
109 case 'x':
110 xflag = 1;
111 break;
112 case 'p':
113 pflag = 1;
114 break;
115 case 'C':
116 len = strlen(optarg);
117 lname = xmalloc(len + 10);
118 (void)sprintf(lname, "llib-l%s.ln", optarg);
119 libname = lname;
120 Cflag = 1;
121 uflag = 0;
122 break;
123 case 'H':
124 Hflag = 1;
125 break;
126 case 'h':
127 hflag = 1;
128 break;
129 case 'F':
130 Fflag = 1;
131 break;
132 case 'l':
133 for (i = 0; libs[i] != NULL; i++) ;
134 libs = xrealloc(libs, (i + 2) * sizeof (char *));
135 libs[i] = xstrdup(optarg);
136 libs[i + 1] = NULL;
137 break;
138 case '?':
139 usage();
143 argc -= optind;
144 argv += optind;
146 if (argc == 0)
147 usage();
149 initmem();
151 /* initialize hash table */
152 inithash();
154 inittyp();
156 for (i = 0; i < argc; i++)
157 readfile(argv[i]);
159 /* write the lint library */
160 if (Cflag) {
161 forall(mkstatic);
162 outlib(libname);
165 /* read additional libraries */
166 for (i = 0; libs[i] != NULL; i++)
167 readfile(libs[i]);
169 forall(mkstatic);
171 mainused();
173 /* perform all tests */
174 forall(chkname);
176 exit(0);
177 /* NOTREACHED */
180 static void
181 usage(void)
183 (void)fprintf(stderr,
184 "usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n");
185 exit(1);