From 12e59f337f838d647deb8f84850324f785e58824 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Tue, 20 Oct 2020 10:53:26 -0400 Subject: [PATCH] Feature: libcrmcommon: Add a spacer formatted output message. --- include/crm/common/output_internal.h | 10 +++++++++- lib/common/output_html.c | 6 ++++++ lib/common/output_log.c | 6 ++++++ lib/common/output_text.c | 6 ++++++ lib/common/output_xml.c | 6 ++++++ tools/crm_mon_curses.c | 6 ++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/crm/common/output_internal.h b/include/crm/common/output_internal.h index 2874259..e1bd295 100644 --- a/include/crm/common/output_internal.h +++ b/include/crm/common/output_internal.h @@ -460,6 +460,14 @@ struct pcmk__output_s { * \return true if output should be supressed, false otherwise. */ bool (*is_quiet) (pcmk__output_t *out); + + /*! + * \internal + * \brief Output a spacer. Not all formatter will do this. + * + * \param[in] out The output functions structure. + */ + void (*spacer) (pcmk__output_t *out); }; /*! @@ -745,7 +753,7 @@ G_GNUC_NULL_TERMINATED; #define PCMK__OUTPUT_SPACER_IF(out_obj, cond) \ if (cond) { \ - out_obj->info(out_obj, "%s", ""); \ + out->spacer(out); \ } #define PCMK__OUTPUT_LIST_HEADER(out_obj, cond, retcode, title...) \ diff --git a/lib/common/output_html.c b/lib/common/output_html.c index 156887d..e354b5d 100644 --- a/lib/common/output_html.c +++ b/lib/common/output_html.c @@ -368,6 +368,11 @@ html_is_quiet(pcmk__output_t *out) { return false; } +static void +html_spacer(pcmk__output_t *out) { + pcmk__output_create_xml_node(out, "br"); +} + pcmk__output_t * pcmk__mk_html_output(char **argv) { pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t)); @@ -399,6 +404,7 @@ pcmk__mk_html_output(char **argv) { retval->end_list = html_end_list; retval->is_quiet = html_is_quiet; + retval->spacer = html_spacer; return retval; } diff --git a/lib/common/output_log.c b/lib/common/output_log.c index fd13c89..6336fa2 100644 --- a/lib/common/output_log.c +++ b/lib/common/output_log.c @@ -226,6 +226,11 @@ log_is_quiet(pcmk__output_t *out) { return false; } +static void +log_spacer(pcmk__output_t *out) { + /* This function intentionally left blank */ +} + pcmk__output_t * pcmk__mk_log_output(char **argv) { pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t)); @@ -256,6 +261,7 @@ pcmk__mk_log_output(char **argv) { retval->end_list = log_end_list; retval->is_quiet = log_is_quiet; + retval->spacer = log_spacer; return retval; } diff --git a/lib/common/output_text.c b/lib/common/output_text.c index 9b3c09a..3432505 100644 --- a/lib/common/output_text.c +++ b/lib/common/output_text.c @@ -244,6 +244,11 @@ text_is_quiet(pcmk__output_t *out) { return out->quiet; } +static void +text_spacer(pcmk__output_t *out) { + fprintf(out->dest, "\n"); +} + pcmk__output_t * pcmk__mk_text_output(char **argv) { pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t)); @@ -275,6 +280,7 @@ pcmk__mk_text_output(char **argv) { retval->end_list = text_end_list; retval->is_quiet = text_is_quiet; + retval->spacer = text_spacer; return retval; } diff --git a/lib/common/output_xml.c b/lib/common/output_xml.c index 9a08d20..1710fac 100644 --- a/lib/common/output_xml.c +++ b/lib/common/output_xml.c @@ -376,6 +376,11 @@ xml_is_quiet(pcmk__output_t *out) { return false; } +static void +xml_spacer(pcmk__output_t *out) { + /* This function intentionally left blank */ +} + pcmk__output_t * pcmk__mk_xml_output(char **argv) { pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t)); @@ -407,6 +412,7 @@ pcmk__mk_xml_output(char **argv) { retval->end_list = xml_end_list; retval->is_quiet = xml_is_quiet; + retval->spacer = xml_spacer; return retval; } diff --git a/tools/crm_mon_curses.c b/tools/crm_mon_curses.c index 2c092df..8a08578 100644 --- a/tools/crm_mon_curses.c +++ b/tools/crm_mon_curses.c @@ -247,6 +247,11 @@ curses_is_quiet(pcmk__output_t *out) { return out->quiet; } +static void +curses_spacer(pcmk__output_t *out) { + addch('\n'); +} + pcmk__output_t * crm_mon_mk_curses_output(char **argv) { pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t)); @@ -278,6 +283,7 @@ crm_mon_mk_curses_output(char **argv) { retval->end_list = curses_end_list; retval->is_quiet = curses_is_quiet; + retval->spacer = curses_spacer; return retval; } -- 1.8.3.1