sched.c: Remove unused timeout_is_zero().
[paraslash.git] / ggo.c
diff --git a/ggo.c b/ggo.c
index a9bc4c367c9af091939af1ed4e02072b71268c2a..04abf8ebf098b93eed18d0d14e0fcbdff13e0c37 100644 (file)
--- a/ggo.c
+++ b/ggo.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2011 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008-2014 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -9,13 +9,17 @@
 
 #include "para.h"
 #include "ggo.h"
+#include "version.h"
 
 /**
  * Wrapper for printf() that exits on errors.
  *
  * \param fmt Usual format string.
+ *
+ * \return The return value of the underlying (successful) call to vprintf(3),
+ * i.e. the number of characters printed, excluding the terminating null byte.
  */
-__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 +28,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);
 }
 
@@ -32,21 +36,25 @@ __printf_1_2 void printf_or_die(const char *fmt, ...)
  * Print one of the two given help texts.
  *
  * \param help contains the help texts.
- * \param detailed_help Whether to print the detailed help text.
+ * \param flags What to print, see \ref ggo_print_help_flags.
  */
-void ggo_print_help(struct ggo_help *help, int detailed_help)
+void ggo_print_help(struct ggo_help *help, unsigned flags)
 {
        const char **p;
 
-       if (!help)
-               return;
-       if (detailed_help)
+       if (help->purpose && (flags & GPH_PRINT_NAME_PURPOSE))
+               printf_or_die("para_%s - %s\n", help->prefix, help->purpose);
+       if (help->usage && (flags & GPH_PRINT_USAGE))
+               printf_or_die("\n%s\n", help->usage);
+       if (help->description && (flags & GPH_PRINT_DESCRIPTION))
+               printf_or_die("\n%s\n", help->description);
+       printf_or_die("\n");
+       if (flags & GPH_DETAILED)
                p = help->detailed_help;
        else
                p = help->short_help;
        if (!p)
                return;
-       p += 3; /* skip -h and -V */
        for (; *p; p++)
-               printf_or_die("\t%s\n", *p);
+               printf_or_die("%s\n", *p);
 }