diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-11-27 12:28:53 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-11-27 12:28:53 +0200 |
commit | 3afa623999ef46a81e353971197ae697d7febfe7 (patch) | |
tree | 0ca9008aae384704eda39dc452df9275eb1f29c3 /src | |
parent | 690ec7913002d28537dbfc04532b17a10ee56ab3 (diff) | |
download | grecs-3afa623999ef46a81e353971197ae697d7febfe7.tar.gz grecs-3afa623999ef46a81e353971197ae697d7febfe7.tar.bz2 |
New function for formatting grecs loci.
* src/diag.c (grecs_asprint_locus): New function.
* src/grecs.hin (grecs_asprint_locus): New proto.
Diffstat (limited to 'src')
-rw-r--r-- | src/diag.c | 28 | ||||
-rw-r--r-- | src/grecs.hin | 3 |
2 files changed, 31 insertions, 0 deletions
@@ -77,4 +77,32 @@ grecs_error(grecs_locus_t const *locus, int errcode, const char *fmt, ...) grecs_error_count++; } +int +grecs_asprint_locus(char **locstr, size_t *size, grecs_locus_t const *locus) +{ + int rc; + + if (locus->beg.col == 0) + rc = grecs_asprintf(locstr, size, "%s:%u", + locus->beg.file, + locus->beg.line); + else if (strcmp(locus->beg.file, locus->end.file)) + rc = 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) + rc = 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 + rc = grecs_asprintf(locstr, size, "%s:%u.%u-%u", + locus->beg.file, + locus->beg.line, locus->beg.col, + locus->end.col); + return rc; +} + diff --git a/src/grecs.hin b/src/grecs.hin index 1a591d3..8bf0826 100644 --- a/src/grecs.hin +++ b/src/grecs.hin @@ -228,6 +228,9 @@ void grecs_error(grecs_locus_t const *locus, int errcode, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); +int grecs_asprint_locus(char **locstr, size_t *size, + grecs_locus_t const *locus); + extern int grecs_trace_flags; |