static int opt_indent;
static int opt_read_hex;
static int opt_write_hex;
+static int opt_stream;
static struct opt_section options = {
OPT_ITEMS {
OPT_BOOL('W', "write-hex", opt_write_hex, 0, "\tWrite JSON, print non-ASCII as hex escapes"),
OPT_BOOL('e', "escape", opt_escape, 0, "\tEscape non-ASCII characters in strings"),
OPT_BOOL('i', "indent", opt_indent, 0, "\tIndent output"),
+ OPT_BOOL('s', "stream", opt_stream, 0, "\tTest of streaming mode"),
OPT_END
}
};
return n;
}
+static void test_stream(struct json_context *js)
+{
+ struct fastbuf *in = bfdopen_shared(0, 65536);
+ struct fastbuf *out = bfdopen_shared(1, 65536);
+ json_set_input(js, in);
+ json_set_output(js, out);
+
+ for (;;)
+ {
+ json_push(js);
+ struct json_node *n = json_next_value(js);
+ if (!n)
+ break;
+ json_write_value(js, n);
+ bputc(out, '\n');
+ json_pop(js);
+ }
+
+ bclose(out);
+ bclose(in);
+}
+
int main(int argc UNUSED, char **argv)
{
opt_parse(&options, argv+1);
if (opt_indent)
js->format_options |= JSON_FORMAT_INDENT;
+ if (opt_stream)
+ {
+ test_stream(js);
+ json_delete(js);
+ return 0;
+ }
+
if (opt_read || opt_read_hex)
{
struct fastbuf *fb = bfdopen_shared(0, 65536);