aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/blogc.1.ronn9
-rw-r--r--src/blogc.c12
-rw-r--r--src/template-parser.c65
-rw-r--r--src/template-parser.h1
4 files changed, 82 insertions, 5 deletions
diff --git a/man/blogc.1.ronn b/man/blogc.1.ronn
index baee026..c3db7f4 100644
--- a/man/blogc.1.ronn
+++ b/man/blogc.1.ronn
@@ -3,9 +3,9 @@ blogc(1) -- a blog compiler
## SYNOPSIS
-`blogc` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE><br>
-`blogc` `-l` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br>
-`blogc` `-l` `-p` <KEY> [`-D` <KEY>=<VALUE> ...] [<SOURCE> ...]<br>
+`blogc` `-d` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE><br>
+`blogc` `-d` `-l` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br>
+`blogc` `-d` `-l` `-p` <KEY> [`-D` <KEY>=<VALUE> ...] [<SOURCE> ...]<br>
`blogc` [`-h`|`-v`]
## DESCRIPTION
@@ -30,6 +30,9 @@ designed to be used with make(1).
## OPTIONS
+ * `-d`:
+ Activates debug.
+
* `-l`:
Activates listing mode, allowing user to provide multiple source files. See
blogc-source(7) for details.
diff --git a/src/blogc.c b/src/blogc.c
index cdc6aeb..10f341f 100644
--- a/src/blogc.c
+++ b/src/blogc.c
@@ -41,7 +41,7 @@ blogc_print_help(void)
{
printf(
"usage:\n"
- " blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n"
+ " blogc [-h] [-v] [-d] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n"
" [-o OUTPUT] [SOURCE ...] - A blog compiler.\n"
"\n"
"positional arguments:\n"
@@ -50,6 +50,7 @@ blogc_print_help(void)
"optional arguments:\n"
" -h show this help message and exit\n"
" -v show version and exit\n"
+ " -d enable debug\n"
" -l build listing page, from multiple source files\n"
" -D KEY=VALUE set global configuration parameter\n"
" -p KEY show the value of a global configuration parameter\n"
@@ -63,7 +64,7 @@ static void
blogc_print_usage(void)
{
printf(
- "usage: blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n"
+ "usage: blogc [-h] [-v] [-d] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n"
" [-o OUTPUT] [SOURCE ...]\n");
}
@@ -110,6 +111,7 @@ main(int argc, char **argv)
int rv = 0;
+ bool debug = false;
bool listing = false;
char *template = NULL;
char *output = NULL;
@@ -131,6 +133,9 @@ main(int argc, char **argv)
case 'v':
printf("%s\n", PACKAGE_STRING);
goto cleanup;
+ case 'd':
+ debug = true;
+ break;
case 'l':
listing = true;
break;
@@ -246,6 +251,9 @@ main(int argc, char **argv)
goto cleanup3;
}
+ if (debug)
+ blogc_template_debug(l);
+
char *out = blogc_render(l, s, config, listing);
bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-")));
diff --git a/src/template-parser.c b/src/template-parser.c
index 525f5f5..1582c17 100644
--- a/src/template-parser.c
+++ b/src/template-parser.c
@@ -11,6 +11,7 @@
#endif /* HAVE_CONFIG_H */
#include <stdbool.h>
+#include <stdio.h>
#include <string.h>
#include "template-parser.h"
@@ -634,3 +635,67 @@ 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 a8b4e8b..bd39678 100644
--- a/src/template-parser.h
+++ b/src/template-parser.h
@@ -47,5 +47,6 @@ 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 */