Annotation of src/usr.bin/error/filter.c, Revision 1.2
1.2 ! deraadt 1: /* $OpenBSD: filter.c,v 1.3 1995/09/02 06:15:28 jtc Exp $ */
1.1 deraadt 2: /* $NetBSD: filter.c,v 1.3 1995/09/02 06:15:28 jtc Exp $ */
3:
4: /*
5: * Copyright (c) 1980, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)filter.c 8.1 (Berkeley) 6/6/93";
40: #endif
1.2 ! deraadt 41: static char rcsid[] = "$OpenBSD: filter.c,v 1.3 1995/09/02 06:15:28 jtc Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include <sys/types.h>
45: #include <pwd.h>
46: #include <unistd.h>
47: #include <stdio.h>
48: #include <ctype.h>
49: #include <stdlib.h>
50: #include <string.h>
51: #include "error.h"
52: #include "pathnames.h"
53:
54: char *lint_libs[] = {
55: IG_FILE1,
56: IG_FILE2,
57: IG_FILE3,
58: IG_FILE4,
59: 0
60: };
61: extern char* processname;
62: int lexsort();
63: /*
64: * Read the file ERRORNAME of the names of functions in lint
65: * to ignore complaints about.
66: */
67: getignored(auxname)
68: char *auxname;
69: {
70: reg int i;
71: FILE *fyle;
72: char inbuffer[256];
73: int uid;
74: char filename[128];
75: char *username;
76: struct passwd *passwdentry;
77:
78: nignored = 0;
79: if (auxname == 0){ /* use the default */
80: if ( (username = (char *)getlogin()) == NULL){
81: username = "Unknown";
82: uid = getuid();
83: if ( (passwdentry = (struct passwd *)getpwuid(uid)) == NULL){
84: return;
85: }
86: } else {
87: if ( (passwdentry = (struct passwd *)getpwnam(username)) == NULL)
88: return;
89: }
90: strcpy(filename, passwdentry->pw_dir);
91: (void)strcat(filename, ERRORNAME);
92: } else
93: (void)strcpy(filename, auxname);
94: #ifdef FULLDEBUG
95: printf("Opening file \"%s\" to read names to ignore.\n",
96: filename);
97: #endif
98: if ( (fyle = fopen(filename, "r")) == NULL){
99: #ifdef FULLDEBUG
100: fprintf(stderr, "%s: Can't open file \"%s\"\n",
101: processname, filename);
102: #endif
103: return;
104: }
105: /*
106: * Make the first pass through the file, counting lines
107: */
108: for (nignored = 0; fgets(inbuffer, 255, fyle) != NULL; nignored++)
109: continue;
110: names_ignored = (char **)Calloc(nignored+1, sizeof (char *));
111: fclose(fyle);
112: if (freopen(filename, "r", fyle) == NULL){
113: #ifdef FULLDEBUG
114: fprintf(stderr, "%s: Failure to open \"%s\" for second read.\n",
115: processname, filename);
116: #endif
117: nignored = 0;
118: return;
119: }
120: for (i=0; i < nignored && (fgets (inbuffer, 255, fyle) != NULL); i++){
121: names_ignored[i] = strsave(inbuffer);
122: (void)substitute(names_ignored[i], '\n', '\0');
123: }
124: qsort(names_ignored, nignored, sizeof *names_ignored, lexsort);
125: #ifdef FULLDEBUG
126: printf("Names to ignore follow.\n");
127: for (i=0; i < nignored; i++){
128: printf("\tIgnore: %s\n", names_ignored[i]);
129: }
130: #endif
131: }
132:
133: int lexsort(cpp1, cpp2)
134: char **cpp1, **cpp2;
135: {
136: return(strcmp(*cpp1, *cpp2));
137: }
138:
139: int search_ignore(key)
140: char *key;
141: {
142: reg int ub, lb;
143: reg int halfway;
144: int order;
145:
146: if (nignored == 0)
147: return(-1);
148: for(lb = 0, ub = nignored - 1; ub >= lb; ){
149: halfway = (ub + lb)/2;
150: if ( (order = strcmp(key, names_ignored[halfway])) == 0)
151: return(halfway);
152: if (order < 0) /*key is less than probe, throw away above*/
153: ub = halfway - 1;
154: else
155: lb = halfway + 1;
156: }
157: return(-1);
158: }
159:
160: /*
161: * Tell if the error text is to be ignored.
162: * The error must have been canonicalized, with
163: * the file name the zeroth entry in the errorv,
164: * and the linenumber the second.
165: * Return the new categorization of the error class.
166: */
167: Errorclass discardit(errorp)
168: reg Eptr errorp;
169: {
170: int language;
171: reg int i;
172: Errorclass errorclass = errorp->error_e_class;
173:
174: switch(errorclass){
175: case C_SYNC:
176: case C_NONSPEC:
177: case C_UNKNOWN: return(errorclass);
178: default: ;
179: }
180: if(errorp->error_lgtext < 2){
181: return(C_NONSPEC);
182: }
183: language = errorp->error_language;
184: if(language == INLINT){
185: if (errorclass != C_NONSPEC){ /* no file */
186: for(i=0; lint_libs[i] != 0; i++){
187: if (strcmp(errorp->error_text[0], lint_libs[i]) == 0){
188: return(C_DISCARD);
189: }
190: }
191: }
192: /* check if the argument to the error message is to be ignored*/
193: if (ispunct(lastchar(errorp->error_text[2])))
194: clob_last(errorp->error_text[2], '\0');
195: if (search_ignore(errorp->error_text[errorclass == C_NONSPEC ? 0 : 2]) >= 0){
196: return(C_NULLED);
197: }
198: }
199: return(errorclass);
200: }