[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.3

1.3     ! mickey      1: /*     $OpenBSD: filter.c,v 1.2 1996/06/26 05:32:42 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.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)filter.c   8.1 (Berkeley) 6/6/93";
                     40: #endif
1.3     ! mickey     41: static char rcsid[] = "$OpenBSD: filter.c,v 1.2 1996/06/26 05:32:42 deraadt Exp $";
1.1       deraadt    42: #endif /* not lint */
                     43:
                     44: #include <sys/types.h>
                     45: #include <pwd.h>
                     46: #include <unistd.h>
                     47: #include <stdio.h>
                     48: #include <ctype.h>
                     49: #include <stdlib.h>
                     50: #include <string.h>
                     51: #include "error.h"
                     52: #include "pathnames.h"
                     53:
                     54: char   *lint_libs[] = {
                     55:        IG_FILE1,
                     56:        IG_FILE2,
                     57:        IG_FILE3,
                     58:        IG_FILE4,
                     59:        0
                     60: };
                     61: int    lexsort();
                     62: /*
                     63:  *     Read the file ERRORNAME of the names of functions in lint
                     64:  *     to ignore complaints about.
                     65:  */
                     66: getignored(auxname)
                     67:        char    *auxname;
                     68: {
                     69:        reg     int     i;
                     70:                FILE    *fyle;
                     71:                char    inbuffer[256];
                     72:                int     uid;
                     73:                char    filename[128];
                     74:                char    *username;
                     75:                struct  passwd *passwdentry;
                     76:
                     77:        nignored = 0;
                     78:        if (auxname == 0){      /* use the default */
                     79:                if ( (username = (char *)getlogin()) == NULL){
                     80:                        username = "Unknown";
                     81:                        uid = getuid();
                     82:                        if ( (passwdentry = (struct passwd *)getpwuid(uid)) == NULL){
                     83:                                return;
                     84:                        }
                     85:                } else {
                     86:                        if ( (passwdentry = (struct passwd *)getpwnam(username)) == NULL)
                     87:                                return;
                     88:                }
                     89:                strcpy(filename, passwdentry->pw_dir);
                     90:                (void)strcat(filename, ERRORNAME);
                     91:        } else
                     92:                (void)strcpy(filename, auxname);
                     93: #ifdef FULLDEBUG
                     94:        printf("Opening file \"%s\" to read names to ignore.\n",
                     95:                filename);
                     96: #endif
                     97:        if ( (fyle = fopen(filename, "r")) == NULL){
                     98: #ifdef FULLDEBUG
1.3     ! mickey     99:                warn("Can't open file \"%s\"", filename);
1.1       deraadt   100: #endif
                    101:                return;
                    102:        }
                    103:        /*
                    104:         *      Make the first pass through the file, counting lines
                    105:         */
                    106:        for (nignored = 0; fgets(inbuffer, 255, fyle) != NULL; nignored++)
                    107:                continue;
                    108:        names_ignored = (char **)Calloc(nignored+1, sizeof (char *));
                    109:        fclose(fyle);
                    110:        if (freopen(filename, "r", fyle) == NULL){
                    111: #ifdef FULLDEBUG
1.3     ! mickey    112:                warn("Failure to open \"%s\" for second read.", filename);
1.1       deraadt   113: #endif
                    114:                nignored = 0;
                    115:                return;
                    116:        }
                    117:        for (i=0; i < nignored && (fgets (inbuffer, 255, fyle) != NULL); i++){
                    118:                names_ignored[i] = strsave(inbuffer);
                    119:                (void)substitute(names_ignored[i], '\n', '\0');
                    120:        }
                    121:        qsort(names_ignored, nignored, sizeof *names_ignored, lexsort);
                    122: #ifdef FULLDEBUG
                    123:        printf("Names to ignore follow.\n");
                    124:        for (i=0; i < nignored; i++){
                    125:                printf("\tIgnore: %s\n", names_ignored[i]);
                    126:        }
                    127: #endif
                    128: }
                    129:
                    130: int lexsort(cpp1, cpp2)
                    131:        char    **cpp1, **cpp2;
                    132: {
                    133:        return(strcmp(*cpp1, *cpp2));
                    134: }
                    135:
                    136: int search_ignore(key)
                    137:        char    *key;
                    138: {
                    139:        reg     int     ub, lb;
                    140:        reg     int     halfway;
                    141:                int     order;
                    142:
                    143:        if (nignored == 0)
                    144:                return(-1);
                    145:        for(lb = 0, ub = nignored - 1; ub >= lb; ){
                    146:                halfway = (ub + lb)/2;
                    147:                if ( (order = strcmp(key, names_ignored[halfway])) == 0)
                    148:                        return(halfway);
                    149:                if (order < 0)  /*key is less than probe, throw away above*/
                    150:                        ub = halfway - 1;
                    151:                 else
                    152:                        lb = halfway + 1;
                    153:        }
                    154:        return(-1);
                    155: }
                    156:
                    157: /*
                    158:  *     Tell if the error text is to be ignored.
                    159:  *     The error must have been canonicalized, with
                    160:  *     the file name the zeroth entry in the errorv,
                    161:  *     and the linenumber the second.
                    162:  *     Return the new categorization of the error class.
                    163:  */
                    164: Errorclass discardit(errorp)
                    165:        reg     Eptr    errorp;
                    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: }