]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
json_print: Introduce print_#type_name_value
authorRon Diskin <rondi@mellanox.com>
Thu, 23 Jan 2020 10:32:26 +0000 (12:32 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 27 Jan 2020 13:43:54 +0000 (05:43 -0800)
Until now print_#type functions supported printing constant names and
unknown (variable) values only.
Add functions to allow printing when the name is also sent to the
function as a variable.

Signed-off-by: Ron Diskin <rondi@mellanox.com>
Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
include/json_print.h
lib/json_print.c

index 6695654f719471c8ff7044d0cd775edb2758e9a9..fcc28d5e244cac1259114ea8f87b2590591586a7 100644 (file)
@@ -72,4 +72,11 @@ _PRINT_FUNC(lluint, unsigned long long)
 _PRINT_FUNC(float, double)
 #undef _PRINT_FUNC
 
+#define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char)             \
+       void print_##type_name##_name_value(const char *name, type value) \
+
+_PRINT_NAME_VALUE_FUNC(uint, unsigned int, u);
+_PRINT_NAME_VALUE_FUNC(string, const char*, s);
+#undef _PRINT_NAME_VALUE_FUNC
+
 #endif /* _JSON_PRINT_H_ */
index 43ea69bbf73908b61b26248a214b13323aa0252b..fb5f0e5d959b7a7c130da2796fea3ea68ed2e802 100644 (file)
@@ -127,6 +127,19 @@ _PRINT_FUNC(lluint, unsigned long long);
 _PRINT_FUNC(float, double);
 #undef _PRINT_FUNC
 
+#define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char)            \
+       void print_##type_name##_name_value(const char *name, type value)\
+       {                                                                \
+               SPRINT_BUF(format);                                      \
+                                                                        \
+               snprintf(format, SPRINT_BSIZE,                           \
+                        "%s %%"#format_char, name);                     \
+               print_##type_name(PRINT_ANY, name, format, value);       \
+       }
+_PRINT_NAME_VALUE_FUNC(uint, unsigned int, u);
+_PRINT_NAME_VALUE_FUNC(string, const char*, s);
+#undef _PRINT_NAME_VALUE_FUNC
+
 void print_color_string(enum output_type type,
                        enum color_attr color,
                        const char *key,