summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2013-11-27 10:28:53 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-11-27 10:28:53 (GMT)
commit3afa623999ef46a81e353971197ae697d7febfe7 (patch) (side-by-side diff)
tree0ca9008aae384704eda39dc452df9275eb1f29c3 /src
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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/diag.c28
-rw-r--r--src/grecs.hin3
2 files changed, 31 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;
+}
+
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;

Return to:

Send suggestions and report system problems to the System administrator.