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

1.6       espie       1: /*     $OpenPackages$ */
1.14      espie       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:
1.1       espie      29: #include <stdio.h>
1.7       espie      30: #include <stdlib.h>
1.10      millert    31: #include <stdarg.h>
1.14      espie      32: #include <sys/types.h>
                     33: #include <unistd.h>
1.6       espie      34:
                     35: #include "config.h"
                     36: #include "defines.h"
1.1       espie      37: #include "error.h"
1.6       espie      38: #include "job.h"
                     39: #include "targ.h"
1.14      espie      40: #include "var.h"
1.6       espie      41:
                     42: #include "lowparse.h"
1.1       espie      43:
1.15      espie      44: int fatal_errors = 0;
                     45: bool supervise_jobs = false;
                     46:
1.6       espie      47: static void ParseVErrorInternal(const char *, unsigned long, int, const char *, va_list);
                     48: /*-
                     49:  * Error --
                     50:  *     Print an error message given its format.
                     51:  */
                     52: /* VARARGS */
                     53: void
                     54: Error(char *fmt, ...)
                     55: {
                     56:        va_list ap;
1.10      millert    57:
1.6       espie      58:        va_start(ap, fmt);
                     59:        (void)vfprintf(stderr, fmt, ap);
                     60:        va_end(ap);
                     61:        (void)fprintf(stderr, "\n");
1.1       espie      62: }
                     63:
1.6       espie      64: /*-
                     65:  * Fatal --
                     66:  *     Produce a Fatal error message. If jobs are running, waits for them
                     67:  *     to finish.
                     68:  *
                     69:  * Side Effects:
                     70:  *     The program exits
1.1       espie      71:  */
1.6       espie      72: /* VARARGS */
                     73: void
                     74: Fatal(char *fmt, ...)
1.1       espie      75: {
1.6       espie      76:        va_list ap;
1.10      millert    77:
1.15      espie      78:        if (supervise_jobs)
                     79:                Job_Wait();
                     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))
                     87:                Targ_PrintGraph(2);
                     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: /* VARARGS */
                    100: void
                    101: Punt(char *fmt, ...)
1.1       espie     102: {
1.6       espie     103:        va_list ap;
1.10      millert   104:
1.6       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");
1.1       espie     110:
1.6       espie     111:        Job_AbortAll();
                    112:        if (DEBUG(GRAPH2))
                    113:                Targ_PrintGraph(2);
                    114:        exit(2);                /* Not 1, so -q can distinguish error */
1.3       espie     115: }
                    116:
1.6       espie     117: /*
                    118:  * Finish --
                    119:  *     Called when aborting due to errors in child shell to signal
                    120:  *     abnormal exit.
                    121:  *
                    122:  * Side Effects:
                    123:  *     The program exits
                    124:  */
                    125: void
1.12      espie     126: Finish(int errors) /* number of errors encountered in Make_Make */
1.3       espie     127: {
1.14      espie     128:        Job_Wait();
                    129:        if (errors != 0) {
1.16      espie     130:                Error("Stop in %s:", Var_Value(".CURDIR"));
1.14      espie     131:        }
                    132:        print_errors();
                    133:        if (DEBUG(GRAPH2))
                    134:                Targ_PrintGraph(2);
                    135:        exit(2);                /* Not 1 so -q can distinguish error */
1.3       espie     136: }
1.5       espie     137:
                    138:
1.6       espie     139: /*-
                    140:  * ParseVErrorInternal --
                    141:  *     Error message abort function for parsing. Prints out the context
                    142:  *     of the error (line number and file) as well as the message with
                    143:  *     two optional arguments.
                    144:  *
                    145:  * Side Effects:
                    146:  *     "fatals" is incremented if the level is PARSE_FATAL.
1.1       espie     147:  */
1.6       espie     148: /* VARARGS */
                    149: static void
1.13      espie     150: ParseVErrorInternal(const char *cfname, unsigned long clineno, int type,
1.6       espie     151:        const char *fmt, va_list ap)
1.1       espie     152: {
1.8       espie     153:        if (cfname)
                    154:            (void)fprintf(stderr, "\"%s\", line %lu: ", cfname, clineno);
1.6       espie     155:        if (type == PARSE_WARNING)
                    156:                (void)fprintf(stderr, "warning: ");
                    157:        (void)vfprintf(stderr, fmt, ap);
                    158:        va_end(ap);
                    159:        (void)fprintf(stderr, "\n");
                    160:        if (type == PARSE_FATAL)
                    161:                fatal_errors ++;
                    162: }
                    163:
                    164: /*-
                    165:  * Parse_Error --
                    166:  *     External interface to ParseVErrorInternal; uses the default filename
                    167:  *     Line number.
1.4       espie     168:  */
1.6       espie     169: /* VARARGS */
1.4       espie     170: void
1.6       espie     171: Parse_Error(int type, const char *fmt, ...)
1.4       espie     172: {
1.6       espie     173:        va_list ap;
1.10      millert   174:
1.6       espie     175:        va_start(ap, fmt);
1.13      espie     176:        ParseVErrorInternal(Parse_Getfilename(), Parse_Getlineno(), type,
1.12      espie     177:            fmt, ap);
1.11      espie     178:        va_end(ap);
1.1       espie     179: }
1.5       espie     180: