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

1.25    ! guenther    1: /*     $OpenBSD: error.c,v 1.24 2012/10/18 17:54:43 espie Exp $ */
1.1       espie       2:
                      3: /*
1.6       espie       4:  * Copyright (c) 2001 Marc Espie.
1.1       espie       5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
1.6       espie      14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
                     16:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
                     17:  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
                     18:  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
                     19:  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                     20:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
                     21:  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     22:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     23:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     24:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
                     25:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  */
                     27:
1.1       espie      28: #include <stdio.h>
1.7       espie      29: #include <stdlib.h>
1.10      millert    30: #include <stdarg.h>
1.14      espie      31: #include <sys/types.h>
                     32: #include <unistd.h>
1.6       espie      33:
                     34: #include "config.h"
                     35: #include "defines.h"
1.1       espie      36: #include "error.h"
1.6       espie      37: #include "job.h"
                     38: #include "targ.h"
1.14      espie      39: #include "var.h"
1.21      espie      40: #ifndef LOCATION_TYPE
1.20      espie      41: #include "location.h"
1.21      espie      42: #endif
1.6       espie      43:
                     44: #include "lowparse.h"
1.23      espie      45: #include "dump.h"
1.1       espie      46:
1.15      espie      47: int fatal_errors = 0;
                     48:
1.25    ! guenther   49: static void ParseVErrorInternal(const Location *, int, const char *, va_list)
        !            50:                        __attribute__((__format__ (printf, 3, 0)));
1.6       espie      51: /*-
                     52:  * Error --
                     53:  *     Print an error message given its format.
                     54:  */
                     55: void
1.25    ! guenther   56: Error(const char *fmt, ...)
1.6       espie      57: {
                     58:        va_list ap;
1.10      millert    59:
1.6       espie      60:        va_start(ap, fmt);
                     61:        (void)vfprintf(stderr, fmt, ap);
                     62:        va_end(ap);
                     63:        (void)fprintf(stderr, "\n");
1.1       espie      64: }
                     65:
1.6       espie      66: /*-
                     67:  * Fatal --
                     68:  *     Produce a Fatal error message. If jobs are running, waits for them
                     69:  *     to finish.
                     70:  *
                     71:  * Side Effects:
                     72:  *     The program exits
1.1       espie      73:  */
1.6       espie      74: void
1.25    ! guenther   75: Fatal(const char *fmt, ...)
1.1       espie      76: {
1.6       espie      77:        va_list ap;
1.10      millert    78:
1.22      espie      79:        Job_Wait();
1.15      espie      80:
1.6       espie      81:        va_start(ap, fmt);
                     82:        (void)vfprintf(stderr, fmt, ap);
                     83:        va_end(ap);
                     84:        (void)fprintf(stderr, "\n");
1.1       espie      85:
1.6       espie      86:        if (DEBUG(GRAPH2))
1.23      espie      87:                post_mortem();
1.6       espie      88:        exit(2);                /* Not 1 so -q can distinguish error */
1.1       espie      89: }
                     90:
                     91: /*
1.6       espie      92:  * Punt --
                     93:  *     Major exception once jobs are being created. Kills all jobs, prints
                     94:  *     a message and exits.
                     95:  *
                     96:  * Side Effects:
                     97:  *     All children are killed indiscriminately and the program Lib_Exits
1.1       espie      98:  */
1.6       espie      99: void
1.25    ! guenther  100: Punt(const char *fmt, ...)
1.1       espie     101: {
1.22      espie     102:        if (fmt) {
                    103:                va_list ap;
1.10      millert   104:
1.22      espie     105:                va_start(ap, fmt);
                    106:                (void)fprintf(stderr, "make: ");
                    107:                (void)vfprintf(stderr, fmt, ap);
                    108:                va_end(ap);
                    109:                (void)fprintf(stderr, "\n");
                    110:        }
1.1       espie     111:
1.6       espie     112:        Job_AbortAll();
                    113:        if (DEBUG(GRAPH2))
1.23      espie     114:                post_mortem();
1.6       espie     115:        exit(2);                /* Not 1, so -q can distinguish error */
1.3       espie     116: }
                    117:
1.6       espie     118: /*
                    119:  * Finish --
1.22      espie     120:  *     Called when aborting due to errors in command or fatal signal
1.6       espie     121:  *
                    122:  * Side Effects:
                    123:  *     The program exits
                    124:  */
                    125: void
1.22      espie     126: Finish()
1.3       espie     127: {
1.14      espie     128:        Job_Wait();
                    129:        print_errors();
                    130:        if (DEBUG(GRAPH2))
1.23      espie     131:                post_mortem();
1.14      espie     132:        exit(2);                /* Not 1 so -q can distinguish error */
1.3       espie     133: }
1.5       espie     134:
                    135:
1.6       espie     136: /*-
                    137:  * ParseVErrorInternal --
                    138:  *     Error message abort function for parsing. Prints out the context
                    139:  *     of the error (line number and file) as well as the message with
                    140:  *     two optional arguments.
                    141:  *
                    142:  * Side Effects:
                    143:  *     "fatals" is incremented if the level is PARSE_FATAL.
1.1       espie     144:  */
1.6       espie     145: static void
1.20      espie     146: ParseVErrorInternal(const Location *origin, int type, const char *fmt,
                    147:     va_list ap)
1.1       espie     148: {
1.24      espie     149:        static bool first = true;
                    150:        fprintf(stderr, "*** %s",
                    151:            type == PARSE_WARNING ? "Warning" : "Parse error");
                    152:        if (first) {
                    153:                fprintf(stderr, " in %s: ", Var_Value(".CURDIR"));
                    154:                first = false;
                    155:        } else
                    156:                fprintf(stderr, ": ");
                    157:        vfprintf(stderr, fmt, ap);
                    158:        va_end(ap);
1.20      espie     159:        if (origin->fname)
1.24      espie     160:                fprintf(stderr, " (%s:%lu)", origin->fname, origin->lineno);
                    161:        fprintf(stderr, "\n");
1.6       espie     162:        if (type == PARSE_FATAL)
                    163:                fatal_errors ++;
                    164: }
                    165:
                    166: /*-
                    167:  * Parse_Error --
                    168:  *     External interface to ParseVErrorInternal; uses the default filename
                    169:  *     Line number.
1.4       espie     170:  */
                    171: void
1.6       espie     172: Parse_Error(int type, const char *fmt, ...)
1.4       espie     173: {
1.6       espie     174:        va_list ap;
1.20      espie     175:        Location l;
1.10      millert   176:
1.6       espie     177:        va_start(ap, fmt);
1.20      espie     178:        Parse_FillLocation(&l);
                    179:        ParseVErrorInternal(&l, type, fmt, ap);
1.11      espie     180:        va_end(ap);
1.1       espie     181: }