aboutsummaryrefslogtreecommitdiffstats
path: root/src/renderer.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-05-18 01:35:37 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-05-18 01:35:37 -0300
commit2b6553f1ee3a6975b7511d01826f5807c49c132d (patch)
tree09257aee999552c559e659fd33a7c15120b2cb22 /src/renderer.c
parent64e772c1125acadad8167fd5fd25b380f333ab86 (diff)
downloadblogc-2b6553f1ee3a6975b7511d01826f5807c49c132d.tar.gz
blogc-2b6553f1ee3a6975b7511d01826f5807c49c132d.tar.bz2
blogc-2b6553f1ee3a6975b7511d01826f5807c49c132d.zip
renderer: implemented if statements
Diffstat (limited to 'src/renderer.c')
-rw-r--r--src/renderer.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/renderer.c b/src/renderer.c
index 7a2fb77..314fe04 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -83,13 +83,16 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
const char *config_value = NULL;
const char *config_var = NULL;
char *config_value2 = NULL;
+ char *defined = NULL;
unsigned int if_count = 0;
unsigned int if_skip = 0;
bool if_not = false;
- bool defined = false;
bool inside_block = false;
+ bool evaluate = false;
+
+ int cmp = 0;
b_slist_t *tmp = tmpl;
while (tmp != NULL) {
@@ -187,8 +190,9 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
case BLOGC_TEMPLATE_IFNDEF_STMT:
if_not = true;
+ case BLOGC_TEMPLATE_IF_STMT:
case BLOGC_TEMPLATE_IFDEF_STMT:
- defined = false;
+ defined = NULL;
if (stmt->value != NULL) {
config_var = NULL;
if (0 == strcmp(stmt->value, "DATE_FORMATTED"))
@@ -203,16 +207,35 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
inside_block ? tmp_source : NULL),
config, inside_block ? tmp_source : NULL);
if (config_value2 != NULL) {
- defined = true;
- free(config_value2);
+ defined = config_value2;
config_value2 = NULL;
}
}
else
- defined = blogc_get_variable(stmt->value, config,
- inside_block ? tmp_source : NULL) != NULL;
+ defined = b_strdup(blogc_get_variable(stmt->value,
+ config, inside_block ? tmp_source : NULL));
+ }
+ evaluate = false;
+ if (stmt->op != 0) {
+ if (defined != NULL && stmt->value2 != NULL) {
+ cmp = strcmp(defined, stmt->value2);
+ if (cmp != 0 && stmt->op & BLOGC_TEMPLATE_OP_NEQ)
+ evaluate = true;
+ else if (cmp == 0 && stmt->op & BLOGC_TEMPLATE_OP_EQ)
+ evaluate = true;
+ else if (cmp < 0 && stmt->op & BLOGC_TEMPLATE_OP_LT)
+ evaluate = true;
+ else if (cmp > 0 && stmt->op & BLOGC_TEMPLATE_OP_GT)
+ evaluate = true;
+ }
+ }
+ else {
+ if (if_not && defined == NULL)
+ evaluate = true;
+ if (!if_not && defined != NULL)
+ evaluate = true;
}
- if ((!if_not && !defined) || (if_not && defined)) {
+ if (!evaluate) {
if_skip = if_count;
// at this point we can just skip anything, counting the
@@ -221,7 +244,8 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
while (1) {
tmp = tmp->next;
stmt = tmp->data;
- if ((stmt->type == BLOGC_TEMPLATE_IFDEF_STMT) ||
+ if ((stmt->type == BLOGC_TEMPLATE_IF_STMT) ||
+ (stmt->type == BLOGC_TEMPLATE_IFDEF_STMT) ||
(stmt->type == BLOGC_TEMPLATE_IFNDEF_STMT))
{
if_count++;
@@ -237,6 +261,8 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
}
}
}
+ free(defined);
+ defined = NULL;
if_not = false;
break;