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

Defined functions

discardit defined in line 130; used 1 times
getignored defined in line 30; used 1 times
lexsort defined in line 96; used 2 times
search_ignore defined in line 102; used 1 times

Defined variables

lint_libs defined in line 17; used 2 times
sccsid defined in line 8; never used
Last modified: 1997-10-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1381
Valid CSS Valid XHTML 1.0 Strict