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