File: test122.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 (40 lines) | stat: -rwxr-xr-x 762 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
35
36
37
38
39
40
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tpl.h"

const char *filename = "/tmp/test122.tpl";

typedef struct {
  char c;
  int i;
} inner_t;

typedef struct {
    int i;
    char c[3];
    double f;
    inner_t inner;
} outer;

int main() {
    tpl_node *tn;
    outer ms = {1, {'a','b','c'}, 3.14, {'a',1}};
    outer os;

    tn = tpl_map( "S(ic#f$(ci))", &ms, 3);
    tpl_pack( tn, 0 );
    tpl_dump( tn, TPL_FILE, filename );
    tpl_free( tn );

    memset(&os, 0, sizeof(outer));
    tn = tpl_map( "S(ic#f$(ci))", &os, 3);
    tpl_load( tn, TPL_FILE, filename );
    tpl_unpack( tn, 0 );
    tpl_free( tn );

    printf("%d %c%c%c %f %c %d\n", os.i, os.c[0],os.c[1],os.c[2],os.f,
      os.inner.c, os.inner.i);

    return(0);
}