aboutsummaryrefslogtreecommitdiff
path: root/ctemplates.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-04-06 12:39:07 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2018-04-06 12:39:07 -0400
commit4c438a0d0b1cf978911accef7424a1e64e3dac1a (patch)
tree817358554816ae6cd8003229fed22b080fe74ae9 /ctemplates.c
parentde254471b7bba86b4b15dbaf7cc04d31aafad319 (diff)
downloadlibctemplates-4c438a0d0b1cf978911accef7424a1e64e3dac1a.tar.gz
libctemplates-4c438a0d0b1cf978911accef7424a1e64e3dac1a.tar.bz2
libctemplates-4c438a0d0b1cf978911accef7424a1e64e3dac1a.zip
Fixed a bug with if/elseif
Elseif now works exactly like if, where it will check for the existance of a variable if it does not have a value field.
Diffstat (limited to 'ctemplates.c')
-rw-r--r--ctemplates.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/ctemplates.c b/ctemplates.c
index e79b676..8d4bbd6 100644
--- a/ctemplates.c
+++ b/ctemplates.c
@@ -522,17 +522,21 @@ parse_elseif(struct TMPL_token* head, struct TMPL_buf* errbuf){
t->TMPL_tag.ifelse.varname = name;
int testval_offset = kmp(start_of_attribs,head->length, ATTRIBUTE_VALUE,ATTRIBUTE_VALUE_LENGTH);
- char* start_of_value = start_of_attribs + testval_offset + ATTRIBUTE_VALUE_LENGTH;
- size_t value_length = get_quoted_string(start_of_value,head->length);
- char* value = (char*)malloc(sizeof(char)*value_length);
- memcpy(value,start_of_value,value_length);
- value[value_length] = '\0';
- t->TMPL_tag.ifelse.testval = value;
+ if(testval_offset == -1){
+ t->TMPL_tag.ifelse.testval = NULL;
+ }else{
+ char* start_of_value = start_of_attribs + testval_offset + ATTRIBUTE_VALUE_LENGTH;
+ size_t value_length = get_quoted_string(start_of_value,head->length);
+ char* value = (char*)malloc(sizeof(char)*value_length);
+ memcpy(value,start_of_value,value_length);
+ value[value_length] = '\0';
+ t->TMPL_tag.ifelse.testval = value;
+ }
struct TMPL_token* cursor = head->next;
int nest_level = 0;
struct TMPL_token* fstart = NULL;
while(nest_level > 0 || cursor->type != tag_end){
- if(nest_level == 0 && fstart == NULL){
+ if(fstart == NULL){
if(cursor->type == tag_elseif){
fstart = cursor;
}else if(cursor->type == tag_else){
@@ -559,8 +563,8 @@ parse_elseif(struct TMPL_token* head, struct TMPL_buf* errbuf){
}
t->TMPL_tag.ifelse.tbranch = parse(head->next,errbuf);
- t->next = NULL;
-
+ t->next = parse(cursor->next,errbuf);
+
t->type = tag_elseif;
return t;