diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc.c | 3 | ||||
-rw-r--r-- | src/debug.c | 82 | ||||
-rw-r--r-- | src/debug.h | 16 | ||||
-rw-r--r-- | src/template-parser.c | 65 | ||||
-rw-r--r-- | src/template-parser.h | 3 |
5 files changed, 101 insertions, 68 deletions
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 <stdio.h> #include <string.h> +#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 <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + +#include <stdio.h> + +#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: <TEMPLATE "); + switch (data->type) { + case BLOGC_TEMPLATE_IFDEF_STMT: + fprintf(stderr, "IFDEF: %s", data->value); + break; + case BLOGC_TEMPLATE_IFNDEF_STMT: + fprintf(stderr, "IFNDEF: %s", data->value); + break; + case BLOGC_TEMPLATE_IF_STMT: + fprintf(stderr, "IF: %s %s %s", data->value, + get_operator(data->op), data->value2); + break; + case BLOGC_TEMPLATE_ENDIF_STMT: + fprintf(stderr, "ENDIF"); + break; + case BLOGC_TEMPLATE_FOREACH_STMT: + fprintf(stderr, "FOREACH: %s", data->value); + break; + case BLOGC_TEMPLATE_ENDFOREACH_STMT: + fprintf(stderr, "ENDFOREACH"); + break; + case BLOGC_TEMPLATE_BLOCK_STMT: + fprintf(stderr, "BLOCK: %s", data->value); + break; + case BLOGC_TEMPLATE_ENDBLOCK_STMT: + fprintf(stderr, "ENDBLOCK"); + break; + case BLOGC_TEMPLATE_VARIABLE_STMT: + fprintf(stderr, "VARIABLE: %s", data->value); + break; + case BLOGC_TEMPLATE_CONTENT_STMT: + fprintf(stderr, "CONTENT: `%s`", data->value); + break; + } + fprintf(stderr, ">\n"); + } +} diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..cd454d4 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,16 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifndef ___DEBUG_H +#define ___DEBUG_H + +#include "utils.h" + +void blogc_debug_template(sb_slist_t *stmts); + +#endif /* ___DEBUG_H */ diff --git a/src/template-parser.c b/src/template-parser.c index 1582c17..525f5f5 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -11,7 +11,6 @@ #endif /* HAVE_CONFIG_H */ #include <stdbool.h> -#include <stdio.h> #include <string.h> #include "template-parser.h" @@ -635,67 +634,3 @@ blogc_template_free_stmts(sb_slist_t *stmts) } sb_slist_free(stmts); } - - -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_template_debug(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: <TEMPLATE "); - switch (data->type) { - case BLOGC_TEMPLATE_IFDEF_STMT: - fprintf(stderr, "IFDEF: %s", data->value); - break; - case BLOGC_TEMPLATE_IFNDEF_STMT: - fprintf(stderr, "IFNDEF: %s", data->value); - break; - case BLOGC_TEMPLATE_IF_STMT: - fprintf(stderr, "IF: %s %s %s", data->value, - get_operator(data->op), data->value2); - break; - case BLOGC_TEMPLATE_ENDIF_STMT: - fprintf(stderr, "ENDIF"); - break; - case BLOGC_TEMPLATE_FOREACH_STMT: - fprintf(stderr, "FOREACH: %s", data->value); - break; - case BLOGC_TEMPLATE_ENDFOREACH_STMT: - fprintf(stderr, "ENDFOREACH"); - break; - case BLOGC_TEMPLATE_BLOCK_STMT: - fprintf(stderr, "BLOCK: %s", data->value); - break; - case BLOGC_TEMPLATE_ENDBLOCK_STMT: - fprintf(stderr, "ENDBLOCK"); - break; - case BLOGC_TEMPLATE_VARIABLE_STMT: - fprintf(stderr, "VARIABLE: %s", data->value); - break; - case BLOGC_TEMPLATE_CONTENT_STMT: - fprintf(stderr, "CONTENT: `%s`", data->value); - break; - } - fprintf(stderr, ">\n"); - } -} diff --git a/src/template-parser.h b/src/template-parser.h index bd39678..46223ec 100644 --- a/src/template-parser.h +++ b/src/template-parser.h @@ -47,6 +47,5 @@ typedef struct { sb_slist_t* blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err); void blogc_template_free_stmts(sb_slist_t *stmts); -void blogc_template_debug(sb_slist_t *stmts); -#endif /* _TEMPLATE_GRAMMAR_H */ +#endif /* _TEMPLATE_PARSER_H */ |