Add expressions
[tedtools.git] / tmpltest.c
index 5c3986f..c5aef19 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <locale.h>
 
 
 #include "tmalloc.h"
@@ -42,7 +43,7 @@ static void
 usage() {
        puts(
        "Usage:\n"
-       "memtest [-t TEMPLATENAME]\n"
+       "tmpltest [-t TEMPLATENAME]\n"
        );
        exit(1);
 }
@@ -53,6 +54,19 @@ outfunc(char *str, int len) {
        fputs( str, stdout ); 
 }
 
+static int counter = 0;
+
+static VariableValue 
+localCounter(Template tmpl, int nargs, VariableValue *args) {
+       VariableValue out = tmalloc(sizeof(VariableValue));
+
+       out->type = valueInt;
+       out->flags = TND_DEFINED;
+       out->value.intValue = ++counter;
+
+       return out;
+}
+
 extern char *optarg;
 extern int opterr;
 
@@ -62,6 +76,12 @@ main(int argn, char *argv[]) {
        char                    *name = NULL;
        TemplateData    template;
        int                     i;
+       executeFunctionDescData funcs[] = {
+               {"callcounter", 0, localCounter},
+               {NULL,0,NULL}
+       };
+
+
 
        opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
        opterr=0;
@@ -81,14 +101,16 @@ main(int argn, char *argv[]) {
        if (!name)
                usage();
 
+       setlocale(LC_ALL,"ru_RU.UTF-8");
        base = allocMemoryContext(NULL, MC_DEBUG);
 
-       printf("initTemplate: %d\n",  initTemplate(&template, base, ".", name) );
-       /* dumpTemplate(&template); */ 
+       printf("initTemplate: %d\n",  initTemplate(&template, base, funcs, ".", name) );
+       /* dumpTemplate(&template); */
 
        setTemplateValueInt(&template, "ID", 17);
        setTemplateValueUndefined(&template, "emptyID");
        setTemplateValueInt(&template, "zeroid", 0);
+       setTemplateValueString(&template, "str", "QWERTY");
 
        addTemplateRow(&template, "outerLoop");
        setTemplateValueString(&template, "outerLoop.data1", "ha1");