[BACK]Return to filter.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / error

Annotation of src/usr.bin/error/filter.c, Revision 1.7

1.7     ! millert     1: /*     $OpenBSD: filter.c,v 1.6 2001/07/12 05:17:02 deraadt Exp $      */
1.1       deraadt     2: /*     $NetBSD: filter.c,v 1.3 1995/09/02 06:15:28 jtc Exp $   */
                      3:
                      4: /*
                      5:  * Copyright (c) 1980, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.7     ! millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #ifndef lint
                     34: #if 0
                     35: static char sccsid[] = "@(#)filter.c   8.1 (Berkeley) 6/6/93";
                     36: #endif
1.7     ! millert    37: static char rcsid[] = "$OpenBSD: filter.c,v 1.6 2001/07/12 05:17:02 deraadt Exp $";
1.1       deraadt    38: #endif /* not lint */
                     39:
1.5       deraadt    40: #include <sys/param.h>
1.1       deraadt    41: #include <pwd.h>
                     42: #include <unistd.h>
                     43: #include <stdio.h>
                     44: #include <ctype.h>
                     45: #include <stdlib.h>
                     46: #include <string.h>
                     47: #include "error.h"
                     48: #include "pathnames.h"
                     49:
                     50: char   *lint_libs[] = {
                     51:        IG_FILE1,
                     52:        IG_FILE2,
                     53:        IG_FILE3,
                     54:        IG_FILE4,
                     55:        0
                     56: };
                     57: int    lexsort();
                     58: /*
                     59:  *     Read the file ERRORNAME of the names of functions in lint
                     60:  *     to ignore complaints about.
                     61:  */
1.6       deraadt    62: void
1.1       deraadt    63: getignored(auxname)
                     64:        char    *auxname;
                     65: {
                     66:        reg     int     i;
1.4       deraadt    67:        FILE    *fyle;
                     68:        char    inbuffer[256];
                     69:        uid_t   uid;
1.5       deraadt    70:        char    filename[MAXPATHLEN];
1.4       deraadt    71:        char    *username;
                     72:        struct  passwd *passwdentry;
1.1       deraadt    73:
                     74:        nignored = 0;
                     75:        if (auxname == 0){      /* use the default */
                     76:                if ( (username = (char *)getlogin()) == NULL){
                     77:                        username = "Unknown";
                     78:                        uid = getuid();
                     79:                        if ( (passwdentry = (struct passwd *)getpwuid(uid)) == NULL){
                     80:                                return;
                     81:                        }
                     82:                } else {
                     83:                        if ( (passwdentry = (struct passwd *)getpwnam(username)) == NULL)
                     84:                                return;
                     85:                }
1.5       deraadt    86:                strlcpy(filename, passwdentry->pw_dir, sizeof(filename));
                     87:                (void)strlcat(filename, ERRORNAME, sizeof(filename));
1.1       deraadt    88:        } else
1.5       deraadt    89:                (void)strlcpy(filename, auxname, sizeof filename);
1.1       deraadt    90: #ifdef FULLDEBUG
                     91:        printf("Opening file \"%s\" to read names to ignore.\n",
                     92:                filename);
                     93: #endif
                     94:        if ( (fyle = fopen(filename, "r")) == NULL){
                     95: #ifdef FULLDEBUG
1.3       mickey     96:                warn("Can't open file \"%s\"", filename);
1.1       deraadt    97: #endif
                     98:                return;
                     99:        }
                    100:        /*
                    101:         *      Make the first pass through the file, counting lines
                    102:         */
1.5       deraadt   103:        for (nignored = 0;
                    104:            fgets(inbuffer, sizeof(inbuffer)-1, fyle) != NULL; nignored++)
1.1       deraadt   105:                continue;
                    106:        names_ignored = (char **)Calloc(nignored+1, sizeof (char *));
                    107:        fclose(fyle);
                    108:        if (freopen(filename, "r", fyle) == NULL){
                    109: #ifdef FULLDEBUG
1.3       mickey    110:                warn("Failure to open \"%s\" for second read.", filename);
1.1       deraadt   111: #endif
                    112:                nignored = 0;
                    113:                return;
                    114:        }
1.5       deraadt   115:        for (i=0; i < nignored &&
                    116:            (fgets (inbuffer, sizeof(inbuffer)-1, fyle) != NULL); i++){
1.1       deraadt   117:                names_ignored[i] = strsave(inbuffer);
                    118:                (void)substitute(names_ignored[i], '\n', '\0');
                    119:        }
                    120:        qsort(names_ignored, nignored, sizeof *names_ignored, lexsort);
                    121: #ifdef FULLDEBUG
                    122:        printf("Names to ignore follow.\n");
                    123:        for (i=0; i < nignored; i++){
                    124:                printf("\tIgnore: %s\n", names_ignored[i]);
                    125:        }
                    126: #endif
                    127: }
                    128:
                    129: int lexsort(cpp1, cpp2)
                    130:        char    **cpp1, **cpp2;
                    131: {
                    132:        return(strcmp(*cpp1, *cpp2));
                    133: }
                    134:
                    135: int search_ignore(key)
                    136:        char    *key;
                    137: {
                    138:        reg     int     ub, lb;
                    139:        reg     int     halfway;
                    140:                int     order;
                    141:
                    142:        if (nignored == 0)
                    143:                return(-1);
                    144:        for(lb = 0, ub = nignored - 1; ub >= lb; ){
                    145:                halfway = (ub + lb)/2;
                    146:                if ( (order = strcmp(key, names_ignored[halfway])) == 0)
                    147:                        return(halfway);
                    148:                if (order < 0)  /*key is less than probe, throw away above*/
                    149:                        ub = halfway - 1;
                    150:                 else
                    151:                        lb = halfway + 1;
                    152:        }
                    153:        return(-1);
                    154: }
                    155:
                    156: /*
                    157:  *     Tell if the error text is to be ignored.
                    158:  *     The error must have been canonicalized, with
                    159:  *     the file name the zeroth entry in the errorv,
                    160:  *     and the linenumber the second.
                    161:  *     Return the new categorization of the error class.
                    162:  */
1.6       deraadt   163: Errorclass
                    164: discardit(errorp)
                    165:        Eptr    errorp;
1.1       deraadt   166: {
                    167:                int     language;
                    168:        reg     int     i;
                    169:        Errorclass      errorclass = errorp->error_e_class;
                    170:
                    171:        switch(errorclass){
                    172:                case    C_SYNC:
                    173:                case    C_NONSPEC:
                    174:                case    C_UNKNOWN:      return(errorclass);
                    175:                default:        ;
                    176:        }
                    177:        if(errorp->error_lgtext < 2){
                    178:                return(C_NONSPEC);
                    179:        }
                    180:        language = errorp->error_language;
                    181:        if(language == INLINT){
                    182:                if (errorclass != C_NONSPEC){   /* no file */
                    183:                        for(i=0; lint_libs[i] != 0; i++){
                    184:                                if (strcmp(errorp->error_text[0], lint_libs[i]) == 0){
                    185:                                        return(C_DISCARD);
                    186:                                }
                    187:                        }
                    188:                }
                    189:                /* check if the argument to the error message is to be ignored*/
                    190:                if (ispunct(lastchar(errorp->error_text[2])))
                    191:                        clob_last(errorp->error_text[2], '\0');
                    192:                if (search_ignore(errorp->error_text[errorclass == C_NONSPEC ? 0 : 2]) >= 0){
                    193:                        return(C_NULLED);
                    194:                }
                    195:        }
                    196:        return(errorclass);
                    197: }