diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc/funcvars.c | 13 | ||||
-rw-r--r-- | src/blogc/funcvars.h | 2 | ||||
-rw-r--r-- | src/blogc/renderer.c | 6 |
3 files changed, 11 insertions, 10 deletions
diff --git a/src/blogc/funcvars.c b/src/blogc/funcvars.c index 25a22bf..42411e2 100644 --- a/src/blogc/funcvars.c +++ b/src/blogc/funcvars.c @@ -43,20 +43,23 @@ static const struct func_map { }; -char* -blogc_funcvars_lookup(const char *name, bc_trie_t *global) +void +blogc_funcvars_eval(bc_trie_t *global, const char *name) { + if (global == NULL || name == NULL) + return; + // protect against evaluating the same function twice in the same global // context if (NULL != bc_trie_lookup(global, name)) - return NULL; + return; for (size_t i = 0; funcs[i].variable != NULL; i++) { if (0 == strcmp(name, funcs[i].variable)) { funcs[i].func(global); - return bc_strdup(bc_trie_lookup(global, name)); + return; } } - return NULL; + return; } diff --git a/src/blogc/funcvars.h b/src/blogc/funcvars.h index f554f8d..aae1bc3 100644 --- a/src/blogc/funcvars.h +++ b/src/blogc/funcvars.h @@ -14,6 +14,6 @@ typedef void (*blogc_funcvars_func_t) (bc_trie_t*); -char* blogc_funcvars_lookup(const char *name, bc_trie_t *global); +void blogc_funcvars_eval(bc_trie_t *global, const char *name); #endif /* ___FUNCVARS_H */ diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c index 2326e09..035f71b 100644 --- a/src/blogc/renderer.c +++ b/src/blogc/renderer.c @@ -106,10 +106,8 @@ blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local, value = foreach_var->data; } else { - value = blogc_funcvars_lookup(var, global); - if (value == NULL) { - value = blogc_get_variable(var, global, local); - } + blogc_funcvars_eval(global, var); + value = blogc_get_variable(var, global, local); } if (value == NULL) { |