1 /* 2 * json_print.h "print regular or json output, based on json_writer". 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 7 * 2 of the License, or (at your option) any later version. 8 * 9 * Authors: Julien Fortin, <[email protected]> 10 */ 11 12 #ifndef _JSON_PRINT_H_ 13 #define _JSON_PRINT_H_ 14 15 #include "json_writer.h" 16 17 json_writer_t *get_json_writer(void); 18 19 /* 20 * use: 21 * - PRINT_ANY for context based output 22 * - PRINT_FP for non json specific output 23 * - PRINT_JSON for json specific output 24 */ 25 enum output_type { 26 PRINT_FP = 1, 27 PRINT_JSON = 2, 28 PRINT_ANY = 4, 29 }; 30 31 void new_json_obj(int json); 32 void delete_json_obj(void); 33 34 bool is_json_context(void); 35 36 void fflush_fp(void); 37 38 void open_json_object(const char *str); 39 void close_json_object(void); 40 void open_json_array(const char *key, const char *str); 41 void close_json_array(const char *delim); 42 43 void print_nl(void); 44 45 #define _PRINT_FUNC(type_name, type) \ 46 void print_##type_name(enum output_type t, \ 47 const char *key, \ 48 const char *fmt, \ 49 type value) \ 50 51 _PRINT_FUNC(int, int); 52 _PRINT_FUNC(s64, int64_t); 53 _PRINT_FUNC(bool, bool); 54 _PRINT_FUNC(null, const char*); 55 _PRINT_FUNC(string, const char*); 56 _PRINT_FUNC(uint, unsigned int); 57 _PRINT_FUNC(u64, uint64_t); 58 _PRINT_FUNC(hhu, unsigned char); 59 _PRINT_FUNC(hu, unsigned short); 60 _PRINT_FUNC(hex, unsigned int); 61 _PRINT_FUNC(0xhex, unsigned long long); 62 _PRINT_FUNC(luint, unsigned long); 63 _PRINT_FUNC(lluint, unsigned long long); 64 _PRINT_FUNC(float, double); 65 #undef _PRINT_FUNC 66 67 #endif /* _JSON_PRINT_H_ */ 68