Debian Codegraph @

libmowgli-2/src/examples/jsontest/jsontest.c

raw
1 #include <mowgli.h>
2
3 void
4 out_string(mowgli_json_output_t *out, const char *str, size_t len)
5 {
6 fwrite(str, 1, len, stdout);
7 }
8
9 void
10 out_char(mowgli_json_output_t *out, const char c)
11 {
12 fputc(c, stdout);
13 }
14
15 mowgli_json_output_t out =
16 {
17 .append = out_string,
18 .append_char = out_char,
19 };
20
21 int
22 main(int argc, char *argv[])
23 {
24 int i;
25 mowgli_json_t *n;
26
27 if (argc < 2)
28 {
29 printf("Usage: %s file [file ...]\n", argv[0]);
30 return 1;
31 }
32
33 for (i = 1; i < argc; i++)
34 {
35 n = mowgli_json_parse_file(argv[i]);
36
37 if (n != NULL)
38 {
39 mowgli_json_serialize(n, &out, 1);
40 putchar('\n');
41 }
42
43 mowgli_json_decref(n);
44 }
45
46 return 0;
47 }