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

Annotation of src/usr.bin/make/error.c, Revision 1.6

1.6     ! espie       1: /*     $OpenPackages$ */
        !             2: /*     $OpenBSD$ */
1.1       espie       3:
                      4: /*
1.6     ! espie       5:  * Copyright (c) 2001 Marc Espie.
1.1       espie       6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
1.6     ! espie      15:  *
        !            16:  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
        !            17:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
        !            18:  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
        !            19:  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
        !            20:  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
        !            21:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
        !            22:  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            23:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            24:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            25:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        !            26:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            27:  */
        !            28: #ifdef __STDC__
        !            29: #include <stdarg.h>
        !            30: #else
        !            31: #include <varargs.h>
        !            32: #endif
        !            33:
1.1       espie      34: #include <stdio.h>
1.6     ! espie      35:
        !            36: #include "config.h"
        !            37: #include "defines.h"
1.1       espie      38: #include "error.h"
1.6     ! espie      39: #include "job.h"
        !            40: #include "targ.h"
        !            41:
        !            42: #include "lowparse.h"
1.1       espie      43:
1.6     ! espie      44: int        fatal_errors = 0;
        !            45: static void ParseVErrorInternal(const char *, unsigned long, int, const char *, va_list);
        !            46: /*-
        !            47:  * Error --
        !            48:  *     Print an error message given its format.
        !            49:  */
        !            50: /* VARARGS */
        !            51: void
        !            52: #ifdef __STDC__
        !            53: Error(char *fmt, ...)
1.5       espie      54: #else
1.6     ! espie      55: Error(va_alist)
        !            56:        va_dcl
1.5       espie      57: #endif
1.6     ! espie      58: {
        !            59:        va_list ap;
        !            60: #ifdef __STDC__
        !            61:        va_start(ap, fmt);
        !            62: #else
        !            63:        char *fmt;
1.5       espie      64:
1.6     ! espie      65:        va_start(ap);
        !            66:        fmt = va_arg(ap, char *);
        !            67: #endif
        !            68:        (void)vfprintf(stderr, fmt, ap);
        !            69:        va_end(ap);
        !            70:        (void)fprintf(stderr, "\n");
1.1       espie      71: }
                     72:
1.6     ! espie      73: /*-
        !            74:  * Fatal --
        !            75:  *     Produce a Fatal error message. If jobs are running, waits for them
        !            76:  *     to finish.
        !            77:  *
        !            78:  * Side Effects:
        !            79:  *     The program exits
1.1       espie      80:  */
1.6     ! espie      81: /* VARARGS */
        !            82: void
        !            83: #ifdef __STDC__
        !            84: Fatal(char *fmt, ...)
        !            85: #else
        !            86: Fatal(va_alist)
        !            87:        va_dcl
        !            88: #endif
1.1       espie      89: {
1.6     ! espie      90:        va_list ap;
        !            91: #ifdef __STDC__
        !            92:        va_start(ap, fmt);
        !            93: #else
        !            94:        char *fmt;
1.1       espie      95:
1.6     ! espie      96:        va_start(ap);
        !            97:        fmt = va_arg(ap, char *);
        !            98: #endif
        !            99:        Job_Wait();
        !           100:
        !           101:        (void)vfprintf(stderr, fmt, ap);
        !           102:        va_end(ap);
        !           103:        (void)fprintf(stderr, "\n");
1.1       espie     104:
1.6     ! espie     105:        if (DEBUG(GRAPH2))
        !           106:                Targ_PrintGraph(2);
        !           107:        exit(2);                /* Not 1 so -q can distinguish error */
1.1       espie     108: }
                    109:
                    110: /*
1.6     ! espie     111:  * Punt --
        !           112:  *     Major exception once jobs are being created. Kills all jobs, prints
        !           113:  *     a message and exits.
        !           114:  *
        !           115:  * Side Effects:
        !           116:  *     All children are killed indiscriminately and the program Lib_Exits
1.1       espie     117:  */
1.6     ! espie     118: /* VARARGS */
        !           119: void
        !           120: #ifdef __STDC__
        !           121: Punt(char *fmt, ...)
        !           122: #else
        !           123: Punt(va_alist)
        !           124:        va_dcl
        !           125: #endif
