Mercurial > hg-old > index.cgi
changeset 39:efa19ec69df9
tweaked debugging system for expression handler
author | lost |
---|---|
date | Sat, 03 Jan 2009 19:20:44 +0000 |
parents | 9bd584bb6296 |
children | d2cee0c335e7 |
files | src/expr.c src/lwasm.c |
diffstat | 2 files changed, 18 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/expr.c Sat Jan 03 04:53:49 2009 +0000 +++ b/src/expr.c Sat Jan 03 19:20:44 2009 +0000 @@ -25,13 +25,15 @@ #define __expr_c_seen__ #include <ctype.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> #include "expr.h" #include "util.h" +// this definition is in lwasm.h but we don't need the whole file here +extern void debug_message(int level, const char *fmt, ...); + lwasm_expr_stack_t *lwasm_expr_stack_create(void) { lwasm_expr_stack_t *s; @@ -68,7 +70,7 @@ { lwasm_expr_term_t *t; -fprintf(stderr, "Creating operator term: %d\n", oper); + debug_message(10, "Creating operator term: %d", oper); t = lwasm_alloc(sizeof(lwasm_expr_term_t)); t -> term_type = LWASM_TERM_OPER; @@ -79,7 +81,7 @@ lwasm_expr_term_t *lwasm_expr_term_create_int(int val) { lwasm_expr_term_t *t; -fprintf(stderr, "Creating integer term: %d\n", val); + debug_message(10, "Creating integer term: %d", val); t = lwasm_alloc(sizeof(lwasm_expr_term_t)); t -> term_type = LWASM_TERM_INT; @@ -91,7 +93,8 @@ { lwasm_expr_term_t *t; -fprintf(stderr, "Creating symbol term: %s\n", sym); + debug_message(10, "Creating symbol term: %s", sym); + t = lwasm_alloc(sizeof(lwasm_expr_term_t)); t -> term_type = LWASM_TERM_SYM; t -> symbol = lwasm_strdup(sym); @@ -112,7 +115,7 @@ return lwasm_expr_term_create_sym(t -> symbol); default: - fprintf(stderr, "lwasm_expr_term_dup(): invalid term type %d\n", t -> term_type); + debug_message(0, "lwasm_expr_term_dup(): invalid term type %d", t -> term_type); exit(1); } // can't get here @@ -124,7 +127,7 @@ if (!s) { - fprintf(stderr, "lwasm_expr_stack_push(): invalid stack pointer\n"); + debug_message(0, "lwasm_expr_stack_push(): invalid stack pointer"); exit(1); } @@ -181,11 +184,12 @@ int lwasm_expr_parse_term(lwasm_expr_stack_t *s, const char **p) { lwasm_expr_term_t *t; -fprintf(stderr, "Expression string %s\n", *p); + debug_message(2, "Expression string %s", *p); + eval_next: if (**p == '(') { - fprintf(stderr, "Starting paren\n"); + debug_message(3, "Starting paren"); (*p)++; lwasm_expr_parse_expr(s, p, 0); if (**p != ')') @@ -196,7 +200,7 @@ if (**p == '+') { - fprintf(stderr, "Unary +\n"); + debug_message(3, "Unary +"); (*p)++; goto eval_next; } @@ -430,7 +434,7 @@ { // otherwise we must be decimal (if we're still allowed one) val = decval; - fprintf(stderr, "End of decimal value\n"); + debug_message(3, "End of decimal value"); break; } else @@ -499,7 +503,7 @@ dval -= '0'; if (dval > 9) dval -= 7; - fprintf(stderr, "Got digit: %d\n", dval); + debug_message(3, "Got digit: %d", dval); // if (dval > 1) // valtype &= 14; // if (dval > 7) @@ -666,7 +670,7 @@ goto cleanup_error; if (lwasm_expr_is_constant(s)) - fprintf(stderr, "Constant expression evaluates to: %d\n", lwasm_expr_get_value(s)); + debug_message(3, "Constant expression evaluates to: %d", lwasm_expr_get_value(s)); return s;
--- a/src/lwasm.c Sat Jan 03 04:53:49 2009 +0000 +++ b/src/lwasm.c Sat Jan 03 19:20:44 2009 +0000 @@ -193,7 +193,8 @@ va_start(args, fmt); if (debug_level >= level) { - fprintf(stderr, "DEBUG %d: ", level); + if (level > 0) + fprintf(stderr, "DEBUG %d: ", level); vfprintf(stderr, fmt, args); fputc('\n', stderr); }