File: test104.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 (33 lines) | stat: -rwxr-xr-x 680 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
#include "tpl.h"
#include <stdio.h>

const char *filename = "/tmp/test104.tpl";
int main() {
  tpl_node *tn;
  struct {
    int i;
    char *s;
    char c;
    char *t;
    int j;
    unsigned u;
  } s;
  char *fmt, *ps, pc, *pt;
  int pi, pj;

  tn = tpl_map("S(iscsiu)", &s);
  s.i = 1; s.s = NULL; s.c = '^'; s.t = "world"; s.j = 2; s.u = 3;
  tpl_pack(tn, 0);
  tpl_dump(tn, TPL_FILE, filename);
  tpl_free(tn);

  fmt = tpl_peek(TPL_FILE|TPL_DATAPEEK, filename, "iscsi",&pi,&ps,&pc,&pt,&pj);
  if (fmt) {
    printf("fmt: %s\n", fmt);
    printf("pi: %d, ps: %s, pc: %c, pt: %s, pi: %d\n",pi,ps?ps:"NULL",pc,pt,pj);
  } else {
    printf("peek failed\n");
  }

  return 0;
}