From 69ce4591d09f1fda85c6a71d452d26a2712cda4e Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 18 Sep 2012 15:31:46 +0200 Subject: commands: generally handle property formatting with m_option Use the m_option code by default to format property values, instead of having separate code in m_property. To facilitate that, add a pretty_print callback to option types. These format values in a more human readable and user friendly way, as opposed to the print callback, which produces parseable values. This also changes the strings used with flags. Instead of "enabled" and "disabled", flags are formatted as "yes" and "no". (We could use the pretty_print callback to deal with this, but we don't for consistency.) --- m_option.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'm_option.h') diff --git a/m_option.h b/m_option.h index 75f9ee5925..acbbb3fd9f 100644 --- a/m_option.h +++ b/m_option.h @@ -209,6 +209,11 @@ struct m_option_type { */ char *(*print)(const m_option_t *opt, const void *val); + // Print the value in a human readable form. Unlike print(), it doesn't + // necessarily return the exact value, and is generally not parseable with + // parse(). + char *(*pretty_print)(const m_option_t *opt, const void *val); + // Copy data between two locations. Deep copy if the data has pointers. /** \param opt The option to copy. * \param dst Pointer to the destination memory. @@ -413,6 +418,15 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr) return NULL; } +static inline char *m_option_pretty_print(const m_option_t *opt, + const void *val_ptr) +{ + if (opt->type->pretty_print) + return opt->type->pretty_print(opt, val_ptr); + else + return m_option_print(opt, val_ptr); +} + // Helper around \ref m_option_type::copy. static inline void m_option_copy(const m_option_t *opt, void *dst, const void *src) -- cgit v1.2.3