1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)filter.c 5.6 (Berkeley) 06/01/90"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 #include <stdio.h> 14 #include <ctype.h> 15 #include <pwd.h> 16 #include "error.h" 17 #include "pathnames.h" 18 19 char *lint_libs[] = { 20 IG_FILE1, 21 IG_FILE2, 22 IG_FILE3, 23 IG_FILE4, 24 0 25 }; 26 extern char* processname; 27 int lexsort(); 28 /* 29 * Read the file ERRORNAME of the names of functions in lint 30 * to ignore complaints about. 31 */ 32 getignored(auxname) 33 char *auxname; 34 { 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; 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); 56 (void)strcat(filename, ERRORNAME); 57 } else 58 (void)strcpy(filename, auxname); 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); 87 (void)substitute(names_ignored[i], '\n', '\0'); 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 98 int lexsort(cpp1, cpp2) 99 char **cpp1, **cpp2; 100 { 101 return(strcmp(*cpp1, *cpp2)); 102 } 103 104 int search_ignore(key) 105 char *key; 106 { 107 reg int ub, lb; 108 reg int halfway; 109 int order; 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 */ 132 Errorclass discardit(errorp) 133 reg Eptr errorp; 134 { 135 int language; 136 reg int i; 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 } 166