From a9bf621b288ef47b3b461adefbd0ef006ebc74d5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 25 Jun 2016 03:06:59 +0200 Subject: debug: move debug functions to separated file --- src/blogc.c | 3 +- src/debug.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/debug.h | 16 ++++++++++ src/template-parser.c | 65 ---------------------------------------- src/template-parser.h | 3 +- 5 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 src/debug.c create mode 100644 src/debug.h (limited to 'src') diff --git a/src/blogc.c b/src/blogc.c index 10f341f..40a5918 100644 --- a/src/blogc.c +++ b/src/blogc.c @@ -24,6 +24,7 @@ #include #include +#include "debug.h" #include "source-parser.h" #include "template-parser.h" #include "loader.h" @@ -252,7 +253,7 @@ main(int argc, char **argv) } if (debug) - blogc_template_debug(l); + blogc_debug_template(l); char *out = blogc_render(l, s, config, listing); diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..767e1a5 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,82 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2015-2016 Rafael G. Martins + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include + +#include "template-parser.h" +#include "utils.h" + +#include "debug.h" + + +static const char* +get_operator(blogc_template_stmt_operator_t op) +{ + if (op & BLOGC_TEMPLATE_OP_NEQ) + return "!="; + if (op & BLOGC_TEMPLATE_OP_EQ) { + if (op & BLOGC_TEMPLATE_OP_LT) + return "<="; + else if (op & BLOGC_TEMPLATE_OP_GT) + return ">="; + return "=="; + } + if (op & BLOGC_TEMPLATE_OP_LT) + return "<"; + else if (op & BLOGC_TEMPLATE_OP_GT) + return ">"; + return ""; +} + + +void +blogc_debug_template(sb_slist_t *stmts) +{ + for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { + blogc_template_stmt_t *data = tmp->data; + fprintf(stderr, "DEBUG: