1 /* $NetBSD: filter.c,v 1.14 2009/08/13 04:09:53 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)filter.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: filter.c,v 1.14 2009/08/13 04:09:53 dholland Exp $");
40 #include <sys/param.h>
48 #include "pathnames.h"
50 static const char *lint_libs
[] = {
58 static int lexsort(const void *, const void *);
59 static int search_ignore(const char *);
62 * Read the file ERRORNAME of the names of functions in lint
63 * to ignore complaints about.
66 getignored(const char *auxname
)
72 char filename
[MAXPATHLEN
];
74 struct passwd
*passwdentry
;
77 if (auxname
== 0) { /* use the default */
78 if ((username
= getlogin()) == NULL
) {
81 if ((passwdentry
= getpwuid(uid
)) == NULL
) {
85 if ((passwdentry
= getpwnam(username
)) == NULL
)
88 strlcpy(filename
, passwdentry
->pw_dir
, sizeof(filename
));
89 (void)strlcat(filename
, ERRORNAME
, sizeof(filename
));
91 (void)strlcpy(filename
, auxname
, sizeof(filename
));
93 printf("Opening file \"%s\" to read names to ignore.\n",
96 if ((fyle
= fopen(filename
, "r")) == NULL
) {
98 fprintf(stderr
, "%s: Can't open file \"%s\"\n",
99 processname
, filename
);
105 * Make the first pass through the file, counting lines
108 fgets(inbuffer
, sizeof(inbuffer
)-1, fyle
) != NULL
; nignored
++)
110 names_ignored
= Calloc(nignored
+1, sizeof (char *));
112 if (freopen(filename
, "r", fyle
) == NULL
) {
114 fprintf(stderr
, "%s: Failure to open \"%s\" for second read.\n",
115 processname
, filename
);
120 for (i
=0; i
< nignored
&&
121 (fgets (inbuffer
, sizeof(inbuffer
)-1, fyle
) != NULL
); i
++) {
122 names_ignored
[i
] = strdup(inbuffer
);
123 (void)substitute(names_ignored
[i
], '\n', '\0');
125 qsort(names_ignored
, nignored
, sizeof *names_ignored
, lexsort
);
127 printf("Names to ignore follow.\n");
128 for (i
=0; i
< nignored
; i
++) {
129 printf("\tIgnore: %s\n", names_ignored
[i
]);
135 lexsort(const void *c1
, const void *c2
)
137 const char *const *cpp1
;
138 const char *const *cpp2
;
142 return (strcmp(*cpp1
, *cpp2
));
146 search_ignore(const char *key
)
154 for (lb
= 0, ub
= nignored
- 1; ub
>= lb
; ) {
155 halfway
= (ub
+ lb
)/2;
156 if ( (order
= strcmp(key
, names_ignored
[halfway
])) == 0)
158 if (order
< 0) /* key is less than probe, throw away above */
167 * Tell if the error text is to be ignored.
168 * The error must have been canonicalized, with
169 * the file name the zeroth entry in the errorv,
170 * and the linenumber the second.
171 * Return the new categorization of the error class.
174 discardit(Eptr errorp
)
177 Errorclass errorclass
= errorp
->error_e_class
;
179 switch (errorclass
) {
182 case C_UNKNOWN
: return (errorclass
);
185 if (errorp
->error_lgtext
< 2) {
188 if (errorp
->error_language
== INLINT
) {
189 if (errorclass
!= C_NONSPEC
) { /* no file */
190 for (i
=0; lint_libs
[i
] != 0; i
++) {
191 if (strcmp(errorp
->error_text
[0], lint_libs
[i
]) == 0) {
196 /* check if the argument to the error message is to be ignored */
197 if (ispunct((unsigned char)lastchar(errorp
->error_text
[2])))
198 clob_last(errorp
->error_text
[2], '\0');
199 if (search_ignore(errorp
->error_text
[errorclass
== C_NONSPEC
? 0 : 2]) >= 0) {