diff options
author | Ori Bernstein <ori@eigenstate.org> | 2016-02-28 19:38:11 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2016-02-28 19:38:11 -0800 |
commit | 7f738bb025195cfb91403588480877c12e72a6d6 (patch) | |
tree | 840882c19c3a429e6bc0f79ccebaa18de24b3018 | |
parent | 09c45b936d8977ed0896905ad2fb9e5d1e1e9b65 (diff) | |
download | roux-7f738bb025195cfb91403588480877c12e72a6d6.tar.gz |
More standard/better error message formatting.
-rw-r--r-- | lisc/lisc.h | 2 | ||||
-rw-r--r-- | lisc/main.c | 7 | ||||
-rw-r--r-- | lisc/parse.c | 21 |
3 files changed, 22 insertions, 8 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h index 3215796..18d435d 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -482,7 +482,7 @@ int bsiter(BSet *, uint *); /* parse.c */ extern OpDesc opdesc[NOp]; -void parse(FILE *, void (Dat *), void (Fn *)); +void parse(FILE *, char *, void (Dat *), void (Fn *)); void printfn(Fn *, FILE *); void printref(Ref, Fn *, FILE *); diff --git a/lisc/main.c b/lisc/main.c index a0959ef..5e4f8f2 100644 --- a/lisc/main.c +++ b/lisc/main.c @@ -97,16 +97,17 @@ main(int ac, char *av[]) do { f = av[optind]; - if (!f || strcmp(f, "-") == 0) + if (!f || strcmp(f, "-") == 0) { inf = stdin; - else { + f = "-"; + } else { inf = fopen(f, "r"); if (!inf) { fprintf(stderr, "cannot open '%s'\n", f); exit(1); } } - parse(inf, data, func); + parse(inf, f, data, func); } while (++optind < ac); if (!dbg) 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 <ctype.h> +#include <stdarg.h> 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; |