2 * Copyright (c) 2008 Teodor Sigaev <teodor@sigaev.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 "tmpltest [-t TEMPLATENAME]\n"
53 outfunc(char *str, int len) {
57 static int counter = 0;
60 localCounter(Template tmpl, int nargs, VariableValue *args) {
61 VariableValue out = tmalloc(sizeof(VariableValue));
64 out->flags = TND_DEFINED;
65 out->value.intValue = ++counter;
74 main(int argn, char *argv[]) {
77 TemplateData template;
79 executeFunctionDescData funcs[] = {
80 {"callcounter", 0, localCounter},
86 opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
89 while((i=getopt(argn,argv,"ht:")) != EOF) {
92 name = tstrdup(optarg);
104 setlocale(LC_ALL,"ru_RU.UTF-8");
105 base = allocMemoryContext(NULL, MC_DEBUG);
107 printf("initTemplate: %d\n", initTemplate(&template, base, funcs, ".", name) );
108 /* dumpTemplate(&template); */
110 setTemplateValueInt(&template, "ID", 17);
111 setTemplateValueUndefined(&template, "emptyID");
112 setTemplateValueInt(&template, "zeroid", 0);
113 setTemplateValueString(&template, "str", "QWERTY");
115 addTemplateRow(&template, "outerLoop");
116 setTemplateValueString(&template, "outerLoop.data1", "ha1");
117 setTemplateValueUndefined(&template, "outerLoop.data2");
119 addTemplateRow(&template, "outerLoop");
120 setTemplateValueInt(&template, "outerLoop.data1", 10);
121 setTemplateValueString(&template, "outerLoop.data2", "WOW");
122 addTemplateRow(&template, "outerLoop.innerLoop");
123 setTemplateValueString(&template, "outerLoop.innerLoop.camenty", "Number 1");
124 addTemplateRow(&template, "outerLoop.innerLoop");
125 setTemplateValueString(&template, "outerLoop.innerLoop.camenty", "Number 2");
127 addTemplateRow(&template, "outerLoop");
128 setTemplateValueString(&template, "outerLoop.data1", "ha3");
130 template.printString = outfunc;
131 printTemplate( &template );
133 resetTemplate(&template);
135 setTemplateValueInt(&template, "ID", 23);
136 setTemplateValueUndefined(&template, "emptyID");
137 setTemplateValueInt(&template, "zeroid", 0);
138 addTemplateRow(&template, "outerLoop");
139 setTemplateValueString(&template, "outerLoop.data1", "ha1");
140 setTemplateValueInt(&template, "outerLoop.data1", 1234);
141 setTemplateValueString(&template, "outerLoop.data2", "FOO");
142 addTemplateRow(&template, "outerLoop.innerLoop");
143 setTemplateValueString(&template, "outerLoop.innerLoop.camenty", "Again 1");
145 fputs("================================================\n", stdout);
146 printTemplate( &template );
148 resetTemplate(&template);
149 freeTemplate(&template);