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