aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-15 14:17:22 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-15 14:17:22 +0100
commit74a547aa407ff8555f40dc38b18dee0bdb708836 (patch)
treeb4499a3ccb0ac902aae1c6fab38b52398ae0e8e5
parent6aee631ac1afe14bd8130df311472d3c552d8bfa (diff)
downloadunja-74a547aa407ff8555f40dc38b18dee0bdb708836.tar.gz
unja-74a547aa407ff8555f40dc38b18dee0bdb708836.zip
move key check to symbol evaluation branch
-rw-r--r--src/template.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/template.c b/src/template.c
index f357d45..a5486df 100644
--- a/src/template.c
+++ b/src/template.c
@@ -58,16 +58,17 @@ int eval(char *dest, mpc_ast_t* t, struct hashmap *ctx) {
if (ctx != NULL && strstr(t->children[2]->tag, "symbol")) {
char *key = t->children[2]->contents;
value = hashmap_resolve(ctx, key);
+
+ // TODO: Handle unexisting keys
+ if (value == NULL) {
+ return 1;
+ }
} else if(strstr(t->children[2]->tag, "number")) {
value = t->children[2]->contents;
} else if(strstr(t->children[2]->tag, "string")) {
value = t->children[2]->children[1]->contents;
}
- // TODO: Handle unexisting keys
- if (value == NULL) {
- return 1;
- }
strcat(dest, value);
return 0;
}