Commit da3ee836 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

More whitespace and string-casting magic.

Remove some debugging that snug into last commit



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5136 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ce61dd91
...@@ -439,7 +439,6 @@ static void ...@@ -439,7 +439,6 @@ static void
vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname) vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname)
{ {
struct token *t_field; struct token *t_field;
struct token *t_first;
struct token *t_host = NULL; struct token *t_host = NULL;
struct token *t_port = NULL; struct token *t_port = NULL;
struct token *t_hosthdr = NULL; struct token *t_hosthdr = NULL;
...@@ -462,7 +461,6 @@ vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname) ...@@ -462,7 +461,6 @@ vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname)
"?max_connections", "?max_connections",
"?saintmode_threshold", "?saintmode_threshold",
NULL); NULL);
t_first = tl->t;
SkipToken(tl, '{'); SkipToken(tl, '{');
......
...@@ -225,7 +225,6 @@ vcc_delete_expr(struct expr *e) ...@@ -225,7 +225,6 @@ vcc_delete_expr(struct expr *e)
vsb_delete(e->vsb); vsb_delete(e->vsb);
FREE_OBJ(e); FREE_OBJ(e);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* We want to get the indentation right in the emitted C code so we have * We want to get the indentation right in the emitted C code so we have
* to represent it symbolically until we are ready to render. * to represent it symbolically until we are ready to render.
...@@ -247,40 +246,12 @@ vcc_delete_expr(struct expr *e) ...@@ -247,40 +246,12 @@ vcc_delete_expr(struct expr *e)
* XXX: check line lengths in edit, should pass indent in for this * XXX: check line lengths in edit, should pass indent in for this
*/ */
static void
vcc_show(const char *p)
{
fprintf(stderr, "<");
for (; *p; p++) {
if (*p == '\n')
fprintf(stderr, "\\n");
else if (*p == '\v')
fprintf(stderr, "\\v");
else
fprintf(stderr, "%c", *p);
}
fprintf(stderr, ">\n");
}
static struct expr * static struct expr *
vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2) vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2)
{ {
struct expr *e; struct expr *e;
int nl = 1; int nl = 1;
fprintf(stderr, "EDIT:");
vcc_show(p);
if (e1 != NULL) {
fprintf(stderr, "E1:");
vcc_show(vsb_data(e1->vsb));
}
if (e2 != NULL) {
fprintf(stderr, "E2:");
vcc_show(vsb_data(e2->vsb));
}
e = vcc_new_expr(); e = vcc_new_expr();
while (*p != '\0') { while (*p != '\0') {
if (*p == '\n') { if (*p == '\n') {
...@@ -320,8 +291,6 @@ vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2 ...@@ -320,8 +291,6 @@ vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2
vcc_delete_expr(e1); vcc_delete_expr(e1);
vcc_delete_expr(e2); vcc_delete_expr(e2);
e->fmt = fmt; e->fmt = fmt;
fprintf(stderr, "RESULT:");
vcc_show(vsb_data(e->vsb));
return (e); return (e);
} }
...@@ -337,17 +306,20 @@ vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1) ...@@ -337,17 +306,20 @@ vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1)
for (i = 0; i < ind; i++) for (i = 0; i < ind; i++)
vsb_cat(d, " "); vsb_cat(d, " ");
for (p = vsb_data(e1->vsb); *p != '\0'; p++) { p = vsb_data(e1->vsb);
while (*p != '\0') {
if (*p == '\n') { if (*p == '\n') {
vsb_putc(d, '\n'); vsb_putc(d, '\n');
if (p[1] != '\0') { if (p[1] != '\0') {
for (i = 0; i < ind; i++) for (i = 0; i < ind; i++)
vsb_cat(d, " "); vsb_cat(d, " ");
} }
p++;
continue; continue;
} }
if (*p != '\v') { if (*p != '\v') {
vsb_putc(d, *p); vsb_putc(d, *p);
p++;
continue; continue;
} }
p++; p++;
...@@ -357,9 +329,34 @@ vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1) ...@@ -357,9 +329,34 @@ vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1)
default: default:
assert(__LINE__ == 0); assert(__LINE__ == 0);
} }
p++;
} }
} }
/*--------------------------------------------------------------------
*/
static void
vcc_expr_tostring(struct expr **e, enum var_type fmt)
{
const char *p;
AN(fmt == STRING || fmt == STRING_LIST);
p = NULL;
switch((*e)->fmt) {
case BACKEND: p = "VRT_backend_string(sp, \v1)"; break;
case INT: p = "VRT_int_string(sp, \v1)"; break;
case IP: p = "VRT_IP_string(sp, \v1)"; break;
case TIME: p = "VRT_time_string(sp, \v1)"; break;
case DURATION: p = "VRT_double_string(sp, \v1)"; break;
/* XXX: should have "s" suffix ? */
default: break;
}
if (p != NULL)
*e = vcc_expr_edit(fmt, p, *e, NULL);
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
*/ */
...@@ -391,14 +388,14 @@ hack_regsub(struct vcc *tl, struct expr **e, int all) ...@@ -391,14 +388,14 @@ hack_regsub(struct vcc *tl, struct expr **e, int all)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* SYNTAX: * SYNTAX:
* Expr5: * Expr4:
* '(' Expr0 ')' * '(' Expr0 ')'
* CNUM * CNUM
* CSTR * CSTR
*/ */
static void static void
vcc_expr5(struct vcc *tl, struct expr **e, enum var_type fmt) vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
{ {
struct expr *e1, *e2; struct expr *e1, *e2;
const struct symbol *sym; const struct symbol *sym;
...@@ -501,34 +498,6 @@ vcc_expr5(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -501,34 +498,6 @@ vcc_expr5(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = e1; *e = e1;
} }
/*--------------------------------------------------------------------
*/
static void
vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
{
const char *p;
*e = NULL;
vcc_expr5(tl, e, fmt);
ERRCHK(tl);
if (fmt == STRING || fmt == STRING_LIST) {
p = NULL;
switch((*e)->fmt) {
case BACKEND: p = "VRT_backend_string(sp, \v1)"; break;
case INT: p = "VRT_int_string(sp, \v1)"; break;
case IP: p = "VRT_IP_string(sp, \v1)"; break;
case TIME: p = "VRT_time_string(sp, \v1)"; break;
case DURATION: p = "VRT_double_string(sp, \v1)"; break;
/* XXX: should have "s" suffix ? */
default: break;
}
if (p != NULL) {
*e = vcc_expr_edit(fmt, p, *e, NULL);
return;
}
}
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* SYNTAX: * SYNTAX:
* Expr3: * Expr3:
...@@ -577,6 +546,7 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -577,6 +546,7 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
{ {
struct expr *e2; struct expr *e2;
enum var_type f2; enum var_type f2;
struct token *tk;
*e = NULL; *e = NULL;
vcc_expr_mul(tl, e, fmt); vcc_expr_mul(tl, e, fmt);
...@@ -584,11 +554,13 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -584,11 +554,13 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
f2 = (*e)->fmt; f2 = (*e)->fmt;
if (fmt == STRING_LIST && f2 == STRING) { if (fmt == STRING_LIST && f2 == STRING) {
if (f2 == STRING) (*e)->fmt = STRING_LIST;
(*e)->fmt = STRING_LIST;
while (tl->t->tok == '+') { while (tl->t->tok == '+') {
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_expr_mul(tl, &e2, STRING); vcc_expr_mul(tl, &e2, STRING);
if (e2->fmt != STRING && e2->fmt != STRING_LIST)
vcc_expr_tostring(&e2, f2);
assert(e2->fmt == STRING || e2->fmt == STRING_LIST);
*e = vcc_expr_edit(STRING_LIST, "\v1,\n\v2", *e, e2); *e = vcc_expr_edit(STRING_LIST, "\v1,\n\v2", *e, e2);
} }
return; return;
...@@ -599,7 +571,10 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -599,7 +571,10 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
while (tl->t->tok == '+') { while (tl->t->tok == '+') {
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_expr_mul(tl, &e2, STRING); vcc_expr_mul(tl, &e2, STRING);
assert(e2->fmt == STRING); if (e2->fmt != STRING && e2->fmt != STRING_LIST)
vcc_expr_tostring(&e2, f2);
assert(e2->fmt == STRING || e2->fmt == STRING_LIST);
*e = vcc_expr_edit(STRING, "\v1,\n\v2", *e, e2); *e = vcc_expr_edit(STRING, "\v1,\n\v2", *e, e2);
} }
*e = vcc_expr_edit(STRING, "\v1, vrt_magic_string_end)", *e = vcc_expr_edit(STRING, "\v1, vrt_magic_string_end)",
...@@ -616,11 +591,12 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -616,11 +591,12 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
} }
while (tl->t->tok == '+' || tl->t->tok == '-') { while (tl->t->tok == '+' || tl->t->tok == '-') {
tk = tl->t;
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_expr_mul(tl, &e2, f2); vcc_expr_mul(tl, &e2, f2);
assert(e2->fmt == f2); assert(e2->fmt == f2);
ERRCHK(tl); ERRCHK(tl);
if (tl->t->tok == '+') if (tk->tok == '+')
*e = vcc_expr_edit(f2, "(\v1+\v2)", *e, e2); *e = vcc_expr_edit(f2, "(\v1+\v2)", *e, e2);
else else
*e = vcc_expr_edit(f2, "(\v1-\v2)", *e, e2); *e = vcc_expr_edit(f2, "(\v1-\v2)", *e, e2);
...@@ -756,12 +732,6 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -756,12 +732,6 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, enum var_type fmt)
break; break;
} }
} }
if (fmt == VOID || fmt != (*e)->fmt) {
vsb_printf(tl->sb, "WANT: %s has %s next %.*s (%s)\n",
vcc_Type(fmt), vcc_Type((*e)->fmt),
PF(tl->t), vsb_data((*e)->vsb));
tl->err = 1;
}
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -804,14 +774,18 @@ vcc_expr0(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -804,14 +774,18 @@ vcc_expr0(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = NULL; *e = NULL;
vcc_expr_cand(tl, e, fmt); vcc_expr_cand(tl, e, fmt);
ERRCHK(tl); ERRCHK(tl);
if ((*e)->fmt != BOOL) if (fmt == STRING || fmt == STRING_LIST)
vcc_expr_tostring(e, fmt);
if ((*e)->fmt != BOOL || tl->t->tok != T_COR)
return; return;
*e = vcc_expr_edit(BOOL, "(\v+\n\v1", *e, NULL);
while (tl->t->tok == T_COR) { while (tl->t->tok == T_COR) {
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_expr_cand(tl, &e2, fmt); vcc_expr_cand(tl, &e2, fmt);
ERRCHK(tl); ERRCHK(tl);
*e = vcc_expr_edit(BOOL, "(\v1||\v2)", *e, e2); *e = vcc_expr_edit(BOOL, "\v1\v-\n||\v+\n\v2", *e, e2);
} }
*e = vcc_expr_edit(BOOL, "\v1\v-\n)", *e, NULL);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
* $Id$ * $Id$
*/ */
/*lint -save -e525 -e539 */
VCC_TYPE(VOID) VCC_TYPE(VOID)
VCC_TYPE(BACKEND) VCC_TYPE(BACKEND)
VCC_TYPE(BOOL) VCC_TYPE(BOOL)
...@@ -39,3 +40,4 @@ VCC_TYPE(STRING_LIST) ...@@ -39,3 +40,4 @@ VCC_TYPE(STRING_LIST)
VCC_TYPE(IP) VCC_TYPE(IP)
VCC_TYPE(HEADER) VCC_TYPE(HEADER)
VCC_TYPE(REAL) VCC_TYPE(REAL)
/*lint -restore */
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