1.1       espie     126: {
1.6     ! espie     127:        va_list ap;
        !           128: #ifdef __STDC__
        !           129:        va_start(ap, fmt);
        !           130: #else
        !           131:        char *fmt;
1.1       espie     132:
1.6     ! espie     133:        va_start(ap);
        !           134:        fmt = va_arg(ap, char *);
        !           135: #endif
1.1       espie     136:
1.6     ! espie     137:        (void)fprintf(stderr, "make: ");
        !           138:        (void)vfprintf(stderr, fmt, ap);
        !           139:        va_end(ap);
        !           140:        (void)fprintf(stderr, "\n");
1.1       espie     141:
1.6     ! espie     142:        DieHorribly();
1.3       espie     143: }
                    144:
1.6     ! espie     145: /*-
        !           146:  * DieHorribly --
        !           147:  *     Exit without giving a message.
        !           148:  *
        !           149:  * Side Effects:
        !           150:  *     A big one...
        !           151:  */
1.3       espie     152: void
1.6     ! espie     153: DieHorribly()
1.3       espie     154: {
1.6     ! espie     155:        Job_AbortAll();
        !           156:        if (DEBUG(GRAPH2))
        !           157:                Targ_PrintGraph(2);
        !           158:        exit(2);                /* Not 1, so -q can distinguish error */
1.3       espie     159: }
                    160:
1.6     ! espie     161: /*
        !           162:  * Finish --
        !           163:  *     Called when aborting due to errors in child shell to signal
        !           164:  *     abnormal exit.
        !           165:  *
        !           166:  * Side Effects:
        !           167:  *     The program exits
        !           168:  */
        !           169: void
        !           170: Finish(errors)
        !           171:        int errors;     /* number of errors encountered in Make_Make */
1.3       espie     172: {
1.6     ! espie     173:        Fatal("%d error%s", errors, errors == 1 ? "" : "s");
1.3       espie     174: }
1.5       espie     175:
                    176:
1.6     ! espie     177: /*-
        !           178:  * ParseVErrorInternal --
        !           179:  *     Error message abort function for parsing. Prints out the context
        !           180:  *     of the error (line number and file) as well as the message with
        !           181:  *     two optional arguments.
        !           182:  *
        !           183:  * Side Effects:
        !           184:  *     "fatals" is incremented if the level is PARSE_FATAL.
1.1       espie     185:  */
1.6     ! espie     186: /* VARARGS */
        !           187: static void
        !           188: #ifdef __STDC__
        !           189: ParseVErrorInternal(const char *cfname, unsigned long clineno, int type,
        !           190:        const char *fmt, va_list ap)
        !           191: #else
        !           192: ParseVErrorInternal(va_alist)
        !           193:        va_dcl
        !           194: #endif
1.1       espie     195: {
1.6     ! espie     196:        (void)fprintf(stderr, "\"%s\", line %lu: ", cfname, clineno);
        !           197:        if (type == PARSE_WARNING)
        !           198:                (void)fprintf(stderr, "warning: ");
        !           199:        (void)vfprintf(stderr, fmt, ap);
        !           200:        va_end(ap);
        !           201:        (void)fprintf(stderr, "\n");
        !           202:        if (type == PARSE_FATAL)
        !           203:                fatal_errors ++;
        !           204: }
        !           205:
        !           206: /*-
        !           207:  * Parse_Error --
        !           208:  *     External interface to ParseVErrorInternal; uses the default filename
        !           209:  *     Line number.
1.4       espie     210:  */
1.6     ! espie     211: /* VARARGS */
1.4       espie     212: void
1.6     ! espie     213: #ifdef __STDC__
        !           214: Parse_Error(int type, const char *fmt, ...)
        !           215: #else
        !           216: Parse_Error(va_alist)
        !           217:        va_dcl
        !           218: #endif
1.4       espie     219: {
1.6     ! espie     220:        va_list ap;
        !           221: #ifdef __STDC__
        !           222:        va_start(ap, fmt);
        !           223: #else
        !           224:        int type;               /* Error type (PARSE_WARNING, PARSE_FATAL) */
        !           225:        char *fmt;
1.1       espie     226:
1.6     ! espie     227:        va_start(ap);
        !           228:        type = va_arg(ap, int);
        !           229:        fmt = va_arg(ap, char *);
        !           230: #endif
1.1       espie     231:
1.6     ! espie     232:        ParseVErrorInternal(Parse_Getfilename(), Parse_Getlineno(), type, fmt, ap);
1.1       espie     233: }
1.5       espie     234: