diff options
Diffstat (limited to 'ctemplates.c')
| -rw-r--r-- | ctemplates.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/ctemplates.c b/ctemplates.c index d858aa9..e9e36ff 100644 --- a/ctemplates.c +++ b/ctemplates.c @@ -747,7 +747,8 @@ TMPL_free_loop(struct TMPL_loop* tl){ if(tl->next != NULL){ TMPL_free_loop(tl->next); } - TMPL_free_varlist(tl->varlist); + if(tl->varlist != NULL) + TMPL_free_varlist(tl->varlist); free(tl); } @@ -874,6 +875,7 @@ render_text(struct TMPL_templates* t, struct TMPL_tagnode* node, struct TMPL_var int print_pair(any_t indent, any_t b){ struct TMPL_varitem* vi = (struct TMPL_varitem*)b; + printf("Print pair, varitem is %p, type is %d\n",(void*)vi,(int)vi->type); int* ip = (int*)indent; int ind = *ip; if(vi->type == vartype_var){ @@ -885,7 +887,9 @@ print_pair(any_t indent, any_t b){ struct TMPL_loop* cursor; printf("{\n"); ind++; - for(cursor = vi->item.l; cursor != NULL; cursor = cursor->next){ + /*If the loop doesn't have any varlists added, the cursor's varlist will be null*/ + for(cursor = vi->item.l; cursor != NULL && cursor->varlist != NULL; cursor = cursor->next){ + printf("First iteration though, cursor was %p\n",(void*)cursor); print_varlist_helper(cursor->varlist,ind); } printf("}\n"); @@ -911,12 +915,20 @@ render_if(struct TMPL_templates* t, struct TMPL_tagnode* node, struct TMPL_varli struct TMPL_varitem* vi; int err = hashmap_get(varlist->map,varname,(void**)&vi); struct TMPL_tagnode* cursor; - if(err == MAP_OK && strcmp(vi->item.s,testval) == 0){ - cursor = node->TMPL_tag.ifelse.tbranch; - while(cursor != NULL){ - render_any(t,cursor,varlist); - cursor = cursor->next; + if(err == MAP_OK){ + if(testval == NULL){/*Use this if as an existance check*/ + + }else if(strcmp(vi->item.s, testval) == 0){ + cursor = node->TMPL_tag.ifelse.tbranch; + while(cursor != NULL){ + render_any(t,cursor,varlist); + cursor = cursor->next; + } + + }else{ + } + }else if(node->TMPL_tag.ifelse.fbranch != NULL){ cursor = node->TMPL_tag.ifelse.fbranch; while(cursor != NULL){ @@ -934,10 +946,27 @@ render_elseif(struct TMPL_templates* t, struct TMPL_tagnode* node, struct TMPL_v } int +resolve_name(struct TMPL_varlist* varlist, char* name,struct TMPL_varitem** item){ + return hashmap_get(varlist->map,name,(void*)item); + /* + struct TMPL_varlist* cursor = varlist; + int err; + do{ + err = hashmap_get(cursor->map,name,(void*)item); + cursor = cursor->parent; + }while(cursor != NULL && err == MAP_MISSING); + if(err == MAP_MISSING){ + return MAP_MISSING; + } + return MAP_OK; + */ +} + +int render_loop(struct TMPL_templates* t, struct TMPL_tagnode* node, struct TMPL_varlist* varlist){ char* loopname = node->TMPL_tag.loop.loopname; struct TMPL_varitem* loop; - int err = hashmap_get(varlist->map,loopname,(void*)&loop); + int err = resolve_name(varlist,loopname,&loop); if(err != MAP_OK){ return -1; } @@ -946,7 +975,8 @@ render_loop(struct TMPL_templates* t, struct TMPL_tagnode* node, struct TMPL_var nt->errout = t->errout; nt->roottag = node->TMPL_tag.loop.body; struct TMPL_loop* cursor; - for(cursor = loop->item.l; cursor != NULL; cursor = cursor->next){ + /*If the loop has no items, it's varlist will be null*/ + for(cursor = loop->item.l; cursor != NULL && cursor->varlist != NULL; cursor = cursor->next){ if(err != 0){ } TMPL_render_helper(nt,cursor->varlist); |
