} else {
switch (value->type) {
case valueInt:
- return value->value.intValue;
+ return (value->value.intValue == 0) ? 0 : 1;
case valueString:
if ( value->value.stringValue == NULL || *value->value.stringValue == '\0' )
return 0;
} else if ( strcmp(varName, "__size") == 0 ) {
flags &= ~TND_GLOBAL; /* special vars cannot be global */
flags |= TND___SIZE;
+ } else if ( strcmp(varName, "__level") == 0 ) {
+ flags &= ~TND_GLOBAL; /* special vars cannot be global */
+ flags |= TND___LEVEL;
}
return flags;
int
-setTemplateValueInt( TemplateInstance tmpl, char * key, int val ) {
+setTemplateValueInt( TemplateInstance tmpl, char * key, int64_t val ) {
storage.flags = TND_DEFINED;
storage.type = valueInt;
storage.value.intValue = val;
switch (value->type) {
case valueInt:
- printedlen = snprintf(NULL, 0, (format) ? format : "%d", value->value.intValue);
+ printedlen = snprintf(NULL, 0, (format) ? format : "%lld", value->value.intValue);
break;
case valueString:
if ( value->value.stringValue == NULL || *value->value.stringValue == '\0' )
switch (value->type) {
case valueInt:
- printedlen = snprintf(res, printedlen+1, (format) ? format : "%d", value->value.intValue);
+ printedlen = snprintf(res, printedlen+1, (format) ? format : "%lld", value->value.intValue);
break;
case valueString:
printedlen = snprintf(res, printedlen+1, (format) ? format : "%s", value->value.stringValue);
}
static void
-printNode( TemplateInstance tmpl, TemplateNode node, LoopInstance loopInstance ) {
+printNode( TemplateInstance tmpl, TemplateNode node, LoopInstance loopInstance, int level ) {
GListCell *cell;
VariableValue value;
int i;
realValue->type = valueInt;
realValue->flags |= TND_DEFINED;
realValue->value.intValue = i+1;
+ } else if ( value->flags & TND___LEVEL ) {
+ realValue->type = valueInt;
+ realValue->flags |= TND_DEFINED;
+ realValue->value.intValue = level;
} else if ( value->flags & TND___SIZE ) {
realValue->type = valueInt;
realValue->flags |= TND_DEFINED;
if ( node->nodeData.loop.selfNode )
node->nodeData.loop.selfNode->nodeData.nest.savedRowData = rowData;
- printNode( tmpl, node->nodeData.loop.bodyNode, NULL );
+ printNode( tmpl, node->nodeData.loop.bodyNode, NULL, level );
}
}
break;
}
}
- printNode( tmpl, node->nodeData.nest.loop, savedRowData->nestedInstance );
+ printNode( tmpl, node->nodeData.nest.loop, savedRowData->nestedInstance, level+1 );
/*
* Restore saved datas
value = executeExpression( tmpl, node->nodeData.condition.expressionNode );
if ( isVariable(value) )
- printNode( tmpl, node->nodeData.condition.ifNode, loopInstance );
+ printNode( tmpl, node->nodeData.condition.ifNode, loopInstance, level );
else
- printNode( tmpl, node->nodeData.condition.elseNode, loopInstance );
+ printNode( tmpl, node->nodeData.condition.elseNode, loopInstance, level );
break;
case CollectionNode:
GListForeach( cell, node->nodeData.children )
- printNode( tmpl, (TemplateNode)GLCELL_DATA(cell), loopInstance );
+ printNode( tmpl, (TemplateNode)GLCELL_DATA(cell), loopInstance, level );
break;
case PrintNode:
value = executeExpression( tmpl, node->nodeData.condition.expressionNode );
if (!tmpl->tmpl->printString)
return 1;
- printNode(tmpl, tmpl->tmpl->tree, NULL);
+ printNode(tmpl, tmpl->tmpl->tree, NULL, 0);
return 0;
}
* __FIRST - true for first iteration
* __LAST - true for last iteration
* __COUNTER - iteration's number
+ * __LEVEL - level of nested loop (root == 0)
* __SIZE - number of iterations
* __ODD - true for odd iteraion
* __EVEN - true for even iteraion
#define TND___SIZE (0x0040)
#define TND___ODD (0x0080)
#define TND___EVEN (0x0100)
+#define TND___LEVEL (0x0200)
-#define TND_DEFINED (0x0200)
+#define TND_DEFINED (0x0400)
-#define TND__SPECIALMASK (TND___FIRST | TND___LAST | TND___COUNTER | TND___SIZE | TND___ODD | TND___EVEN)
+#define TND__SPECIALMASK (TND___FIRST | TND___LAST | TND___COUNTER | TND___SIZE | TND___ODD | TND___EVEN | TND___LEVEL)
typedef struct TemplateData *Template;
TemplateNodeType type; /* should be first, see resetTemplate/freeTemplate */
int flags;
union {
- int intValue;
+ int64_t intValue;
char *stringValue;
time_t timeValue;
int boolValue;
#define TVAR_NOROW (3)
#define TVAR_LOOPMARK (4)
-int setTemplateValueInt( TemplateInstance tmpl, char * key, int val );
+int setTemplateValueInt( TemplateInstance tmpl, char * key, int64_t val );
int setTemplateValueString( TemplateInstance tmpl, char * key, char * val );
int setTemplateValueTime( TemplateInstance tmpl, char * key, time_t val );
int setTemplateValueBool( TemplateInstance tmpl, char * key, int val );