mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
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:
3
jv.h
3
jv.h
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
JV_KIND_INVALID,
|
JV_KIND_INVALID,
|
||||||
@@ -124,7 +125,9 @@ jv jv_object_iter_value(jv, int);
|
|||||||
int jv_get_refcnt(jv);
|
int jv_get_refcnt(jv);
|
||||||
|
|
||||||
enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8, JV_PRINT_UNBUFFERED = 16 };
|
enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8, JV_PRINT_UNBUFFERED = 16 };
|
||||||
|
void jv_dumpf(jv, FILE *f, int flags);
|
||||||
void jv_dump(jv, int flags);
|
void jv_dump(jv, int flags);
|
||||||
|
void jv_show(jv, int flags);
|
||||||
jv jv_dump_string(jv, int flags);
|
jv jv_dump_string(jv, int flags);
|
||||||
|
|
||||||
jv jv_parse(const char* string);
|
jv jv_parse(const char* string);
|
||||||
|
|||||||
16
jv_print.c
16
jv_print.c
@@ -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;
|
struct dtoa_context C;
|
||||||
jvp_dtoa_context_init(&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);
|
jvp_dtoa_context_free(&C);
|
||||||
if (flags & JV_PRINT_UNBUFFERED) {
|
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) {
|
jv jv_dump_string(jv x, int flags) {
|
||||||
struct dtoa_context C;
|
struct dtoa_context C;
|
||||||
jvp_dtoa_context_init(&C);
|
jvp_dtoa_context_init(&C);
|
||||||
|
|||||||
Reference in New Issue
Block a user