]>
Commit | Line | Data |
---|---|---|
7f2935c7 | 1 | /* Default error handlers for CPP Library. |
5d8ebbd8 | 2 | Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000, |
148e4216 | 3 | 2001, 2002, 2004, 2008, 2009 Free Software Foundation, Inc. |
7f2935c7 | 4 | Written by Per Bothner, 1994. |
38e01259 | 5 | Based on CCCP program by Paul Rubin, June 1986 |
7f2935c7 PB |
6 | Adapted to ANSI C, Richard Stallman, Jan 1987 |
7 | ||
8 | This program is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU General Public License as published by the | |
748086b7 | 10 | Free Software Foundation; either version 3, or (at your option) any |
7f2935c7 PB |
11 | later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
748086b7 JJ |
19 | along with this program; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. | |
7f2935c7 PB |
21 | |
22 | In other words, you are welcome to use, share and improve this program. | |
23 | You are forbidden to forbid anyone else to use, share and improve | |
24 | what you give them. Help stamp out software-hoarding! */ | |
25 | ||
84ee6fd4 | 26 | #include "config.h" |
b04cd507 | 27 | #include "system.h" |
f32da1f6 | 28 | #include "cpplib.h" |
4f4e53dd | 29 | #include "internal.h" |
f32da1f6 | 30 | |
5d8ebbd8 | 31 | /* Print an error at the location of the previously lexed token. */ |
148e4216 | 32 | bool |
e34d07f2 | 33 | cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) |
c1212d2f | 34 | { |
12f9df4e | 35 | source_location src_loc; |
e34d07f2 | 36 | va_list ap; |
148e4216 JM |
37 | bool ret; |
38 | ||
e34d07f2 | 39 | va_start (ap, msgid); |
c1212d2f | 40 | |
148e4216 | 41 | if (CPP_OPTION (pfile, traditional)) |
75ee800b | 42 | { |
148e4216 JM |
43 | if (pfile->state.in_directive) |
44 | src_loc = pfile->directive_line; | |
178b58b5 | 45 | else |
148e4216 JM |
46 | src_loc = pfile->line_table->highest_line; |
47 | } | |
48 | /* We don't want to refer to a token before the beginning of the | |
49 | current run -- that is invalid. */ | |
50 | else if (pfile->cur_token == pfile->cur_run->base) | |
51 | { | |
52 | if (pfile->cur_run->prev != NULL) | |
53 | src_loc = pfile->cur_run->prev->limit->src_loc; | |
54 | else | |
55 | src_loc = 0; | |
178b58b5 | 56 | } |
148e4216 JM |
57 | else |
58 | { | |
59 | src_loc = pfile->cur_token[-1].src_loc; | |
60 | } | |
61 | ||
62 | if (!pfile->cb.error) | |
63 | abort (); | |
64 | ret = pfile->cb.error (pfile, level, src_loc, 0, _(msgid), &ap); | |
b649398a | 65 | |
e34d07f2 | 66 | va_end (ap); |
148e4216 | 67 | return ret; |
c1212d2f ZW |
68 | } |
69 | ||
ebef4e8c | 70 | /* Print an error at a specific location. */ |
148e4216 | 71 | bool |
e34d07f2 | 72 | cpp_error_with_line (cpp_reader *pfile, int level, |
12f9df4e | 73 | source_location src_loc, unsigned int column, |
e34d07f2 | 74 | const char *msgid, ...) |
c1212d2f | 75 | { |
e34d07f2 | 76 | va_list ap; |
148e4216 | 77 | bool ret; |
e34d07f2 KG |
78 | |
79 | va_start (ap, msgid); | |
ab87f8c8 | 80 | |
148e4216 JM |
81 | if (!pfile->cb.error) |
82 | abort (); | |
83 | ret = pfile->cb.error (pfile, level, src_loc, column, _(msgid), &ap); | |
b649398a | 84 | |
e34d07f2 | 85 | va_end (ap); |
148e4216 | 86 | return ret; |
c1212d2f ZW |
87 | } |
88 | ||
148e4216 | 89 | bool |
6cf87ca4 | 90 | cpp_errno (cpp_reader *pfile, int level, const char *msgid) |
c1212d2f | 91 | { |
ebef4e8c NB |
92 | if (msgid[0] == '\0') |
93 | msgid = _("stdout"); | |
94 | ||
148e4216 | 95 | return cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno)); |
c1212d2f | 96 | } |