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

1.21    ! espie       1: /*     $OpenBSD: error.c,v 1.20 2012/03/22 13:47:12 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.1       espie      45:
1.15      espie      46: int fatal_errors = 0;
                     47: bool supervise_jobs = false;
                     48:
1.20      espie      49: static void ParseVErrorInternal(const Location *, int, const char *, va_list);
1.6       espie      50: /*-
                     51:  * Error --
                     52:  *     Print an error message given its format.
                     53:  */
                     54: /* VARARGS */
                     55: void
                     56: Error(char *fmt, ...)
                     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: /* VARARGS */
                     75: void
                     76: Fatal(char *fmt, ...)
1.1       espie      77: {
1.6       espie      78:        va_list ap;
1.10      millert    79:
1.15      espie      80:        if (supervise_jobs)
                     81:                Job_Wait();
                     82:
1.6       espie      83:        va_start(ap, fmt);
                     84:        (void)vfprintf(stderr, fmt, ap);
                     85:        va_end(ap);
                     86:        (void)fprintf(stderr, "\n");
1.1       espie      87:
1.6       espie      88:        if (DEBUG(GRAPH2))
                     89:                Targ_PrintGraph(2);
                     90:        exit(2);                /* Not 1 so -q can distinguish error */
1.1       espie      91: }
                     92:
                     93: /*
1.6       espie      94:  * Punt --
                     95:  *     Major exception once jobs are being created. Kills all jobs, prints
                     96:  *     a message and exits.
                     97:  *
                     98:  * Side Effects:
                     99:  *     All children are killed indiscriminately and the program Lib_Exits
1.1       espie     100:  */
1.6       espie     101: /* VARARGS */
                    102: void
                    103: Punt(char *fmt, ...)
1.1       espie     104: {
1.6       espie     105:        va_list ap;
1.10      millert   106:
1.6       espie     107:        va_start(ap, fmt);
                    108:        (void)fprintf(stderr, "make: ");
                    109:        (void)vfprintf(stderr, fmt, ap);
                    110:        va_end(ap);
                    111:        (void)fprintf(stderr, "\n");
1.1       espie     112:
1.6       espie     113:        Job_AbortAll();
                    114:        if (DEBUG(GRAPH2))
                    115:                Targ_PrintGraph(2);
                    116:        exit(2);                /* Not 1, so -q can distinguish error */
1.3       espie     117: }
                    118:
1.6       espie     119: /*
                    120:  * Finish --
                    121:  *     Called when aborting due to errors in child shell to signal
                    122:  *     abnormal exit.
                    123:  *
                    124:  * Side Effects:
                    125:  *     The program exits
                    126:  */
                    127: void
1.12      espie     128: Finish(int errors) /* number of errors encountered in Make_Make */
1.3       espie     129: {
1.14      espie     130:        Job_Wait();
                    131:        if (errors != 0) {
1.16      espie     132:                Error("Stop in %s:", Var_Value(".CURDIR"));
1.14      espie     133:        }
                    134:        print_errors();
                    135:        if (DEBUG(GRAPH2))
                    136:                Targ_PrintGraph(2);
                    137:        exit(2);                /* Not 1 so -q can distinguish error */
1.3       espie     138: }
1.5       espie     139:
                    140:
1.6       espie     141: /*-
                    142:  * ParseVErrorInternal --
                    143:  *     Error message abort function for parsing. Prints out the context
                    144:  *     of the error (line number and file) as well as the message with
                    145:  *     two optional arguments.
                    146:  *
                    147:  * Side Effects:
                    148:  *     "fatals" is incremented if the level is PARSE_FATAL.
1.1       espie     149:  */
1.6       espie     150: /* VARARGS */
                    151: static void
1.20      espie     152: ParseVErrorInternal(const Location *origin, int type, const char *fmt,
                    153:     va_list ap)
1.1       espie     154: {
1.20      espie     155:        if (origin->fname)
                    156:            (void)fprintf(stderr, "\"%s\", line %lu: ", origin->fname, origin->lineno);
1.6       espie     157:        if (type == PARSE_WARNING)
                    158:                (void)fprintf(stderr, "warning: ");
                    159:        (void)vfprintf(stderr, fmt, ap);
                    160:        va_end(ap);
                    161:        (void)fprintf(stderr, "\n");
                    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:  */
1.6       espie     171: /* VARARGS */
1.4       espie     172: void
1.6       espie     173: Parse_Error(int type, const char *fmt, ...)
1.4       espie     174: {
1.6       espie     175:        va_list ap;
1.20      espie     176:        Location l;
1.10      millert   177:
1.6       espie     178:        va_start(ap, fmt);
1.20      espie     179:        Parse_FillLocation(&l);
                    180:        ParseVErrorInternal(&l, type, fmt, ap);
1.11      espie     181:        va_end(ap);
1.1       espie     182: }
1.5       espie     183: