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 --- Makefile.am | 6 ++-- src/blogc.c | 3 +- src/debug.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/debug.h | 16 ++++++++++ src/template-parser.c | 65 ---------------------------------------- src/template-parser.h | 3 +- 6 files changed, 105 insertions(+), 70 deletions(-) create mode 100644 src/debug.c create mode 100644 src/debug.h diff --git a/Makefile.am b/Makefile.am index d3ab12c..75bd927 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,8 +34,9 @@ BUILT_SOURCES = \ noinst_HEADERS = \ src/content-parser.h \ src/datetime-parser.h \ - src/file.h \ + src/debug.h \ src/error.h \ + src/file.h \ src/loader.h \ src/renderer.h \ src/source-parser.h \ @@ -74,8 +75,9 @@ check_PROGRAMS = \ libblogc_la_SOURCES = \ src/content-parser.c \ src/datetime-parser.c \ - src/file.c \ + src/debug.c \ src/error.c \ + src/file.c \ src/loader.c \ src/renderer.c \ src/source-parser.c \ 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: