Mercurial > audlegacy
changeset 4381:ce3f2d2455cf
Moved debugging functions to tuple_compiler.c
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Mar 2008 08:49:54 +0200 |
parents | a5382bae0eea |
children | 53ed80a5b205 |
files | src/audacious/tuple_compiler.c src/audacious/tuple_compiler.h src/audacious/tuple_formatter.c |
diffstat | 3 files changed, 108 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/tuple_compiler.c Fri Mar 28 04:41:53 2008 +0200 +++ b/src/audacious/tuple_compiler.c Fri Mar 28 08:49:54 2008 +0200 @@ -829,3 +829,110 @@ return res; } + + +static void print_vars(FILE *f, TupleEvalContext *ctx, TupleEvalNode *node, gint start, gint end) +{ + gint i; + g_return_if_fail(node != NULL); + g_return_if_fail(ctx != NULL); + g_return_if_fail(start >= 0); + g_return_if_fail(start <= end); + g_return_if_fail(end < MAX_VAR); + + for (i = start; i <= end; i++) { + TupleEvalVar *v = NULL; + gchar *s = NULL; + gint n = node->var[i]; + + if (n >= 0) { + v = ctx->variables[n]; + if (v) { + s = v->name; + + if (v->type == VAR_CONST) + fprintf(f, "(const)"); + else if (v->type == VAR_DEF) + fprintf(f, "(def)"); + } + } + + fprintf(f, "var[%d]=(%d),\"%s\" ", i, n, s); + } +} + + +gint tuple_formatter_print(FILE *f, gint *level, TupleEvalContext *ctx, TupleEvalNode *expr) +{ + TupleEvalNode *curr = expr; + + if (!expr) return -1; + + (*level)++; + + while (curr) { + gint i; + for (i = 0; i < *level; i++) + fprintf(f, " "); + + switch (curr->opcode) { + case OP_RAW: + fprintf(f, "OP_RAW text=\"%s\"\n", curr->text); + break; + + case OP_FIELD: + fprintf(f, "OP_FIELD "); + print_vars(f, ctx, curr, 0, 0); + fprintf(f, "\n"); + break; + + case OP_EXISTS: + fprintf(f, "OP_EXISTS "); + print_vars(f, ctx, curr, 0, 0); + fprintf(f, "\n"); + tuple_formatter_print(f, level, ctx, curr->children); + break; + + case OP_DEF_STRING: + fprintf(f, "OP_DEF_STRING "); + fprintf(f, "\n"); + break; + + case OP_DEF_INT: + fprintf(f, "OP_DEF_INT "); + fprintf(f, "\n"); + break; + + case OP_EQUALS: + fprintf(f, "OP_EQUALS "); + print_vars(f, ctx, curr, 0, 1); + fprintf(f, "\n"); + tuple_formatter_print(f, level, ctx, curr->children); + break; + + case OP_NOT_EQUALS: + fprintf(f, "OP_NOT_EQUALS "); + print_vars(f, ctx, curr, 0, 1); + fprintf(f, "\n"); + tuple_formatter_print(f, level, ctx, curr->children); + break; + + case OP_IS_EMPTY: + fprintf(f, "OP_IS_EMPTY "); + print_vars(f, ctx, curr, 0, 0); + fprintf(f, "\n"); + tuple_formatter_print(f, level, ctx, curr->children); + break; + + default: + fprintf(f, "Unimplemented opcode %d!\n", curr->opcode); + break; + } + + curr = curr->next; + } + + (*level)--; + + return 0; +}
--- a/src/audacious/tuple_compiler.h Fri Mar 28 04:41:53 2008 +0200 +++ b/src/audacious/tuple_compiler.h Fri Mar 28 08:49:54 2008 +0200 @@ -104,6 +104,7 @@ void tuple_evalnode_free(TupleEvalNode *expr); +gint tuple_formatter_print(FILE *f, gint *level, TupleEvalContext *ctx, TupleEvalNode *expr); TupleEvalNode *tuple_formatter_compile(TupleEvalContext *ctx, gchar *expr); gchar *tuple_formatter_eval(TupleEvalContext *ctx, TupleEvalNode *expr, Tuple *tuple);
--- a/src/audacious/tuple_formatter.c Fri Mar 28 04:41:53 2008 +0200 +++ b/src/audacious/tuple_formatter.c Fri Mar 28 08:49:54 2008 +0200 @@ -613,114 +613,3 @@ return rv; } - -#ifdef TUPLE_COMPILER_DEBUG -static void print_vars(FILE *f, TupleEvalContext *ctx, TupleEvalNode *node, gint start, gint end) -{ - gint i; - g_return_if_fail(node != NULL); - g_return_if_fail(ctx != NULL); - g_return_if_fail(start >= 0); - g_return_if_fail(start <= end); - g_return_if_fail(end < MAX_VAR); - - for (i = start; i <= end; i++) { - TupleEvalVar *v = NULL; - gchar *s = NULL; - gint n = node->var[i]; - - if (n >= 0) { - v = ctx->variables[n]; - if (v) { - s = v->name; - - if (v->type == VAR_CONST) - fprintf(f, "(const)"); - else if (v->type == VAR_DEF) - fprintf(f, "(def)"); - } - } - - fprintf(f, "var[%d]=(%d),\"%s\" ", i, n, s); - } -} - -gint tuple_formatter_print(FILE *f, gint *level, TupleEvalContext *ctx, TupleEvalNode *expr) -{ - TupleEvalNode *curr = expr; - - if (!expr) return -1; - - (*level)++; - - /* Evaluate tuple in given TupleEval expression in given - * context and return resulting string. - */ - while (curr) { - gint i; - for (i = 0; i < *level; i++) - fprintf(f, " "); - - switch (curr->opcode) { - case OP_RAW: - fprintf(f, "OP_RAW text=\"%s\"\n", curr->text); - break; - - case OP_FIELD: - fprintf(f, "OP_FIELD "); - print_vars(f, ctx, curr, 0, 0); - fprintf(f, "\n"); - break; - - case OP_EXISTS: - fprintf(f, "OP_EXISTS "); - print_vars(f, ctx, curr, 0, 0); - fprintf(f, "\n"); - tuple_formatter_print(f, level, ctx, curr->children); - break; - - case OP_DEF_STRING: - fprintf(f, "OP_DEF_STRING "); - fprintf(f, "\n"); - break; - - case OP_DEF_INT: - fprintf(f, "OP_DEF_INT "); - fprintf(f, "\n"); - break; - - case OP_EQUALS: - fprintf(f, "OP_EQUALS "); - print_vars(f, ctx, curr, 0, 1); - fprintf(f, "\n"); - tuple_formatter_print(f, level, ctx, curr->children); - break; - - case OP_NOT_EQUALS: - fprintf(f, "OP_NOT_EQUALS "); - print_vars(f, ctx, curr, 0, 1); - fprintf(f, "\n"); - tuple_formatter_print(f, level, ctx, curr->children); - break; - - case OP_IS_EMPTY: - fprintf(f, "OP_IS_EMPTY "); - print_vars(f, ctx, curr, 0, 0); - fprintf(f, "\n"); - tuple_formatter_print(f, level, ctx, curr->children); - break; - - default: - fprintf(f, "Unimplemented opcode %d!\n", curr->opcode); - break; - } - - curr = curr->next; - } - - (*level)--; - - return 0; -} - -#endif