filter: Wrap lines in the available filter list.
authorAndre Noll <maan@systemlinux.org>
Sat, 6 Apr 2013 19:25:18 +0000 (19:25 +0000)
committerAndre Noll <maan@systemlinux.org>
Thu, 13 Jun 2013 16:29:02 +0000 (18:29 +0200)
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
ggo.c
ggo.h

index 907912f..6eb550e 100644 (file)
@@ -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 b2e079a..7f8eb76 100644 (file)
--- 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 e81b10c..be85a1b 100644 (file)
--- 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, ...);