trivial pathname changes
[unix-history] / usr / src / usr.bin / error / filter.c
CommitLineData
442fe3bf
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
c9bf2796
KB
3 * All rights reserved.
4 *
6ecf3d85 5 * %sccs.include.redist.c%
442fe3bf
DF
6 */
7
8#ifndef lint
6ecf3d85 9static char sccsid[] = "@(#)filter.c 5.6 (Berkeley) %G%";
c9bf2796 10#endif /* not lint */
442fe3bf 11
eb6d76cb 12#include <sys/types.h>
3a5a3cc6
BJ
13#include <stdio.h>
14#include <ctype.h>
15#include <pwd.h>
16#include "error.h"
dc0e9d50 17#include "pathnames.h"
3a5a3cc6
BJ
18
19char *lint_libs[] = {
20 IG_FILE1,
21 IG_FILE2,
22 IG_FILE3,
23 IG_FILE4,
24 0
25};
26extern char* processname;
27int lexsort();
28/*
29 * Read the file ERRORNAME of the names of functions in lint
30 * to ignore complaints about.
31 */
32getignored(auxname)
33 char *auxname;
34{
58195f21
RH
35 reg int i;
36 FILE *fyle;
37 char inbuffer[256];
38 int uid;
39 char filename[128];
40 char *username;
41 struct passwd *passwdentry;
3a5a3cc6
BJ
42
43 nignored = 0;
44 if (auxname == 0){ /* use the default */
45 if ( (username = (char *)getlogin()) == NULL){
46 username = "Unknown";
47 uid = getuid();
48 if ( (passwdentry = (struct passwd *)getpwuid(uid)) == NULL){
49 return;
50 }
51 } else {
52 if ( (passwdentry = (struct passwd *)getpwnam(username)) == NULL)
53 return;
54 }
55 strcpy(filename, passwdentry->pw_dir);
58195f21 56 (void)strcat(filename, ERRORNAME);
3a5a3cc6 57 } else
58195f21 58 (void)strcpy(filename, auxname);
3a5a3cc6
BJ
59#ifdef FULLDEBUG
60 printf("Opening file \"%s\" to read names to ignore.\n",
61 filename);
62#endif
63 if ( (fyle = fopen(filename, "r")) == NULL){
64#ifdef FULLDEBUG
65 fprintf(stderr, "%s: Can't open file \"%s\"\n",
66 processname, filename);
67#endif
68 return;
69 }
70 /*
71 * Make the first pass through the file, counting lines
72 */
73 for (nignored = 0; fgets(inbuffer, 255, fyle) != NULL; nignored++)
74 continue;
75 names_ignored = (char **)Calloc(nignored+1, sizeof (char *));
76 fclose(fyle);
77 if (freopen(filename, "r", fyle) == NULL){
78#ifdef FULLDEBUG
79 fprintf(stderr, "%s: Failure to open \"%s\" for second read.\n",
80 processname, filename);
81#endif
82 nignored = 0;
83 return;
84 }
85 for (i=0; i < nignored && (fgets (inbuffer, 255, fyle) != NULL); i++){
86 names_ignored[i] = strsave(inbuffer);
58195f21 87 (void)substitute(names_ignored[i], '\n', '\0');
3a5a3cc6
BJ
88 }
89 qsort(names_ignored, nignored, sizeof *names_ignored, lexsort);
90#ifdef FULLDEBUG
91 printf("Names to ignore follow.\n");
92 for (i=0; i < nignored; i++){
93 printf("\tIgnore: %s\n", names_ignored[i]);
94 }
95#endif
96}
97
98int lexsort(cpp1, cpp2)
99 char **cpp1, **cpp2;
100{
101 return(strcmp(*cpp1, *cpp2));
102}
103
104int search_ignore(key)
105 char *key;
106{
58195f21
RH
107 reg int ub, lb;
108 reg int halfway;
109 int order;
3a5a3cc6
BJ
110
111 if (nignored == 0)
112 return(-1);
113 for(lb = 0, ub = nignored - 1; ub >= lb; ){
114 halfway = (ub + lb)/2;
115 if ( (order = strcmp(key, names_ignored[halfway])) == 0)
116 return(halfway);
117 if (order < 0) /*key is less than probe, throw away above*/
118 ub = halfway - 1;
119 else
120 lb = halfway + 1;
121 }
122 return(-1);
123}
124
125/*
126 * Tell if the error text is to be ignored.
127 * The error must have been canonicalized, with
128 * the file name the zeroth entry in the errorv,
129 * and the linenumber the second.
130 * Return the new categorization of the error class.
131 */
132Errorclass discardit(errorp)
58195f21 133 reg Eptr errorp;
3a5a3cc6 134{
58195f21
RH
135 int language;
136 reg int i;
3a5a3cc6
BJ
137 Errorclass errorclass = errorp->error_e_class;
138
139 switch(errorclass){
140 case C_SYNC:
141 case C_NONSPEC:
142 case C_UNKNOWN: return(errorclass);
143 default: ;
144 }
145 if(errorp->error_lgtext < 2){
146 return(C_NONSPEC);
147 }
148 language = errorp->error_language;
149 if(language == INLINT){
150 if (errorclass != C_NONSPEC){ /* no file */
151 for(i=0; lint_libs[i] != 0; i++){
152 if (strcmp(errorp->error_text[0], lint_libs[i]) == 0){
153 return(C_DISCARD);
154 }
155 }
156 }
157 /* check if the argument to the error message is to be ignored*/
158 if (ispunct(lastchar(errorp->error_text[2])))
159 clob_last(errorp->error_text[2], '\0');
160 if (search_ignore(errorp->error_text[errorclass == C_NONSPEC ? 0 : 2]) >= 0){
161 return(C_NULLED);
162 }
163 }
164 return(errorclass);
165}