Annotation of src/usr.bin/make/error.c, Revision 1.10
1.6 espie 1: /* $OpenPackages$ */
1.10 ! millert 2: /* $OpenBSD: error.c,v 1.9 2001/09/05 22:32:41 deraadt Exp $ */
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.6 espie 32:
33: #include "config.h"
34: #include "defines.h"
1.1 espie 35: #include "error.h"
1.6 espie 36: #include "job.h"
37: #include "targ.h"
38:
39: #include "lowparse.h"
1.1 espie 40:
1.6 espie 41: int fatal_errors = 0;
42: static void ParseVErrorInternal(const char *, unsigned long, int, const char *, va_list);
43: /*-
44: * Error --
45: * Print an error message given its format.
46: */
47: /* VARARGS */
48: void
49: Error(char *fmt, ...)
50: {
51: va_list ap;
1.10 ! millert 52:
1.6 espie 53: va_start(ap, fmt);
54: (void)vfprintf(stderr, fmt, ap);
55: va_end(ap);
56: (void)fprintf(stderr, "\n");
1.1 espie 57: }
58:
1.6 espie 59: /*-
60: * Fatal --
61: * Produce a Fatal error message. If jobs are running, waits for them
62: * to finish.
63: *
64: * Side Effects:
65: * The program exits
1.1 espie 66: */
1.6 espie 67: /* VARARGS */
68: void
69: Fatal(char *fmt, ...)
1.1 espie 70: {
1.6 espie 71: va_list ap;
1.10 ! millert 72:
1.6 espie 73: va_start(ap, fmt);
74: Job_Wait();
75:
76: (void)vfprintf(stderr, fmt, ap);
77: va_end(ap);
78: (void)fprintf(stderr, "\n");
1.1 espie 79:
1.6 espie 80: if (DEBUG(GRAPH2))
81: Targ_PrintGraph(2);
82: exit(2); /* Not 1 so -q can distinguish error */
1.1 espie 83: }
84:
85: /*
1.6 espie 86: * Punt --
87: * Major exception once jobs are being created. Kills all jobs, prints
88: * a message and exits.
89: *
90: * Side Effects:
91: * All children are killed indiscriminately and the program Lib_Exits
1.1 espie 92: */
1.6 espie 93: /* VARARGS */
94: void
95: Punt(char *fmt, ...)
1.1 espie 96: {
1.6 espie 97: va_list ap;
1.10 ! millert 98:
1.6 espie 99: va_start(ap, fmt);
100: (void)fprintf(stderr, "make: ");
101: (void)vfprintf(stderr, fmt, ap);
102: va_end(ap);
103: (void)fprintf(stderr, "\n");
1.1 espie 104:
1.6 espie 105: DieHorribly();
1.3 espie 106: }
107:
1.6 espie 108: /*-
109: * DieHorribly --
110: * Exit without giving a message.
111: *
112: * Side Effects:
113: * A big one...
114: */
1.3 espie 115: void
1.6 espie 116: DieHorribly()
1.3 espie 117: {
1.6 espie 118: Job_AbortAll();
119: if (DEBUG(GRAPH2))
120: Targ_PrintGraph(2);
121: exit(2); /* Not 1, so -q can distinguish error */
1.3 espie 122: }
123:
1.6 espie 124: /*
125: * Finish --
126: * Called when aborting due to errors in child shell to signal
127: * abnormal exit.
128: *
129: * Side Effects:
130: * The program exits
131: */
132: void
133: Finish(errors)
134: int errors; /* number of errors encountered in Make_Make */
1.3 espie 135: {
1.6 espie 136: Fatal("%d error%s", errors, errors == 1 ? "" : "s");
1.3 espie 137: }
1.5 espie 138:
139:
1.6 espie 140: /*-
141: * ParseVErrorInternal --
142: * Error message abort function for parsing. Prints out the context
143: * of the error (line number and file) as well as the message with
144: * two optional arguments.
145: *
146: * Side Effects:
147: * "fatals" is incremented if the level is PARSE_FATAL.
1.1 espie 148: */
1.6 espie 149: /* VARARGS */
150: static void
151: ParseVErrorInternal(const char *cfname, unsigned long clineno, int type,
152: const char *fmt, va_list ap)
1.1 espie 153: {
1.8 espie 154: if (cfname)
155: (void)fprintf(stderr, "\"%s\", line %lu: ", cfname, clineno);
1.6 espie 156: if (type == PARSE_WARNING)
157: (void)fprintf(stderr, "warning: ");
158: (void)vfprintf(stderr, fmt, ap);
159: va_end(ap);
160: (void)fprintf(stderr, "\n");
161: if (type == PARSE_FATAL)
162: fatal_errors ++;
163: }
164:
165: /*-
166: * Parse_Error --
167: * External interface to ParseVErrorInternal; uses the default filename
168: * Line number.
1.4 espie 169: */
1.6 espie 170: /* VARARGS */
1.4 espie 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.10 ! millert 175:
1.6 espie 176: va_start(ap, fmt);
177: ParseVErrorInternal(Parse_Getfilename(), Parse_Getlineno(), type, fmt, ap);
1.9 deraadt 178: va_end(va);
1.1 espie 179: }
1.5 espie 180: