From cbf89abe774a763399b4752e520185697525821c Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 29 Sep 2008 08:11:06 +0000 Subject: [PATCH] Split vcc_Coord() function out from vcc_ErrWhere(), to give a set of source coordinates in human readable form in a vsb. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3235 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvcl/vcc_compile.h | 1 + varnish-cache/lib/libvcl/vcc_token.c | 38 ++++++++++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index 4b80f0cd..90008c42 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -203,6 +203,7 @@ int vcc_StringVal(struct tokenlist *tl); void vcc_ExpectedStringval(struct tokenlist *tl); /* vcc_token.c */ +void vcc_Coord(const struct tokenlist *tl, struct vsb *vsb, const struct token *t); void vcc_ErrToken(const struct tokenlist *tl, const struct token *t); void vcc_ErrWhere(struct tokenlist *tl, const struct token *t); void vcc__Expect(struct tokenlist *tl, unsigned tok, int line); diff --git a/varnish-cache/lib/libvcl/vcc_token.c b/varnish-cache/lib/libvcl/vcc_token.c index a6a72f8c..093c317c 100644 --- a/varnish-cache/lib/libvcl/vcc_token.c +++ b/varnish-cache/lib/libvcl/vcc_token.c @@ -68,32 +68,52 @@ vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line) tl->err = 1; } -void -vcc_ErrWhere(struct tokenlist *tl, const struct token *t) +static void +vcc_icoord(struct vsb *vsb, const struct token *t, const char **ll) { - unsigned lin, pos, x, y; - const char *p, *l, *f, *b, *e; + unsigned lin, pos; + const char *p, *b; struct source *sp; lin = 1; pos = 0; sp = t->src; - f = sp->name; b = sp->b; - e = sp->e; - for (l = p = b; p < t->b; p++) { + for (p = b; p < t->b; p++) { if (*p == '\n') { lin++; pos = 0; - l = p + 1; + if (ll != NULL) + *ll = p + 1; } else if (*p == '\t') { pos &= ~7; pos += 8; } else pos++; } - vsb_printf(tl->sb, "(%s Line %d Pos %d)\n", f, lin, pos + 1); + vsb_printf(vsb, "(%s Line %d Pos %d)", sp->name, lin, pos + 1); +} + +void +vcc_Coord(const struct tokenlist *tl, struct vsb *vsb, const struct token *t) +{ + + if (t == NULL) + t = tl->t; + vcc_icoord(vsb, t, NULL); +} + +void +vcc_ErrWhere(struct tokenlist *tl, const struct token *t) +{ + unsigned x, y; + const char *p, *l, *e; + + vcc_icoord(tl->sb, t, &l); + vsb_printf(tl->sb, "\n"); + x = y = 0; + e = t->src->e; for (p = l; p < e && *p != '\n'; p++) { if (*p == '\t') { y &= ~7; -- 2.39.5