From: phk Date: Wed, 9 May 2007 07:59:22 +0000 (+0000) Subject: Sanitize generation of white-space in generated C code. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c56f714cd1073b020ebbb64b16ae584c4c85d823;p=varnish Sanitize generation of white-space in generated C code. (It is my intent that the compiled-to C-source should have sensible readability) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1388 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index b35d4090..b01b2498 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -134,7 +134,7 @@ Fh(const struct tokenlist *tl, int indent, const char *fmt, ...) va_list ap; if (indent) - vsb_printf(tl->fh, "%*.*s", tl->indent, tl->indent, ""); + vsb_printf(tl->fh, "%*.*s", tl->hindent, tl->hindent, ""); va_start(ap, fmt); vsb_vprintf(tl->fh, fmt, ap); va_end(ap); @@ -171,7 +171,7 @@ Fi(const struct tokenlist *tl, int indent, const char *fmt, ...) va_list ap; if (indent) - vsb_printf(tl->fi, "%*.*s", tl->indent, tl->indent, ""); + vsb_printf(tl->fi, "%*.*s", tl->iindent, tl->iindent, ""); va_start(ap, fmt); vsb_vprintf(tl->fi, fmt, ap); va_end(ap); @@ -183,7 +183,7 @@ Ff(const struct tokenlist *tl, int indent, const char *fmt, ...) va_list ap; if (indent) - vsb_printf(tl->ff, "%*.*s", tl->indent, tl->indent, ""); + vsb_printf(tl->ff, "%*.*s", tl->findent, tl->findent, ""); va_start(ap, fmt); vsb_vprintf(tl->ff, fmt, ap); va_end(ap); @@ -301,8 +301,8 @@ LocTable(const struct tokenlist *tl) struct source *sp; const char *p; - Fh(tl, 0, "#define VGC_NREFS %u\n", tl->cnt + 1); - Fc(tl, 0, "static struct vrt_ref VGC_ref[VGC_NREFS] = {\n"); + Fh(tl, 0, "\n#define VGC_NREFS %u\n", tl->cnt + 1); + Fc(tl, 0, "\nstatic struct vrt_ref VGC_ref[VGC_NREFS] = {\n"); lin = 1; pos = 0; sp = 0; @@ -590,7 +590,8 @@ vcc_CompileSource(struct vsb *sb, struct source *sp) tl->sb = sb; vcl_output_lang_h(tl->fh); - Fh(tl, 0, "extern struct VCL_conf VCL_conf;\n"); + Fh(tl, 0, "\n/* ---===### VCC generated below here ###===---*/\n"); + Fh(tl, 0, "\nextern struct VCL_conf VCL_conf;\n"); Fi(tl, 0, "\tVRT_alloc_backends(&VCL_conf);\n"); @@ -639,14 +640,14 @@ vcc_CompileSource(struct vsb *sb, struct source *sp) /* Emit method functions */ for (i = 0; i < N_METHODS; i++) { - Fc(tl, 1, "static int\n"); + Fc(tl, 1, "\nstatic int\n"); Fc(tl, 1, "VGC_function_%s (struct sess *sp)\n", method_tab[i].name); vsb_finish(tl->fm[i]); /* XXX: check vsb_overflowed ? */ Fc(tl, 1, "{\n"); Fc(tl, 1, "%s", vsb_data(tl->fm[i])); - Fc(tl, 1, "}\n\n"); + Fc(tl, 1, "}\n"); } LocTable(tl); diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index 1e6239af..563b351c 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -67,6 +67,9 @@ struct tokenlist { struct source *src; struct token *t; int indent; + int hindent; + int iindent; + int findent; unsigned cnt; struct vsb *fc, *fh, *fi, *ff, *fb; struct vsb *fm[N_METHODS];