aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ctemplates.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/ctemplates.c b/src/ctemplates.c
index 3209bf4..ab746ee 100644
--- a/src/ctemplates.c
+++ b/src/ctemplates.c
@@ -1078,32 +1078,57 @@ render_if(struct TMPL_templates* t, struct TMPL_varlist* varlist){
if(err == MAP_OK){
//These two if statements can't be combined because of
//the condition for the elseif
+ //If we found the value without a test value, or we have
+ //a test value and it's correct, do the true branch
if(testval == NULL || strcmp(vi->item.s, testval) == 0){
nt->roottag = t->cursor->TMPL_tag.ifelse.tbranch;
nt->cursor = nt->roottag;
err = TMPL_render_helper(nt,varlist);
+ if(err){
+ goto cleanup;
+ }
if(nt->jumping)
t->cursor = nt->cursor;
t->breaks += nt->breaks;
t->continues = nt->continues;
t->jumping = nt->jumping;
}else{
-
+ //Our test value is not empty, and we found the value,
+ //but it's not the correct value.
+ nt->roottag = t->cursor->TMPL_tag.ifelse.fbranch;
+ nt->cursor = nt->roottag;
+ err = TMPL_render_helper(nt,varlist);
+ if(err){
+ goto cleanup;
+ }
+ if(nt->jumping)
+ t->cursor = nt->cursor;
+ t->breaks += nt->breaks;
+ t->continues = nt->continues;
+ t->jumping = nt->jumping;
+ err = 0;
}
-
}else if(t->cursor->TMPL_tag.ifelse.fbranch != NULL){
nt->roottag = t->cursor->TMPL_tag.ifelse.fbranch;
nt->cursor = nt->roottag;
err = TMPL_render_helper(nt,varlist);
+ if(err){
+ goto cleanup;
+ }
if(nt->jumping)
t->cursor = nt->cursor;
t->breaks += nt->breaks;
t->continues = nt->continues;
t->jumping = nt->jumping;
+ err = 0;
}else{
+ //Could not find value, and we don't have a false branch,
+ //do nothing
+ err = 0;
}
- free(nt);
advance_cursor(t);
+cleanup:
+ free(nt);
return err;
}