Annotation of src/usr.bin/make/error.c, Revision 1.7
1.6 espie 1: /* $OpenPackages$ */
1.7 ! espie 2: /* $OpenBSD: error.c,v 1.6 2001/05/23 12:34:42 espie 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: #ifdef __STDC__
29: #include <stdarg.h>
30: #else
31: #include <varargs.h>
32: #endif
33:
1.1 espie 34: #include <stdio.h>
1.7 ! espie 35: #include <stdlib.h>
1.6 espie 36:
37: #include "config.h"
38: #include "defines.h"
1.1 espie 39: #include "error.h"
1.6 espie 40: #include "job.h"
41: #include "targ.h"
42:
43: #include "lowparse.h"
1.1 espie 44:
1.6 espie 45: int fatal_errors = 0;
46: static void ParseVErrorInternal(const char *, unsigned long, int, const char *, va_list);
47: /*-
48: * Error --
49: * Print an error message given its format.
50: */
51: /* VARARGS */
52: void
53: #ifdef __STDC__
54: Error(char *fmt, ...)
1.5 espie 55: #else
1.6 espie 56: Error(va_alist)
57: va_dcl
1.5 espie 58: #endif
1.6 espie 59: {
60: va_list ap;
61: #ifdef __STDC__
62: va_start(ap, fmt);
63: #else
64: char *fmt;
1.5 espie 65:
1.6 espie 66: va_start(ap);
67: fmt = va_arg(ap, char *);
68: #endif
69: (void)vfprintf(stderr, fmt, ap);
70: va_end(ap);
71: (void)fprintf(stderr, "\n");
1.1 espie 72: }
73:
1.6 espie 74: /*-
75: * Fatal --
76: * Produce a Fatal error message. If jobs are running, waits for them
77: * to finish.
78: *
79: * Side Effects:
80: * The program exits
1.1 espie 81: */
1.6 espie 82: /* VARARGS */
83: void
84: #ifdef __STDC__
85: Fatal(char *fmt, ...)
86: #else
87: Fatal(va_alist)
88: va_dcl
89: #endif
1.1 espie 90: {
1.6 espie 91: va_list ap;
92: #ifdef __STDC__
93: va_start(ap, fmt);
94: #else
95: char *fmt;
1.1 espie 96:
1.6 espie 97: va_start(ap);
98: fmt = va_arg(ap, char *);
99: #endif
100: Job_Wait();
101:
102: (void)vfprintf(stderr, fmt, ap);
103: va_end(ap);
104: (void)fprintf(stderr, "\n");
1.1 espie 105:
1.6 espie 106: if (DEBUG(GRAPH2))
107: Targ_PrintGraph(2);
108: exit(2); /* Not 1 so -q can distinguish error */
1.1 espie 109: }
110:
111: /*
1.6 espie 112: * Punt --
113: * Major exception once jobs are being created. Kills all jobs, prints
114: * a message and exits.
115: *
116: * Side Effects:
117: * All children are killed indiscriminately and the program Lib_Exits
1.1 espie 118: */
1.6 espie 119: /* VARARGS */
120: void
121: #ifdef __STDC__
122: Punt(char *fmt, ...)
123: #else
124: Punt(va_alist)
125: va_dcl
126: #endif
1.1 espie 127: {
1.6 espie 128: va_list ap;
129: #ifdef __STDC__
130: va_start(ap, fmt);
131: #else
132: char *fmt;
1.1 espie 133:
1.6 espie 134: va_start(ap);
135: fmt = va_arg(ap, char *);
136: #endif
1.1 espie 137:
1.6 espie 138: (void)fprintf(stderr, "make: ");
139: (void)vfprintf(stderr, fmt, ap);
140: va_end(ap);
141: (void)fprintf(stderr, "\n");
1.1 espie 142:
1.6 espie 143: DieHorribly();
1.3 espie 144: }
145:
1.6 espie 146: /*-
147: * DieHorribly --
148: * Exit without giving a message.
149: *
150: * Side Effects:
151: * A big one...
152: */
1.3 espie 153: void
1.6 espie 154: DieHorribly()
1.3 espie 155: {
1.6 espie 156: Job_AbortAll();
157: if (DEBUG(GRAPH2))
158: Targ_PrintGraph(2);
159: exit(2); /* Not 1, so -q can distinguish error */
1.3 espie 160: }
161:
1.6 espie 162: /*
163: * Finish --
164: * Called when aborting due to errors in child shell to signal
165: * abnormal exit.
166: *
167: * Side Effects:
168: * The program exits
169: */
170: void
171: Finish(errors)
172: int errors; /* number of errors encountered in Make_Make */
1.3 espie 173: {
1.6 espie 174: Fatal("%d error%s", errors, errors == 1 ? "" : "s");
1.3 espie 175: }
1.5 espie 176:
177:
1.6 espie 178: /*-
179: * ParseVErrorInternal --
180: * Error message abort function for parsing. Prints out the context
181: * of the error (line number and file) as well as the message with
182: * two optional arguments.
183: *
184: * Side Effects:
185: * "fatals" is incremented if the level is PARSE_FATAL.
1.1 espie 186: */
1.6 espie 187: /* VARARGS */
188: static void
189: #ifdef __STDC__
190: ParseVErrorInternal(const char *cfname, unsigned long clineno, int type,
191: const char *fmt, va_list ap)
192: #else
193: ParseVErrorInternal(va_alist)
194: va_dcl
195: #endif
1.1 espie 196: {
1.6 espie 197: (void)fprintf(stderr, "\"%s\", line %lu: ", cfname, clineno);
198: if (type == PARSE_WARNING)
199: (void)fprintf(stderr, "warning: ");
200: (void)vfprintf(stderr, fmt, ap);
201: va_end(ap);
202: (void)fprintf(stderr, "\n");
203: if (type == PARSE_FATAL)
204: fatal_errors ++;
205: }
206:
207: /*-
208: * Parse_Error --
209: * External interface to ParseVErrorInternal; uses the default filename
210: * Line number.
1.4 espie 211: */
1.6 espie 212: /* VARARGS */
1.4 espie 213: void
1.6 espie 214: #ifdef __STDC__
215: Parse_Error(int type, const char *fmt, ...)
216: #else
217: Parse_Error(va_alist)
218: va_dcl
219: #endif
1.4 espie 220: {
1.6 espie 221: va_list ap;
222: #ifdef __STDC__
223: va_start(ap, fmt);
224: #else
225: int type; /* Error type (PARSE_WARNING, PARSE_FATAL) */
226: char *fmt;
1.1 espie 227:
1.6 espie 228: va_start(ap);
229: type = va_arg(ap, int);
230: fmt = va_arg(ap, char *);
231: #endif
1.1 espie 232:
1.6 espie 233: ParseVErrorInternal(Parse_Getfilename(), Parse_Getlineno(), type, fmt, ap);
1.1 espie 234: }
1.5 espie 235: