#include "config.h"
#include "system.h"
#include "cpplib.h"
#include "cpphash.h"
#include "intl.h"
static int gcc_error_colon = 0;
static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int));
static void
print_location (pfile, line, col)
cpp_reader *pfile;
unsigned int line, col;
{
const char *estr;
{
static int done = 0;
if ( ! done)
{
done = 1;
if (getenv ("GCC_DASH_W"))
CPP_OPTION (pfile, inhibit_warnings) = 1;
if (getenv ("GCC_ERROR_COLON"))
gcc_error_colon = 1;
}
}
{
estr = (gcc_error_colon) ? "error:" : "" ;
}
if (!pfile->buffer || line == 0)
fprintf (stderr, "%s: ", progname);
else
{
const struct line_map *map;
map = lookup_line (&pfile->line_maps, line);
print_containing_files (&pfile->line_maps, map);
line = SOURCE_LINE (map, line);
if (col == 0)
col = 1;
if (line == 0)
fprintf (stderr, "%s:%s", map->to_file, estr);
else if (CPP_OPTION (pfile, show_column) == 0)
fprintf (stderr, "%s:%u:%s", map->to_file, line, estr);
else
fprintf (stderr, "%s:%u:%u:%s", map->to_file, line, col, estr);
fputc (' ', stderr);
}
}
int
_cpp_begin_message (pfile, code, line, column)
cpp_reader *pfile;
int code;
unsigned int line, column;
{
int level = DL_EXTRACT (code);
switch (level)
{
case DL_WARNING:
case DL_PEDWARN:
if (CPP_IN_SYSTEM_HEADER (pfile)
&& ! CPP_OPTION (pfile, warn_system_headers))
return 0;
case DL_WARNING_SYSHDR:
if (CPP_OPTION (pfile, warnings_are_errors)
|| (level == DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors)))
{
if (CPP_OPTION (pfile, inhibit_errors))
return 0;
level = DL_ERROR;
pfile->errors++;
}
else if (CPP_OPTION (pfile, inhibit_warnings))
return 0;
break;
case DL_ERROR:
if (CPP_OPTION (pfile, inhibit_errors))
return 0;
case DL_ICE:
pfile->errors++;
break;
}
print_location (pfile, line, column);
if (DL_WARNING_P (level))
fputs (_("warning: "), stderr);
else if (level == DL_ICE)
fputs (_("internal error: "), stderr);
return 1;
}
#define v_message(msgid, ap) \
do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
void
cpp_error VPARAMS ((cpp_reader * pfile, int level, const char *msgid, ...))
{
unsigned int line, column;
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, level);
VA_FIXEDARG (ap, const char *, msgid);
if (pfile->buffer)
{
if (CPP_OPTION (pfile, traditional))
{
if (pfile->state.in_directive)
line = pfile->directive_line;
else
line = pfile->line;
column = 0;
}
else
{
line = pfile->cur_token[-1].line;
column = pfile->cur_token[-1].col;
}
}
else
line = column = 0;
if (_cpp_begin_message (pfile, level, line, column))
v_message (msgid, ap);
VA_CLOSE (ap);
}
void
cpp_error_with_line VPARAMS ((cpp_reader *pfile, int level,
unsigned int line, unsigned int column,
const char *msgid, ...))
{
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, level);
VA_FIXEDARG (ap, unsigned int, line);
VA_FIXEDARG (ap, unsigned int, column);
VA_FIXEDARG (ap, const char *, msgid);
if (_cpp_begin_message (pfile, level, line, column))
v_message (msgid, ap);
VA_CLOSE (ap);
}
void
cpp_errno (pfile, level, msgid)
cpp_reader *pfile;
int level;
const char *msgid;
{
if (msgid[0] == '\0')
msgid = _("stdout");
cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
}