1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "tpl.h"
5 
6 #define NUM_STRS 3
7 #define NUM_ELMT 3
8 #define STR "apple"
9 #define SLEN 5
10 
11 const char *filename = "/tmp/test117.tpl";
12 
main()13 int main() {
14   tpl_node *tn;
15   int i,j,d=1,D=-1;
16   char c='a', C='0';
17   char *strs[NUM_STRS];
18   char *STRS[NUM_STRS];
19 
20   tn = tpl_map("cA(s#)i", &c, strs, NUM_STRS, &d);
21   for(i=0; i<NUM_ELMT; i++) {  /* pack the same thing this many times*/
22     for(j=0; j<NUM_STRS; j++) {/* each time just tweaking them a bit */
23       strs[j] = malloc( SLEN+1 );
24       memcpy(strs[j], STR, SLEN+1);
25       strs[j][0] = 'a'+j;
26     }
27     tpl_pack(tn,1);
28   }
29   tpl_pack(tn,0);
30   tpl_dump(tn,TPL_FILE,filename);
31   tpl_free(tn);
32 
33   tn = tpl_map("cA(s#)i", &C, STRS, NUM_STRS, &D);
34   tpl_load(tn,TPL_FILE,filename);
35   tpl_unpack(tn,0);
36   while(tpl_unpack(tn,1)>0) {
37     for(i=0;i<NUM_STRS;i++) {
38       printf("%s\n", STRS[i]);
39       free(STRS[i]);
40     }
41   }
42   tpl_free(tn);
43 
44   printf("%d %c\n", D, C);
45 
46   return 0;
47 }
48