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