00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "config.h"
00027 #include "system.h"
00028 #include "cpplib.h"
00029 #include "internal.h"
00030
00031 static void print_location (cpp_reader *, source_location, unsigned int);
00032
00033
00034
00035
00036
00037 static void
00038 print_location (cpp_reader *pfile, source_location line, unsigned int col)
00039 {
00040 if (line == 0)
00041 fprintf (stderr, "%s: ", progname);
00042 else
00043 {
00044 const struct line_map *map;
00045 unsigned int lin;
00046
00047 map = linemap_lookup (pfile->line_table, line);
00048 linemap_print_containing_files (pfile->line_table, map);
00049
00050 lin = SOURCE_LINE (map, line);
00051 if (col == 0)
00052 {
00053 col = SOURCE_COLUMN (map, line);
00054 if (col == 0)
00055 col = 1;
00056 }
00057
00058 if (lin == 0)
00059 fprintf (stderr, "%s:", map->to_file);
00060 else if (CPP_OPTION (pfile, show_column) == 0)
00061 fprintf (stderr, "%s:%u:", map->to_file, lin);
00062 else
00063 fprintf (stderr, "%s:%u:%u:", map->to_file, lin, col);
00064
00065 fputc (' ', stderr);
00066 }
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 int
00080 _cpp_begin_message (cpp_reader *pfile, int code,
00081 source_location src_loc, unsigned int column)
00082 {
00083 int level = CPP_DL_EXTRACT (code);
00084
00085 switch (level)
00086 {
00087 case CPP_DL_WARNING:
00088 case CPP_DL_PEDWARN:
00089 if (cpp_in_system_header (pfile)
00090 && ! CPP_OPTION (pfile, warn_system_headers))
00091 return 0;
00092
00093
00094 case CPP_DL_WARNING_SYSHDR:
00095 if (CPP_OPTION (pfile, warnings_are_errors)
00096 || (level == CPP_DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors)))
00097 {
00098 if (CPP_OPTION (pfile, inhibit_errors))
00099 return 0;
00100 level = CPP_DL_ERROR;
00101 pfile->errors++;
00102 }
00103 else if (CPP_OPTION (pfile, inhibit_warnings))
00104 return 0;
00105 break;
00106
00107 case CPP_DL_ERROR:
00108 if (CPP_OPTION (pfile, inhibit_errors))
00109 return 0;
00110
00111 case CPP_DL_ICE:
00112 pfile->errors++;
00113 break;
00114 }
00115
00116 print_location (pfile, src_loc, column);
00117 if (CPP_DL_WARNING_P (level))
00118 fputs (_("warning: "), stderr);
00119 else if (level == CPP_DL_ICE)
00120 fputs (_("internal error: "), stderr);
00121 else
00122 fputs (_("error: "), stderr);
00123
00124 return 1;
00125 }
00126
00127
00128
00129 #define v_message(msgid, ap) \
00130 do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
00131
00132
00133
00134
00135 void
00136 cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
00137 {
00138 source_location src_loc;
00139 va_list ap;
00140
00141 va_start (ap, msgid);
00142
00143 if (CPP_OPTION (pfile, traditional))
00144 {
00145 if (pfile->state.in_directive)
00146 src_loc = pfile->directive_line;
00147 else
00148 src_loc = pfile->line_table->highest_line;
00149 }
00150 else
00151 {
00152 src_loc = pfile->cur_token[-1].src_loc;
00153 }
00154
00155 if (_cpp_begin_message (pfile, level, src_loc, 0))
00156 v_message (msgid, ap);
00157
00158 va_end (ap);
00159 }
00160
00161
00162 void
00163 cpp_error_with_line (cpp_reader *pfile, int level,
00164 source_location src_loc, unsigned int column,
00165 const char *msgid, ...)
00166 {
00167 va_list ap;
00168
00169 va_start (ap, msgid);
00170
00171 if (_cpp_begin_message (pfile, level, src_loc, column))
00172 v_message (msgid, ap);
00173
00174 va_end (ap);
00175 }
00176
00177 void
00178 cpp_errno (cpp_reader *pfile, int level, const char *msgid)
00179 {
00180 if (msgid[0] == '\0')
00181 msgid = _("stdout");
00182
00183 cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
00184 }