File: test70.c

package info (click to toggle)
libtpl 1.5-2
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 4,284 kB
  • ctags: 748
  • sloc: sh: 10,059; ansic: 5,644; perl: 1,062; makefile: 119; cpp: 32
file content (34 lines) | stat: -rwxr-xr-x 804 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tpl.h"

struct ms_t {
    char c;
    int i;
    char s[2];
    char o;
    char *x;
    char y;
    double d;
};

int main() {
    tpl_node *tn;
    struct ms_t ms = {/*.c =*/ 'a', /*.i =*/ 1, /*.s =*/ {'h','i'}, /*.o =*/ 'o', /*.x =*/ "matilda", /*.y =*/ 'y', /*.d =*/ 3.14 };
    struct ms_t ms2;

    tn = tpl_map("S(cic#cscf)", &ms, 2);
    tpl_pack(tn,0);
    tpl_dump(tn,TPL_FILE,"/tmp/test70.tpl");
    tpl_free(tn);

    memset(&ms2,0,sizeof(struct ms_t));
    tn = tpl_map("S(cic#cscf)", &ms2, 2);
    tpl_load(tn,TPL_FILE,"/tmp/test70.tpl");
    tpl_unpack(tn,0);
    tpl_free(tn);
    printf("%c\n%d\n%c%c\n%c\n%s\n%c\n%f\n", ms2.c, ms2.i, ms2.s[0], ms2.s[1], ms2.o, ms2.x, ms2.y, ms2.d);
    free(ms2.x);
    return(0);
}