summaryrefslogtreecommitdiff
path: root/src/examples/jsontest/jsontest.c
diff options
context:
space:
mode:
authorAndrew Shadura <andrew@shadura.me>2014-06-17 11:57:32 +0200
committerAndrew Shadura <andrew@shadura.me>2014-06-17 11:57:32 +0200
commitd1e7e16224c881ee3093658fe4cbf14db244cec7 (patch)
tree8850e7a55b4b1589a7a08e2364e9c12dad31962c /src/examples/jsontest/jsontest.c
parent246fb6b81eef837f1269073255373bf0a3d5c27a (diff)
Update to the latest upstream snapshot
Diffstat (limited to 'src/examples/jsontest/jsontest.c')
-rw-r--r--src/examples/jsontest/jsontest.c47
1 files changed, 47 insertions, 0 deletions
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;
+}