Annotation of 43BSDReno/pgrm/error/errormain.c, revision 1.1

1.1     ! root        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: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: char copyright[] =
        !            22: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)errormain.c        5.5 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: #include <stdio.h>
        !            31: #include <ctype.h>
        !            32: #include <signal.h>
        !            33: #include "error.h"
        !            34: #include "pathnames.h"
        !            35: 
        !            36: int    nerrors = 0;
        !            37: Eptr   er_head;
        !            38: Eptr   *errors;
        !            39: 
        !            40: int    nfiles = 0;
        !            41: Eptr   **files;        /* array of pointers into errors*/
        !            42: int    language = INCC;
        !            43: 
        !            44: char   *currentfilename = "????";
        !            45: char   *processname;
        !            46: char   im_on[] = _PATH_TTY;    /* my tty name */
        !            47: 
        !            48: boolean        query = FALSE;          /* query the operator if touch files */
        !            49: boolean        notouch = FALSE;        /* don't touch ANY files */
        !            50: boolean        piflag  = FALSE;        /* this is not pi */
        !            51: boolean        terse   = FALSE;        /* Terse output */
        !            52: 
        !            53: char   *suffixlist = ".*";     /* initially, can touch any file */
        !            54: 
        !            55: int    errorsort();
        !            56: int    onintr();
        !            57: /*
        !            58:  *     error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile]
        !            59:  *     
        !            60:  *     -T:     terse output
        !            61:  *
        !            62:  *     -I:     the following name, `ignorename' contains a list of
        !            63:  *             function names that are not to be treated as hard errors.
        !            64:  *             Default: ~/.errorsrc
        !            65:  *
        !            66:  *     -n:     don't touch ANY files!
        !            67:  *
        !            68:  *     -q:     The user is to be queried before touching each
        !            69:  *             file; if not specified, all files with hard, non
        !            70:  *             ignorable errors are touched (assuming they can be).
        !            71:  *
        !            72:  *     -t:     touch only files ending with the list of suffices, each
        !            73:  *             suffix preceded by a dot.
        !            74:  *             eg, -t .c.y.l
        !            75:  *             will touch only files ending with .c, .y or .l
        !            76:  *
        !            77:  *     -s:     print a summary of the error's categories.
        !            78:  *
        !            79:  *     -v:     after touching all files, overlay vi(1), ex(1) or ed(1)
        !            80:  *             on top of error, entered in the first file with
        !            81:  *             an error in it, with the appropriate editor
        !            82:  *             set up to use the "next" command to get the other
        !            83:  *             files containing errors.
        !            84:  *
        !            85:  *     -p:     (obsolete: for older versions of pi without bug
        !            86:  *             fix regarding printing out the name of the main file
        !            87:  *             with an error in it)
        !            88:  *             Take the following argument and use it as the name of
        !            89:  *             the pascal source file, suffix .p
        !            90:  *
        !            91:  *     -E:     show the errors in sorted order; intended for
        !            92:  *             debugging.
        !            93:  *
        !            94:  *     -S:     show the errors in unsorted order
        !            95:  *             (as they come from the error file)
        !            96:  *
        !            97:  *     infile: The error messages come from this file.
        !            98:  *             Default: stdin
        !            99:  */
        !           100: main(argc, argv)
        !           101:        int     argc;
        !           102:        char    *argv[];
        !           103: {
        !           104:        char    *cp;
        !           105:        char    *ignorename = 0;
        !           106:        int     ed_argc;
        !           107:        char    **ed_argv;              /*return from touchfiles*/
        !           108:        boolean show_errors = FALSE;
        !           109:        boolean Show_Errors = FALSE;
        !           110:        boolean pr_summary = FALSE;
        !           111:        boolean edit_files = FALSE;
        !           112: 
        !           113:        processname = argv[0];
        !           114: 
        !           115:        errorfile = stdin;
        !           116:        if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){
        !           117:                for (cp = argv[1] + 1; *cp; cp++) switch(*cp){
        !           118:                default:
        !           119:                        fprintf(stderr, "%s: -%c: Unknown flag\n",
        !           120:                                processname, *cp);
        !           121:                        break;
        !           122: 
        !           123:                case 'n':       notouch = TRUE; break;
        !           124:                case 'q':       query = TRUE;   break;
        !           125:                case 'S':       Show_Errors = TRUE;     break;
        !           126:                case 's':       pr_summary = TRUE;      break;
        !           127:                case 'v':       edit_files = TRUE;      break;
        !           128:                case 'T':       terse = TRUE;   break;
        !           129:                case 't':
        !           130:                        *cp-- = 0; argv++; argc--;
        !           131:                        if (argc > 1){
        !           132:                                suffixlist = argv[1];
        !           133:                        }
        !           134:                        break;
        !           135:                case 'I':       /*ignore file name*/
        !           136:                        *cp-- = 0; argv++; argc--;
        !           137:                        if (argc > 1)
        !           138:                                ignorename = argv[1];
        !           139:                        break;
        !           140:                }
        !           141:        }       
        !           142:        if (notouch)
        !           143:                suffixlist = 0;
        !           144:        if (argc > 1){
        !           145:                if (argc > 3){
        !           146:                        fprintf(stderr, "%s: Only takes 0 or 1 arguments\n",
        !           147:                                processname);
        !           148:                        exit(3);
        !           149:                }
        !           150:                if ( (errorfile = fopen(argv[1], "r")) == NULL){
        !           151:                        fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n",
        !           152:                                processname, argv[1]);
        !           153:                        exit(4);
        !           154:                }
        !           155:        }
        !           156:        if ( (queryfile = fopen(im_on, "r")) == NULL){
        !           157:                if (query){
        !           158:                        fprintf(stderr,
        !           159:                                "%s: Can't open \"%s\" to query the user.\n",
        !           160:                                processname, im_on);
        !           161:                        exit(9);
        !           162:                }
        !           163:        }
        !           164:        if (signal(SIGINT, onintr) == SIG_IGN)
        !           165:                signal(SIGINT, SIG_IGN);
        !           166:        if (signal(SIGTERM, onintr) == SIG_IGN)
        !           167:                signal(SIGTERM, SIG_IGN);
        !           168:        getignored(ignorename);
        !           169:        eaterrors(&nerrors, &errors);
        !           170:        if (Show_Errors)
        !           171:                printerrors(TRUE, nerrors, errors);
        !           172:        qsort(errors, nerrors, sizeof(Eptr), errorsort);
        !           173:        if (show_errors)
        !           174:                printerrors(FALSE, nerrors, errors);
        !           175:        findfiles(nerrors, errors, &nfiles, &files);
        !           176: #define P(msg, arg) fprintf(stdout, msg, arg)
        !           177:        if (pr_summary){
        !           178:            if (nunknown)
        !           179:              P("%d Errors are unclassifiable.\n", nunknown);
        !           180:            if (nignore)
        !           181:              P("%d Errors are classifiable, but totally discarded.\n",nignore);
        !           182:            if (nsyncerrors)
        !           183:              P("%d Errors are synchronization errors.\n", nsyncerrors);
        !           184:            if (nignore)
        !           185:              P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard);
        !           186:            if (nnulled)
        !           187:              P("%d Errors are nulled because they refer to specific functions.\n", nnulled);
        !           188:            if (nnonspec)
        !           189:              P("%d Errors are not specific to any file.\n", nnonspec);
        !           190:            if (nthisfile)
        !           191:              P("%d Errors are specific to a given file, but not to a line.\n", nthisfile);
        !           192:            if (ntrue)
        !           193:              P("%d Errors are true errors, and can be inserted into the files.\n", ntrue);
        !           194:        }
        !           195:        filenames(nfiles, files);
        !           196:        fflush(stdout);
        !           197:        if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files)
        !           198:                forkvi(ed_argc, ed_argv);
        !           199: }
        !           200: 
        !           201: forkvi(argc, argv)
        !           202:        int     argc;
        !           203:        char    **argv;
        !           204: {
        !           205:        if (query){
        !           206:                switch(inquire(terse
        !           207:                    ? "Edit? "
        !           208:                    : "Do you still want to edit the files you touched? ")){
        !           209:                case Q_NO:
        !           210:                case Q_no:
        !           211:                        return;
        !           212:                default:
        !           213:                        break;
        !           214:                }
        !           215:        }
        !           216:        /*
        !           217:         *      ed_agument's first argument is
        !           218:         *      a vi/ex compatabile search argument
        !           219:         *      to find the first occurance of ###
        !           220:         */
        !           221:        try("vi", argc, argv);
        !           222:        try("ex", argc, argv);
        !           223:        try("ed", argc-1, argv+1);
        !           224:        fprintf(stdout, "Can't find any editors.\n");
        !           225: }
        !           226: 
        !           227: try(name, argc, argv)
        !           228:        char    *name;
        !           229:        int     argc;
        !           230:        char    **argv;
        !           231: {
        !           232:        argv[0] = name;
        !           233:        wordvprint(stdout, argc, argv);
        !           234:        fprintf(stdout, "\n");
        !           235:        fflush(stderr);
        !           236:        fflush(stdout);
        !           237:        sleep(2);
        !           238:        if (freopen(im_on, "r", stdin) == NULL)
        !           239:                return;
        !           240:        if (freopen(im_on, "w", stdout) == NULL)
        !           241:                return;
        !           242:        execvp(name, argv);
        !           243: }
        !           244: 
        !           245: int errorsort(epp1, epp2)
        !           246:                Eptr    *epp1, *epp2;
        !           247: {
        !           248:        reg     Eptr    ep1, ep2;
        !           249:                int     order;
        !           250:        /*
        !           251:         *      Sort by:
        !           252:         *      1)      synchronization, non specific, discarded errors first;
        !           253:         *      2)      nulled and true errors last
        !           254:         *              a)      grouped by similar file names
        !           255:         *                      1)      grouped in ascending line number
        !           256:         */
        !           257:        ep1 = *epp1; ep2 = *epp2;
        !           258:        if (ep1 == 0 || ep2 == 0)
        !           259:                return(0);
        !           260:        if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){
        !           261:                return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1);
        !           262:        }
        !           263:        if (NOTSORTABLE(ep1->error_e_class))    /* then both are */
        !           264:                return(ep1->error_no - ep2->error_no);
        !           265:        order = strcmp(ep1->error_text[0], ep2->error_text[0]);
        !           266:        if (order == 0){
        !           267:                return(ep1->error_line - ep2->error_line);
        !           268:        }
        !           269:        return(order);
        !           270: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.