From b59a3c4131a7cd0da2a4364f6bf29b005400f77b Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 6 Apr 2013 19:25:18 +0000 Subject: [PATCH] filter: Wrap lines in the available filter list. Currently para_filter -h and para_audiod -h print the available filters in a single line which exceeds 80 characters if many filters are supported. This patch makes printf_or_die() return the number of characters printed. This allows to add line breaks to format the filter list. --- filter_common.c | 15 ++++++++++----- ggo.c | 4 ++-- ggo.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/filter_common.c b/filter_common.c index 907912fd..6eb550e8 100644 --- a/filter_common.c +++ b/filter_common.c @@ -105,12 +105,17 @@ int check_filter_arg(char *fa, void **conf) */ void print_filter_helps(int detailed) { - int i; + int i, num = 0; - printf_or_die("\nAvailable filters: \n\t"); - FOR_EACH_SUPPORTED_FILTER(i) - printf_or_die("%s%s", i? " " : "", filters[i].name); - printf_or_die("\n\n"); + printf_or_die("\nAvailable filters: "); + FOR_EACH_SUPPORTED_FILTER(i) { + if (num > 50) { + printf_or_die("\n "); + num = 0; + } + num += printf_or_die("%s%s", i? " " : "", filters[i].name); + } + printf_or_die("\n"); FOR_EACH_SUPPORTED_FILTER(i) { struct filter *f = filters + i; diff --git a/ggo.c b/ggo.c index b2e079ab..7f8eb760 100644 --- a/ggo.c +++ b/ggo.c @@ -15,7 +15,7 @@ * * \param fmt Usual format string. */ -__printf_1_2 void printf_or_die(const char *fmt, ...) +__printf_1_2 int printf_or_die(const char *fmt, ...) { va_list argp; int ret; @@ -24,7 +24,7 @@ __printf_1_2 void printf_or_die(const char *fmt, ...) ret = vprintf(fmt, argp); va_end(argp); if (ret >= 0) - return; + return ret; exit(EXIT_FAILURE); } diff --git a/ggo.h b/ggo.h index e81b10c6..be85a1b4 100644 --- a/ggo.h +++ b/ggo.h @@ -17,4 +17,4 @@ struct ggo_help { }; void ggo_print_help(struct ggo_help *help, int detailed_help); -__printf_1_2 void printf_or_die(const char *fmt, ...); +__printf_1_2 int printf_or_die(const char *fmt, ...); -- 2.39.2