[Libguestfs] [PATCH] fish: simplify output of 'supported'

Pino Toscano ptoscano at redhat.com
Tue May 20 11:31:07 UTC 2014


Print each line at once, making use of the padding features of printf
instead of doing it manually.
---
 fish/supported.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/fish/supported.c b/fish/supported.c
index 651e3aa..b49011a 100644
--- a/fish/supported.c
+++ b/fish/supported.c
@@ -49,20 +49,11 @@ run_supported (const char *cmd, size_t argc, char *argv[])
   }
 
   for (i = 0; groups[i] != NULL; ++i) {
-    size_t l = strlen (groups[i]);
-    size_t j;
-    for (j = 0; j < len-l; ++j)
-      putchar (' ');
-    printf ("%s", groups[i]);
-    putchar (' ');
-
     char *gg[] = { groups[i], NULL };
     int r = guestfs_available (g, gg);
-    if (r == 0)
-      printf ("%s", _("yes"));
-    else
-      printf ("%s", _("no"));
-    putchar ('\n');
+    const char *str = r == 0 ? _("yes") : _("no");
+
+    printf ("%*s %s\n", (int) len, groups[i], str);
   }
 
   /* Restore error handler. */
-- 
1.9.0




More information about the Libguestfs mailing list