diff options
-rw-r--r-- | include/json_print.h | 4 | ||||
-rw-r--r-- | ip/ipaddress.c | 4 | ||||
-rw-r--r-- | lib/json_print.c | 31 |
3 files changed, 13 insertions, 26 deletions
diff --git a/include/json_print.h b/include/json_print.h index 44cf5ac5..b6ce1f9f 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -29,13 +29,11 @@ enum output_type { PRINT_ANY = 4, }; -void new_json_obj(int json, FILE *fp); +void new_json_obj(int json); void delete_json_obj(void); bool is_json_context(void); -void set_current_fp(FILE *fp); - void fflush_fp(void); void open_json_object(const char *str); diff --git a/ip/ipaddress.c b/ip/ipaddress.c index b8bc387a..9e9a7e0a 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1815,7 +1815,7 @@ static int ipaddr_showdump(void) if (ipadd_dump_check_magic()) exit(-1); - new_json_obj(json, stdout); + new_json_obj(json); open_json_object(NULL); open_json_array(PRINT_JSON, "addr_info"); @@ -2176,7 +2176,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) * Initialize a json_writer and open an array object * if -json was specified. */ - new_json_obj(json, stdout); + new_json_obj(json); /* * If only filter_dev present and none of the other diff --git a/lib/json_print.c b/lib/json_print.c index 93b4119d..aa527af6 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -16,15 +16,14 @@ #include "json_print.h" static json_writer_t *_jw; -static FILE *_fp; #define _IS_JSON_CONTEXT(type) ((type & PRINT_JSON || type & PRINT_ANY) && _jw) #define _IS_FP_CONTEXT(type) (!_jw && (type & PRINT_FP || type & PRINT_ANY)) -void new_json_obj(int json, FILE *fp) +void new_json_obj(int json) { if (json) { - _jw = jsonw_new(fp); + _jw = jsonw_new(stdout); if (!_jw) { perror("json object"); exit(1); @@ -32,7 +31,6 @@ void new_json_obj(int json, FILE *fp) jsonw_pretty(_jw, true); jsonw_start_array(_jw); } - set_current_fp(fp); } void delete_json_obj(void) @@ -48,15 +46,6 @@ bool is_json_context(void) return _jw != NULL; } -void set_current_fp(FILE *fp) -{ - if (!fp) { - fprintf(stderr, "Error: invalid file pointer.\n"); - exit(1); - } - _fp = fp; -} - json_writer_t *get_json_writer(void) { return _jw; @@ -89,7 +78,7 @@ void open_json_array(enum output_type type, const char *str) jsonw_name(_jw, str); jsonw_start_array(_jw); } else if (_IS_FP_CONTEXT(type)) { - fprintf(_fp, "%s", str); + printf("%s", str); } } @@ -103,7 +92,7 @@ void close_json_array(enum output_type type, const char *str) jsonw_end_array(_jw); jsonw_pretty(_jw, true); } else if (_IS_FP_CONTEXT(type)) { - fprintf(_fp, "%s", str); + printf("%s", str); } } @@ -124,7 +113,7 @@ void close_json_array(enum output_type type, const char *str) else \ jsonw_##type_name##_field(_jw, key, value); \ } else if (_IS_FP_CONTEXT(t)) { \ - color_fprintf(_fp, color, fmt, value); \ + color_fprintf(stdout, color, fmt, value); \ } \ } _PRINT_FUNC(int, int); @@ -147,7 +136,7 @@ void print_color_string(enum output_type type, else jsonw_string_field(_jw, key, value); } else if (_IS_FP_CONTEXT(type)) { - color_fprintf(_fp, color, fmt, value); + color_fprintf(stdout, color, fmt, value); } } @@ -168,7 +157,7 @@ void print_color_bool(enum output_type type, else jsonw_bool(_jw, value); } else if (_IS_FP_CONTEXT(type)) { - color_fprintf(_fp, color, fmt, value ? "true" : "false"); + color_fprintf(stdout, color, fmt, value ? "true" : "false"); } } @@ -187,7 +176,7 @@ void print_color_0xhex(enum output_type type, snprintf(b1, sizeof(b1), "%#x", hex); print_string(PRINT_JSON, key, NULL, b1); } else if (_IS_FP_CONTEXT(type)) { - color_fprintf(_fp, color, fmt, hex); + color_fprintf(stdout, color, fmt, hex); } } @@ -206,7 +195,7 @@ void print_color_hex(enum output_type type, else jsonw_string(_jw, b1); } else if (_IS_FP_CONTEXT(type)) { - color_fprintf(_fp, color, fmt, hex); + color_fprintf(stdout, color, fmt, hex); } } @@ -226,6 +215,6 @@ void print_color_null(enum output_type type, else jsonw_null(_jw); } else if (_IS_FP_CONTEXT(type)) { - color_fprintf(_fp, color, fmt, value); + color_fprintf(stdout, color, fmt, value); } } |