diff --git a/src/tools/sysdb/json.c b/src/tools/sysdb/json.c
index 1bd8080970b831fe5a00c1dd586e887ee616e8e5..8e9b1e79839b709d96497e83036ea74fda16cb5d 100644 (file)
--- a/src/tools/sysdb/json.c
+++ b/src/tools/sysdb/json.c
*/
typedef struct {
+ FILE *out;
+
/* The context describes the state of the formatter along with the
* respective parent contexts. */
int context[8];
bool have_output;
} formatter_t;
#define F(obj) ((formatter_t *)(obj))
-#define F_INIT { { 0 }, { -1, -1, -1, -1, -1, -1, -1, -1 }, 0, 0, false }
+#define F_INIT(out) { (out), { 0 }, { -1, -1, -1, -1, -1, -1, -1, -1 }, 0, 0, false }
static int
push(formatter_t *f, int type)
char buf[l + 1];
strncpy(buf, s, l);
buf[l] = '\0';
- printf("%s", buf);
+ fprintf(f->out, "%s", buf);
}
else
- printf("%s", s);
+ fprintf(f->out, "%s", s);
f->have_output = true;
} /* print */
*/
int
-sdb_json_print(sdb_input_t *input, int type, sdb_strbuf_t *buf)
+sdb_json_print(FILE *out, sdb_input_t *input, int type, sdb_strbuf_t *buf)
{
#ifdef HAVE_LIBYAJL
const unsigned char *json;
yajl_handle h;
yajl_status status;
- formatter_t f = F_INIT;
+ formatter_t f = F_INIT(out);
int ret = 0;
if (!input->interactive) {
/* no formatting */
- printf("%s\n", sdb_strbuf_string(buf));
+ fprintf(out, "%s\n", sdb_strbuf_string(buf));
return 0;
}
#else /* HAVE_LIBYAJL */
(void)input;
(void)type;
- printf("%s\n", sdb_strbuf_string(buf));
+ fprintf(out, "%s\n", sdb_strbuf_string(buf));
return 0;
#endif /* HAVE_LIBYAJL */
} /* sdb_json_print */