Commit 6a9b5a22 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move string stuff to vcc_string.c, there's going to be a fair bit of it.

Give vcc_StringVal() a return value to say if it did anything so we can
emit better error messages when confused.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1662 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 47149f9d
......@@ -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
......
......@@ -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,
......
......@@ -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 */
......
/*-
* 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);
}
}
......@@ -40,40 +40,6 @@
/*--------------------------------------------------------------------*/
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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment