Annotation of src/usr.bin/make/error.c, Revision 1.24
1.24 ! espie 1: /* $OpenBSD: error.c,v 1.23 2012/10/02 10:29:30 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.23 espie 45: #include "dump.h"
1.1 espie 46:
1.15 espie 47: int fatal_errors = 0;
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.22 espie 80: Job_Wait();
1.15 espie 81:
1.6 espie 82: va_start(ap, fmt);
83: (void)vfprintf(stderr, fmt, ap);
84: va_end(ap);
85: (void)fprintf(stderr, "\n");
1.1 espie 86:
1.6 espie 87: if (DEBUG(GRAPH2))
1.23 espie 88: post_mortem();
1.6 espie 89: exit(2); /* Not 1 so -q can distinguish error */
1.1 espie 90: }
91:
92: /*
1.6 espie 93: * Punt --
94: * Major exception once jobs are being created. Kills all jobs, prints
95: * a message and exits.
96: *
97: * Side Effects:
98: * All children are killed indiscriminately and the program Lib_Exits
1.1 espie 99: */
1.6 espie 100: /* VARARGS */
101: void
102: Punt(char *fmt, ...)
1.1 espie 103: {
1.22 espie 104: if (fmt) {
105: va_list ap;
1.10 millert 106:
1.22 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");
112: }
1.1 espie 113:
1.6 espie 114: Job_AbortAll();
115: if (DEBUG(GRAPH2))
1.23 espie 116: post_mortem();
1.6 espie 117: exit(2); /* Not 1, so -q can distinguish error */
1.3 espie 118: }
119:
1.6 espie 120: /*
121: * Finish --
1.22 espie 122: * Called when aborting due to errors in command or fatal signal
1.6 espie 123: *
124: * Side Effects:
125: * The program exits
126: */
127: void
1.22 espie 128: Finish()
1.3 espie 129: {
1.14 espie 130: Job_Wait();
131: print_errors();
132: if (DEBUG(GRAPH2))
1.23 espie 133: post_mortem();
1.14 espie 134: exit(2); /* Not 1 so -q can distinguish error */
1.3 espie 135: }
1.5 espie 136:
137:
1.6 espie 138: /*-
139: * ParseVErrorInternal --
140: * Error message abort function for parsing. Prints out the context
141: * of the error (line number and file) as well as the message with
142: * two optional arguments.
143: *
144: * Side Effects:
145: * "fatals" is incremented if the level is PARSE_FATAL.
1.1 espie 146: */
1.6 espie 147: /* VARARGS */
148: static void
1.20 espie 149: ParseVErrorInternal(const Location *origin, int type, const char *fmt,
150: va_list ap)
1.1 espie 151: {
1.24 ! espie 152: static bool first = true;
! 153: fprintf(stderr, "*** %s",
! 154: type == PARSE_WARNING ? "Warning" : "Parse error");
! 155: if (first) {
! 156: fprintf(stderr, " in %s: ", Var_Value(".CURDIR"));
! 157: first = false;
! 158: } else
! 159: fprintf(stderr, ": ");
! 160: vfprintf(stderr, fmt, ap);
! 161: va_end(ap);
1.20 espie 162: if (origin->fname)
1.24 ! espie 163: fprintf(stderr, " (%s:%lu)", origin->fname, origin->lineno);
! 164: fprintf(stderr, "\n");
1.6 espie 165: if (type == PARSE_FATAL)
166: fatal_errors ++;
167: }
168:
169: /*-
170: * Parse_Error --
171: * External interface to ParseVErrorInternal; uses the default filename
172: * Line number.
1.4 espie 173: */
1.6 espie 174: /* VARARGS */
1.4 espie 175: void
1.6 espie 176: Parse_Error(int type, const char *fmt, ...)
1.4 espie 177: {
1.6 espie 178: va_list ap;
1.20 espie 179: Location l;
1.10 millert 180:
1.6 espie 181: va_start(ap, fmt);
1.20 espie 182: Parse_FillLocation(&l);
183: ParseVErrorInternal(&l, type, fmt, ap);
1.11 espie 184: va_end(ap);
1.1 espie 185: }