292
|
1 /*
|
|
2 lwcc/cpp/error.c
|
|
3
|
|
4 Copyright © 2013 William Astle
|
|
5
|
|
6 This file is part of LWTOOLS.
|
|
7
|
|
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
|
|
9 terms of the GNU General Public License as published by the Free Software
|
|
10 Foundation, either version 3 of the License, or (at your option) any later
|
|
11 version.
|
|
12
|
|
13 This program is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
16 more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License along with
|
|
19 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 */
|
|
21
|
|
22 #include <stdarg.h>
|
|
23 #include <stdio.h>
|
|
24 #include <stdlib.h>
|
|
25
|
|
26 #include "cpp.h"
|
|
27
|
|
28 static void show_file_pos(void)
|
|
29 {
|
|
30 if (file_stack == NULL)
|
|
31 return;
|
|
32
|
|
33 fprintf(stderr, "(%s:%d): ", file_stack -> fn, file_stack -> line);
|
|
34 }
|
|
35
|
|
36 void do_error(const char *f, ...)
|
|
37 {
|
|
38 va_list arg;
|
|
39
|
|
40 va_start(arg, f);
|
|
41 fprintf(stderr, "ERROR: ");
|
|
42 show_file_pos();
|
|
43 vfprintf(stderr, f, arg);
|
|
44 fprintf(stderr, "\n");
|
|
45 va_end(arg);
|
|
46 exit(1);
|
|
47 }
|
|
48
|
|
49 void do_warning(const char *f, ...)
|
|
50 {
|
|
51 va_list arg;
|
|
52
|
|
53 va_start(arg, f);
|
|
54 fprintf(stderr, "WARNING: ");
|
|
55 show_file_pos();
|
|
56 vfprintf(stderr, f, arg);
|
|
57 fprintf(stderr, "\n");
|
|
58 va_end(arg);
|
|
59 }
|