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