]> err.no Git - varnish/commitdiff
Move string stuff to vcc_string.c, there's going to be a fair bit of it.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 10 Jul 2007 19:46:16 +0000 (19:46 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 10 Jul 2007 19:46:16 +0000 (19:46 +0000)
Give vcc_StringVal() a return value to say if it did anything so we can
emit better error messages when confused.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1662 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/lib/libvcl/Makefile.am
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_string.c [new file with mode: 0644]
varnish-cache/lib/libvcl/vcc_var.c

index 9a8a4d7ab37bdb444a9f4cf4b712ae164c36fd37..4c0a42572b1761608e7a6d7db24be2b43b1b0300 100644 (file)
@@ -16,6 +16,7 @@ libvcl_la_SOURCES = \
        vcc_parse.c \
        vcc_fixed_token.c \
        vcc_obj.c \
+       vcc_string.c \
        vcc_token.c \
        vcc_var.c \
        vcc_xref.c
index 9084b30eb472031c686aeb76c53c0f95741b1a18..5e5d8e90b995014c6621601f90c19b34199e3605 100644 (file)
@@ -200,7 +200,11 @@ parse_set(struct tokenlist *tl)
        case HASH:
                ExpectErr(tl, T_INCR);
                vcc_NextToken(tl);
-               vcc_StringVal(tl);
+               if (!vcc_StringVal(tl)) {
+                       ERRCHK(tl);
+                       vcc_ExpectedStringval(tl);
+                       return;
+               }
                Fb(tl, 0, ");\n");
                break;
        case STRING:
@@ -209,12 +213,22 @@ parse_set(struct tokenlist *tl)
                        return;
                }
                vcc_NextToken(tl);
-               vcc_StringVal(tl);
-               while (tl->t->tok != ';') {
+               if (!vcc_StringVal(tl)) {
+                       ERRCHK(tl);
+                       vcc_ExpectedStringval(tl);
+                       return;
+               }
+               do 
                        Fb(tl, 0, ", ");
-                       vcc_StringVal(tl);
+               while (vcc_StringVal(tl));
+               if (tl->t->tok != ';') {
+                       ERRCHK(tl);
+                       vsb_printf(tl->sb,
+                           "Expected variable, string or semicolon\n");
+                       vcc_ErrWhere(tl, tl->t);
+                       return;
                }
-               Fb(tl, 0, "0);\n");
+               Fb(tl, 0, "0);\n");
                break;
        default:
                vsb_printf(tl->sb,
index 762dd4b61ffa1ad2ea18d65f78ce6e3fcd76e9f9..bd7d64253735e8cc7b4fdea8c2d39dc90cc82527 100644 (file)
@@ -167,6 +167,10 @@ void vcc_SizeVal(struct tokenlist *tl);
 unsigned vcc_UintVal(struct tokenlist *tl);
 double vcc_DoubleVal(struct tokenlist *tl);
 
+/* vcc_string.c */
+int vcc_StringVal(struct tokenlist *tl);
+void vcc_ExpectedStringval(struct tokenlist *tl);
+
 /* vcc_token.c */
 void vcc_ErrToken(const struct tokenlist *tl, const struct token *t);
 void vcc_ErrWhere(struct tokenlist *tl, const struct token *t);
@@ -180,7 +184,6 @@ void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char
 void vcc_FreeToken(struct token *t);
 
 /* vcc_var.c */
-void vcc_StringVal(struct tokenlist *tl);
 struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl);
 
 /* vcc_xref.c */
diff --git a/varnish-cache/lib/libvcl/vcc_string.c b/varnish-cache/lib/libvcl/vcc_string.c
new file mode 100644 (file)
index 0000000..bc89143
--- /dev/null
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2007 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "vsb.h"
+
+#include "vcc_priv.h"
+#include "vcc_compile.h"
+#include "libvarnish.h"
+
+/*--------------------------------------------------------------------
+ * Parse a string value and emit something that results in a usable
+ * "const char *".
+ * There are three possible outcomes:
+ *     tl->err != 0 means something bad happened and a message is emitted.
+ *     return (0) means "could not use this token"
+ *     return (1) means "done"
+ */
+
+int
+vcc_StringVal(struct tokenlist *tl) 
+{
+       struct var *vp;
+
+       if (tl->t->tok == CSTR) {
+               EncToken(tl->fb, tl->t);
+               vcc_NextToken(tl);
+               return (1);
+       }
+       if (tl->t->tok == VAR) {
+               vp = vcc_FindVar(tl, tl->t, vcc_vars);
+               if (tl->err)
+                       return (0);
+               assert(vp != NULL);
+               switch (vp->fmt) {
+               case STRING:
+                       Fb(tl, 0, "%s", vp->rname);
+                       break;
+               default:
+                       vsb_printf(tl->sb,
+                           "String representation of '%s' not implemented yet.\n",
+                               vp->name);
+                       vcc_ErrWhere(tl, tl->t);
+                       return (0);
+               }
+               vcc_NextToken(tl);
+               return (1);
+       }
+       return (0);
+}
+
+void
+vcc_ExpectedStringval(struct tokenlist *tl)
+{
+
+       if (!tl->err) {
+               vsb_printf(tl->sb, "Expected string variable or constant\n");
+               vcc_ErrWhere(tl, tl->t);
+       }
+}
index 53a549a4ea25c973d1b14166587992ce21248784..33cf04e8573e6fb706d6aaf2997629dc7690aacf 100644 (file)
 
 /*--------------------------------------------------------------------*/
 
-void
-vcc_StringVal(struct tokenlist *tl) 
-{
-       struct var *vp;
-
-       if (tl->t->tok == CSTR) {
-               EncToken(tl->fb, tl->t);
-               vcc_NextToken(tl);
-               return;
-       } else if (tl->t->tok != VAR) {
-               vsb_printf(tl->sb, "Expected string variable or constant\n");
-               vcc_ErrWhere(tl, tl->t);
-               return;
-       }
-       ERRCHK(tl);
-       vp = vcc_FindVar(tl, tl->t, vcc_vars);
-       ERRCHK(tl);
-       assert(vp != NULL);
-       switch (vp->fmt) {
-       case STRING:
-               Fb(tl, 0, "%s", vp->rname);
-               break;
-       default:
-               vsb_printf(tl->sb,
-                   "String representation of '%s' not implemented yet.\n",
-                       vp->name);
-               vcc_ErrWhere(tl, tl->t);
-               return;
-       }
-       vcc_NextToken(tl);
-}
-
-/*--------------------------------------------------------------------*/
-
 static struct var *
 HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
 {