aboutsummaryrefslogtreecommitdiff
path: root/src/diag.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-11-27 12:28:53 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-11-27 12:28:53 +0200
commit3afa623999ef46a81e353971197ae697d7febfe7 (patch)
tree0ca9008aae384704eda39dc452df9275eb1f29c3 /src/diag.c
parent690ec7913002d28537dbfc04532b17a10ee56ab3 (diff)
downloadgrecs-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/diag.c')
-rw-r--r--src/diag.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/diag.c b/src/diag.c
index 6de3ce6..2fc6f20 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -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;
+}
+

Return to:

Send suggestions and report system problems to the System administrator.