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