diff options
Diffstat (limited to 'src/diag.c')
-rw-r--r-- | src/diag.c | 40 |
1 files changed, 34 insertions, 6 deletions
@@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2009, 2010 Sergey Poznyakoff + Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff @@ -127,11 +127,39 @@ 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); } |