diff options
author | <andrewsh@debian.org> | 2016-07-05 15:22:32 +0200 |
---|---|---|
committer | <andrewsh@debian.org> | 2016-07-05 15:22:32 +0200 |
commit | cd4e6862b9b46c5a86bd5aea69fb853650bafe52 (patch) | |
tree | 2689a7c405f673e112eb3346eeb2588ea683ed0f /src/examples/jsontest | |
parent | 89ea71be5b5b98cf7869ba1059e4b6c60cd82c85 (diff) | |
parent | 9e0c7e865c04dcbcdb6bd74a2e3ab379dfd8dd8b (diff) |
Merge experimental version.
Diffstat (limited to 'src/examples/jsontest')
-rw-r--r-- | src/examples/jsontest/Makefile | 7 | ||||
-rw-r--r-- | src/examples/jsontest/jsontest.c | 47 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/examples/jsontest/Makefile b/src/examples/jsontest/Makefile new file mode 100644 index 0000000..eb5d82d --- /dev/null +++ b/src/examples/jsontest/Makefile @@ -0,0 +1,7 @@ +PROG_NOINST = jsontest${PROG_SUFFIX} +SRCS = jsontest.c + +include ../../../buildsys.mk + +CPPFLAGS += -I../../libmowgli +LIBS += -L../../libmowgli -lmowgli-2 diff --git a/src/examples/jsontest/jsontest.c b/src/examples/jsontest/jsontest.c new file mode 100644 index 0000000..a63dbc5 --- /dev/null +++ b/src/examples/jsontest/jsontest.c @@ -0,0 +1,47 @@ +#include <mowgli.h> + +void +out_string(mowgli_json_output_t *out, const char *str, size_t len) +{ + fwrite(str, 1, len, stdout); +} + +void +out_char(mowgli_json_output_t *out, const char c) +{ + fputc(c, stdout); +} + +mowgli_json_output_t out = +{ + .append = out_string, + .append_char = out_char, +}; + +int +main(int argc, char *argv[]) +{ + int i; + mowgli_json_t *n; + + if (argc < 2) + { + printf("Usage: %s file [file ...]\n", argv[0]); + return 1; + } + + for (i = 1; i < argc; i++) + { + n = mowgli_json_parse_file(argv[i]); + + if (n != NULL) + { + mowgli_json_serialize(n, &out, 1); + putchar('\n'); + } + + mowgli_json_decref(n); + } + + return 0; +} |