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 907912fd06d9f0e4a78a53c7a5026c4a0a9d4846..6eb550e845db9865dc42937cfb1188c4de840050 100644 (file)
@@ -105,12 +105,17 @@ int check_filter_arg(char *fa, void **conf)
  */
 void print_filter_helps(int detailed)
 {
  */
 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;
 
        FOR_EACH_SUPPORTED_FILTER(i) {
                struct filter *f = filters + i;
diff --git a/ggo.c b/ggo.c
index b2e079ab426a5e0a4547d5db465570e00a803695..7f8eb760b49d0d72d01f284d852dc419c4c042ca 100644 (file)
--- a/ggo.c
+++ b/ggo.c
@@ -15,7 +15,7 @@
  *
  * \param fmt Usual format string.
  */
  *
  * \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;
 {
        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)
        ret = vprintf(fmt, argp);
        va_end(argp);
        if (ret >= 0)
-               return;
+               return ret;
        exit(EXIT_FAILURE);
 }
 
        exit(EXIT_FAILURE);
 }
 
diff --git a/ggo.h b/ggo.h
index e81b10c6a3846f2b3c73bd14de56264216a2ba89..be85a1b43be998d8b3c3fa3fd9518055b2153bf0 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);
 };
 
 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, ...);