aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-02-10 00:58:25 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-02-10 00:58:25 +0100
commit8b7ef9a86d712f0939d1170b5abfe9af13b1873e (patch)
treef535fc319fd41126ab1100b4b59d2c02c8cc8ba0 /src
parent49ed30a5e87e510fd0c14b367110175f9d2fb144 (diff)
downloadblogc-8b7ef9a86d712f0939d1170b5abfe9af13b1873e.tar.gz
blogc-8b7ef9a86d712f0939d1170b5abfe9af13b1873e.tar.bz2
blogc-8b7ef9a86d712f0939d1170b5abfe9af13b1873e.zip
blogc: funcvars: code simplified, added tests
Diffstat (limited to 'src')
-rw-r--r--src/blogc/funcvars.c13
-rw-r--r--src/blogc/funcvars.h2
-rw-r--r--src/blogc/renderer.c6
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) {