Add jv_dumpf() and jv_show()

jv_dumpf() takes a FILE *.

jv_show() is intended for use in debuggers, so it dumps the jv to stderr
and it does not jv_free() the jv, so it's safe to
"call jv_show(some_jv, -1)" in a debugger.  If flags == -1 then the jv
will be shown pretty-printed and in color.
This commit is contained in:
Nicolas Williams committed 2013-12-26 18:40:34 -06:00
1 parent cb976b9a50
commit a71138a43a
2 files changed
+16 -3

No files matched your search

+13 -3
View File
@@ -260,16 +260,26 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
}
}
void jv_dump(jv x, int flags) {
void jv_dumpf(jv x, FILE *f, int flags) {
struct dtoa_context C;
jvp_dtoa_context_init(&C);
jv_dump_term(&C, x, flags, 0, stdout, 0);
jv_dump_term(&C, x, flags, 0, f, 0);
jvp_dtoa_context_free(&C);
if (flags & JV_PRINT_UNBUFFERED) {
fflush(stdout);
fflush(f);
}
}
void jv_dump(jv x, int flags) {
jv_dumpf(x, stdout, flags);
}
void jv_show(jv x, int flags) {
if (flags == -1)
flags = JV_PRINT_PRETTY | JV_PRINT_COLOUR | JV_PRINT_UNBUFFERED;
jv_dumpf(jv_copy(x), stderr, flags);
}
jv jv_dump_string(jv x, int flags) {
struct dtoa_context C;
jvp_dtoa_context_init(&C);