From 7f738bb025195cfb91403588480877c12e72a6d6 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sun, 28 Feb 2016 19:38:11 -0800 Subject: More standard/better error message formatting. --- lisc/parse.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lisc/parse.c') diff --git a/lisc/parse.c b/lisc/parse.c index 49ed139..2c25476 100644 --- a/lisc/parse.c +++ b/lisc/parse.c @@ -1,5 +1,6 @@ #include "lisc.h" #include +#include OpDesc opdesc[NOp] = { /* NAME NM */ @@ -107,6 +108,7 @@ enum { static FILE *inf; +static char *inpath; static int thead; static struct { double fltd; @@ -129,12 +131,22 @@ static int rcls; static int ntyp; + static void -err(char *s) +err(char *s, ...) { - char buf[100]; + char buf[100], *p, *end; + va_list ap; + + + p = buf; + end = buf + sizeof(buf); + + va_start(ap, s); + p += snprintf(p, end - p, "%s:%d: ", inpath, lnum); + p += vsnprintf(p, end - p, s, ap); + va_end(ap); - snprintf(buf, sizeof buf, "parse: %s (line %d)", s, lnum); diag(buf); } @@ -815,9 +827,10 @@ parsedat(void cb(Dat *)) } void -parse(FILE *f, void data(Dat *), void func(Fn *)) +parse(FILE *f, char *path, void data(Dat *), void func(Fn *)) { inf = f; + inpath = path; lnum = 1; thead = TXXX; ntyp = 0; -- cgit 1.4.1