} \
} while(0)
+#define DEBUG_DUMP_EVAL(ctx, node) do { \
+ char c = '"'; \
+ switch ((node)->token.type) { \
+ case TOKEN_STRING: \
+ debug_printf((ctx), " Evaluate: %s (%s) -> %c\n", (node)->token.s,\
+ (node)->token.value, ((node)->value) ? '1':'0'); \
+ break; \
+ case TOKEN_AND: \
+ case TOKEN_OR: \
+ debug_printf((ctx), " Evaluate: %s (Left: %s; Right: %s) -> %c\n",\
+ (node)->token.s, \
+ (((node)->left->done) ? ((node)->left->value ?"1":"0") \
+ : "short circuited"), \
+ (((node)->right->done) ? ((node)->right->value?"1":"0") \
+ : "short circuited"), \
+ (node)->value ? '1' : '0'); \
+ break; \
+ case TOKEN_EQ: \
+ case TOKEN_NE: \
+ case TOKEN_GT: \
+ case TOKEN_GE: \
+ case TOKEN_LT: \
+ case TOKEN_LE: \
+ if ((node)->right->token.type == TOKEN_RE) c = '/'; \
+ debug_printf((ctx), " Compare: %s (\"%s\" with %c%s%c) -> %c\n", \
+ (node)->token.s, \
+ (node)->left->token.value, \
+ c, (node)->right->token.value, c, \
+ (node)->value ? '1' : '0'); \
+ break; \
+ default: \
+ debug_printf((ctx), " Evaluate: %s -> %c\n", (node)->token.s, \
+ (node)->value ? '1' : '0'); \
+ break; \
+ } \
+} while(0)
+
#define DEBUG_DUMP_UNMATCHED(ctx, unmatched) do { \
if (unmatched) { \
DEBUG_PRINTF(((ctx), " Unmatched %c\n", (char)(unmatched))); \
#define DEBUG_INIT(ctx, f, bb)
#define DEBUG_PRINTF(arg)
#define DEBUG_DUMP_TOKEN(ctx, token)
+#define DEBUG_DUMP_EVAL(ctx, node)
#define DEBUG_DUMP_UNMATCHED(ctx, unmatched)
#define DEBUG_DUMP_COND(ctx, text)
#define DEBUG_DUMP_TREE(ctx, root)
/* Create Parse Tree */
while (1) {
- DEBUG_DUMP_TREE(ctx, root);
+ /* uncomment this to see how the tree a built:
+ *
+ * DEBUG_DUMP_TREE(ctx, root);
+ */
CREATE_NODE(ctx, new);
was_unmatched = get_ptoken(ctx->dpool, &parse, &new->token);
}
}
+ DEBUG_DUMP_TREE(ctx, root);
+
/* Evaluate Parse Tree */
current = root;
while (current) {
switch (current->token.type) {
case TOKEN_STRING:
- DEBUG_PRINTF((ctx, " Evaluate %s\n", current->token.s));
-
buffer = ap_ssi_parse_string(ctx, current->token.value, NULL, 0,
SSI_EXPAND_DROP_NAME);
current->token.value = buffer;
current->value = !!*current->token.value;
+ DEBUG_DUMP_EVAL(ctx, current);
current->done = 1;
current = current->parent;
break;
case TOKEN_AND:
case TOKEN_OR:
- DEBUG_PRINTF((ctx, " Evaluate %s\n", current->token.s));
-
if (!current->left || !current->right) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"Invalid expression \"%s\" in file %s",
if (!current->left->done && !regex &&
((current->token.type == TOKEN_AND && !current->right->value) ||
(current->token.type == TOKEN_OR && current->right->value))) {
- DEBUG_PRINTF((ctx, " Left: short circuited\n"));
- DEBUG_PRINTF((ctx, " Right: %c\n", current->right->value
- ? '1' : '0'));
-
current->value = current->right->value;
}
else {
}
}
- DEBUG_PRINTF((ctx, " Left: %c\n", current->left->value
- ? '1' : '0'));
- DEBUG_PRINTF((ctx, " Right: %c\n", current->right->value
- ? '1' : '0'));
-
if (current->token.type == TOKEN_AND) {
current->value = current->left->value &&
current->right->value;
}
}
- DEBUG_PRINTF((ctx, " Returning %c\n", current->value
- ? '1' : '0'));
+ DEBUG_DUMP_EVAL(ctx, current);
current->done = 1;
current = current->parent;
break;
case TOKEN_EQ:
case TOKEN_NE:
- DEBUG_PRINTF((ctx, " Evaluate %s\n", current->token.s));
-
if (!current->left || !current->right ||
current->left->token.type != TOKEN_STRING ||
(current->right->token.type != TOKEN_STRING &&
current->right->token.value = buffer;
if (current->right->token.type == TOKEN_RE) {
- DEBUG_PRINTF((ctx, " Re Compare (%s) with /%s/\n",
- current->left->token.value,
- current->right->token.value));
-
current->value = re_check(ctx, current->left->token.value,
current->right->token.value);
--regex;
}
else {
- DEBUG_PRINTF((ctx, " Compare (%s) with (%s)\n",
- current->left->token.value,
- current->right->token.value));
-
current->value = !strcmp(current->left->token.value,
current->right->token.value);
}
current->value = !current->value;
}
- DEBUG_PRINTF((ctx, " Returning %c\n", current->value
- ? '1' : '0'));
-
+ DEBUG_DUMP_EVAL(ctx, current);
current->done = 1;
current = current->parent;
break;
case TOKEN_GT:
case TOKEN_LE:
case TOKEN_LT:
- DEBUG_PRINTF((ctx, " Evaluate %s\n", current->token.s));
-
if (!current->left || !current->right ||
current->left->token.type != TOKEN_STRING ||
current->right->token.type != TOKEN_STRING) {
0, SSI_EXPAND_DROP_NAME);
current->right->token.value = buffer;
- DEBUG_PRINTF((ctx, " Compare (%s) with (%s)\n",
- current->left->token.value,
- current->right->token.value));
-
current->value = strcmp(current->left->token.value,
current->right->token.value);
current->value = 0; /* Don't return -1 if unknown token */
}
- DEBUG_PRINTF((ctx, " Returning %c\n", current->value
- ? '1' : '0'));
-
+ DEBUG_DUMP_EVAL(ctx, current);
current->done = 1;
current = current->parent;
break;
current->value = 0;
}
- DEBUG_PRINTF((ctx, " Evaluate %s: %c\n", current->token.s,
- current->value ? '1' : '0'));
-
+ DEBUG_DUMP_EVAL(ctx, current);
current->done = 1;
current = current->parent;
break;
current->value = 1;
}
- DEBUG_PRINTF((ctx, " Evaluate %s: %c\n", current->token.s,
- current->value ? '1' : '0'));
-
+ DEBUG_DUMP_EVAL(ctx, current);
current->done = 1;
current = current->parent;
break;