1 #include "tpl.h"
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5
main(int argc,char * argv[])6 int main(int argc, char*argv[]) {
7 tpl_bin bin;
8 tpl_node *tn;
9 int i;
10 char *file = "/tmp/test30.tpl";
11 char str[10];
12
13 strcpy(str,"good egg");
14 bin.addr = str;
15 bin.sz = 4; /* just going to pack 'good' (no NUL) */
16
17 tn = tpl_map("B", &bin);
18 tpl_pack(tn,0);
19 memset(str,0,10); /* just to test that buf was copied */
20 tpl_dump(tn,TPL_FILE,file);
21 tpl_free(tn);
22
23 bin.addr = NULL;
24 bin.sz = 0;
25
26 tn = tpl_map("B", &bin);
27 tpl_load(tn,TPL_FILE,file);
28 tpl_unpack(tn,0);
29 tpl_free(tn);
30
31 /* print the buffer char-by-char ; its not a nul-termd string */
32 printf("buffer length: %u\n", bin.sz);
33 for(i=0; i < bin.sz; i++) printf("%c", ((char*)bin.addr)[i]);
34 printf("\n");
35
36 if (bin.sz > 0)
37 free(bin.addr); /* malloc'd for us by tpl_unpack, we must free */
38 return(0);
39 }
40
41