Annotation of src/usr.bin/make/error.c, Revision 1.14
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.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: Error(char *fmt, ...)
53: {
54: va_list ap;
1.10 millert 55:
1.6 espie 56: va_start(ap, fmt);
57: (void)vfprintf(stderr, fmt, ap);
58: va_end(ap);
59: (void)fprintf(stderr, "\n");
1.1 espie 60: }
61:
1.6 espie 62: /*-
63: * Fatal --
64: * Produce a Fatal error message. If jobs are running, waits for them
65: * to finish.
66: *
67: * Side Effects:
68: * The program exits
1.1 espie 69: */
1.6 espie 70: /* VARARGS */
71: void
72: Fatal(char *fmt, ...)
1.1 espie 73: {
1.6 espie 74: va_list ap;
1.10 millert 75:
1.6 espie 76: va_start(ap, fmt);
77: Job_Wait();
78:
79: (void)vfprintf(stderr, fmt, ap);
80: va_end(ap);
81: (void)fprintf(stderr, "\n");
1.1 espie 82:
1.6 espie 83: if (DEBUG(GRAPH2))
84: Targ_PrintGraph(2);
85: exit(2); /* Not 1 so -q can distinguish error */
1.1 espie 86: }
87:
88: /*
1.6 espie 89: * Punt --
90: * Major exception once jobs are being created. Kills all jobs, prints
91: * a message and exits.
92: *
93: * Side Effects:
94: * All children are killed indiscriminately and the program Lib_Exits
1.1 espie 95: */
1.6 espie 96: /* VARARGS */
97: void
98: Punt(char *fmt, ...)
1.1 espie 99: {
1.6 espie 100: va_list ap;
1.10 millert 101:
1.6 espie 102: va_start(ap, fmt);
103: (void)fprintf(stderr, "make: ");
104: (void)vfprintf(stderr, fmt, ap);
105: va_end(ap);
106: (void)fprintf(stderr, "\n");
1.1 espie 107:
1.6 espie 108: DieHorribly();
1.3 espie 109: }
110:
1.6 espie 111: /*-
112: * DieHorribly --
113: * Exit without giving a message.
114: *
115: * Side Effects:
116: * A big one...
117: */
1.3 espie 118: void
1.12 espie 119: DieHorribly(void)
1.3 espie 120: {
1.6 espie 121: Job_AbortAll();
122: if (DEBUG(GRAPH2))
123: Targ_PrintGraph(2);
124: exit(2); /* Not 1, so -q can distinguish error */
1.3 espie 125: }
126:
1.6 espie 127: /*
128: * Finish --
129: * Called when aborting due to errors in child shell to signal
130: * abnormal exit.
131: *
132: * Side Effects:
133: * The program exits
134: */
135: void
1.12 espie 136: Finish(int errors) /* number of errors encountered in Make_Make */
1.3 espie 137: {
1.14 ! espie 138: Job_Wait();
! 139: if (errors != 0) {
! 140: Error("make pid #%ld: %d error%s in directory %s:", (long)getpid(),
! 141: errors, errors == 1 ? "" : "s",
! 142: Var_Value(".CURDIR"));
! 143: }
! 144: print_errors();
! 145: if (DEBUG(GRAPH2))
! 146: Targ_PrintGraph(2);
! 147: exit(2); /* Not 1 so -q can distinguish error */
1.3 espie 148: }
1.5 espie 149:
150:
1.6 espie 151: /*-
152: * ParseVErrorInternal --
153: * Error message abort function for parsing. Prints out the context
154: * of the error (line number and file) as well as the message with
155: * two optional arguments.
156: *
157: * Side Effects:
158: * "fatals" is incremented if the level is PARSE_FATAL.
1.1 espie 159: */
1.6 espie 160: /* VARARGS */
161: static void
1.13 espie 162: ParseVErrorInternal(const char *cfname, unsigned long clineno, int type,
1.6 espie 163: const char *fmt, va_list ap)
1.1 espie 164: {
1.8 espie 165: if (cfname)
166: (void)fprintf(stderr, "\"%s\", line %lu: ", cfname, clineno);
1.6 espie 167: if (type == PARSE_WARNING)
168: (void)fprintf(stderr, "warning: ");
169: (void)vfprintf(stderr, fmt, ap);
170: va_end(ap);
171: (void)fprintf(stderr, "\n");
172: if (type == PARSE_FATAL)
173: fatal_errors ++;
174: }
175:
176: /*-
177: * Parse_Error --
178: * External interface to ParseVErrorInternal; uses the default filename
179: * Line number.
1.4 espie 180: */
1.6 espie 181: /* VARARGS */
1.4 espie 182: void
1.6 espie 183: Parse_Error(int type, const char *fmt, ...)
1.4 espie 184: {
1.6 espie 185: va_list ap;
1.10 millert 186:
1.6 espie 187: va_start(ap, fmt);
1.13 espie 188: ParseVErrorInternal(Parse_Getfilename(), Parse_Getlineno(), type,
1.12 espie 189: fmt, ap);
1.11 espie 190: va_end(ap);
1.1 espie 191: }
1.5 espie 192: