aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.