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