aboutsummaryrefslogtreecommitdiff
path: root/src/diag.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diag.c')
-rw-r--r--src/diag.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/diag.c b/src/diag.c
index 53bc044..fe057d0 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -1,8 +1,8 @@
/* This file is part of GNU Pies.
- Copyright (C) 2009, 2010 Sergey Poznyakoff
+ Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
GNU Pies is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
@@ -122,21 +122,49 @@ logmsg_printf (int prio, const char *fmt, ...)
va_end (ap);
}
void
grecs_print_diag (grecs_locus_t *locus, int err, int errcode, const char *msg)
{
+ char *locstr = NULL;
+
if (locus)
{
+ size_t size = 0;
+
+ if (locus->beg.col == 0)
+ grecs_asprintf (&locstr, &size, "%s:%u",
+ locus->beg.file,
+ locus->beg.line);
+ else if (strcmp (locus->beg.file, locus->end.file))
+ grecs_asprintf (&locstr, &size, "%s:%u.%u-%s:%u.%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.file,
+ locus->end.line, locus->end.col);
+ else if (locus->beg.line != locus->end.line)
+ grecs_asprintf (&locstr, &size, "%s:%u.%u-%u.%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.line, locus->end.col);
+ else
+ grecs_asprintf (&locstr, &size, "%s:%u.%u-%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.col);
+ }
+
+ if (locstr)
+ {
if (errcode)
- logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s: %s",
- locus->file, (unsigned long)locus->line, msg,
- strerror (errcode));
+ logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s: %s",
+ locstr, msg, strerror (errcode));
else
- logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s",
- locus->file, (unsigned long)locus->line, msg);
+ logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s",
+ locstr, msg);
+ free (locstr);
}
else
{
if (errcode)
logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s", msg,
strerror (errcode));

Return to:

Send suggestions and report system problems to the System administrator.