mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-06-22 13:21:36 +00:00
Refactor to reduce complexity of dict print funcs
Dictionary print functions (print_valstr, print_valstr_2col, dcmi_print_strs) are used in various modules and are excessively complex. One of the reasons is support for loglevel -1, which means printing to STDOUT. Another reason is support in dcmi_print_strs() for so called 'horizontal printing' when only strings without descriptions are printed in one line with separators. Horizontal printing was in fact broken as dcmi_print_strs() was always called with loglevel set to LOG_ERR, which resulted in using lprintf() that adds a '\n' at the end of each printout. This commit: * Fixes horizontal printout for dcmi_print_strs(); * Reduces complexity of all three functions by introducing a macro helper called uprintf() that automatically chooses either printf() or lprintf() based on the selected loglevel; Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
@@ -59,5 +59,17 @@ int log_level_get(void);
|
||||
void lprintf(int level, const char * format, ...);
|
||||
void lperror(int level, const char * format, ...);
|
||||
|
||||
/**
|
||||
* @brief Print to log or to STDOUT depending on the \p ll argument.
|
||||
* @param[in] ll Log level. Negative values meant "print to stdout".
|
||||
* @param[in] fmt The printf format string. No '\n' is needed at the end.
|
||||
*/
|
||||
#define uprintf(ll, fmt, ...) do { \
|
||||
if (ll < 0) \
|
||||
printf(fmt "\n", ##__VA_ARGS__); \
|
||||
else \
|
||||
lprintf(ll, fmt, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#endif /*IPMITOOL_LOG_H*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user