1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)filter.c 5.3 (Berkeley) 06/29/88"; 20 #endif /* not lint */ 21 22 #include <stdio.h> 23 #include <ctype.h> 24 #include <pwd.h> 25 #include "error.h" 26 27 char *lint_libs[] = { 28 IG_FILE1, 29 IG_FILE2, 30 IG_FILE3, 31 IG_FILE4, 32 0 33 }; 34 extern char* processname; 35 int lexsort(); 36 /* 37 * Read the file ERRORNAME of the names of functions in lint 38 * to ignore complaints about. 39 */ 40 getignored(auxname) 41 char *auxname; 42 { 43 reg int i; 44 FILE *fyle; 45 char inbuffer[256]; 46 int uid; 47 char filename[128]; 48 char *username; 49 struct passwd *passwdentry; 50 51 nignored = 0; 52 if (auxname == 0){ /* use the default */ 53 if ( (username = (char *)getlogin()) == NULL){ 54 username = "Unknown"; 55 uid = getuid(); 56 if ( (passwdentry = (struct passwd *)getpwuid(uid)) == NULL){ 57 return; 58 } 59 } else { 60 if ( (passwdentry = (struct passwd *)getpwnam(username)) == NULL) 61 return; 62 } 63 strcpy(filename, passwdentry->pw_dir); 64 (void)strcat(filename, ERRORNAME); 65 } else 66 (void)strcpy(filename, auxname); 67 #ifdef FULLDEBUG 68 printf("Opening file \"%s\" to read names to ignore.\n", 69 filename); 70 #endif 71 if ( (fyle = fopen(filename, "r")) == NULL){ 72 #ifdef FULLDEBUG 73 fprintf(stderr, "%s: Can't open file \"%s\"\n", 74 processname, filename); 75 #endif 76 return; 77 } 78 /* 79 * Make the first pass through the file, counting lines 80 */ 81 for (nignored = 0; fgets(inbuffer, 255, fyle) != NULL; nignored++) 82 continue; 83 names_ignored = (char **)Calloc(nignored+1, sizeof (char *)); 84 fclose(fyle); 85 if (freopen(filename, "r", fyle) == NULL){ 86 #ifdef FULLDEBUG 87 fprintf(stderr, "%s: Failure to open \"%s\" for second read.\n", 88 processname, filename); 89 #endif 90 nignored = 0; 91 return; 92 } 93 for (i=0; i < nignored && (fgets (inbuffer, 255, fyle) != NULL); i++){ 94 names_ignored[i] = strsave(inbuffer); 95 (void)substitute(names_ignored[i], '\n', '\0'); 96 } 97 qsort(names_ignored, nignored, sizeof *names_ignored, lexsort); 98 #ifdef FULLDEBUG 99 printf("Names to ignore follow.\n"); 100 for (i=0; i < nignored; i++){ 101 printf("\tIgnore: %s\n", names_ignored[i]); 102 } 103 #endif 104 } 105 106 int lexsort(cpp1, cpp2) 107 char **cpp1, **cpp2; 108 { 109 return(strcmp(*cpp1, *cpp2)); 110 } 111 112 int search_ignore(key) 113 char *key; 114 { 115 reg int ub, lb; 116 reg int halfway; 117 int order; 118 119 if (nignored == 0) 120 return(-1); 121 for(lb = 0, ub = nignored - 1; ub >= lb; ){ 122 halfway = (ub + lb)/2; 123 if ( (order = strcmp(key, names_ignored[halfway])) == 0) 124 return(halfway); 125 if (order < 0) /*key is less than probe, throw away above*/ 126 ub = halfway - 1; 127 else 128 lb = halfway + 1; 129 } 130 return(-1); 131 } 132 133 /* 134 * Tell if the error text is to be ignored. 135 * The error must have been canonicalized, with 136 * the file name the zeroth entry in the errorv, 137 * and the linenumber the second. 138 * Return the new categorization of the error class. 139 */ 140 Errorclass discardit(errorp) 141 reg Eptr errorp; 142 { 143 int language; 144 reg int i; 145 Errorclass errorclass = errorp->error_e_class; 146 147 switch(errorclass){ 148 case C_SYNC: 149 case C_NONSPEC: 150 case C_UNKNOWN: return(errorclass); 151 default: ; 152 } 153 if(errorp->error_lgtext < 2){ 154 return(C_NONSPEC); 155 } 156 language = errorp->error_language; 157 if(language == INLINT){ 158 if (errorclass != C_NONSPEC){ /* no file */ 159 for(i=0; lint_libs[i] != 0; i++){ 160 if (strcmp(errorp->error_text[0], lint_libs[i]) == 0){ 161 return(C_DISCARD); 162 } 163 } 164 } 165 /* check if the argument to the error message is to be ignored*/ 166 if (ispunct(lastchar(errorp->error_text[2]))) 167 clob_last(errorp->error_text[2], '\0'); 168 if (search_ignore(errorp->error_text[errorclass == C_NONSPEC ? 0 : 2]) >= 0){ 169 return(C_NULLED); 170 } 171 } 172 return(errorclass); 173 } 174