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