X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=ggo.c;h=d8d56c03faa42e86a0c2d7862adb72a0b4603f04;hp=55f1043082e5c511231616ad6bc5bd6a43e1f6af;hb=aa74a903545250506fd4c29791e6f4aef3a01c41;hpb=6442f07bb08eb6e557086587f997b1785ea18ef7 diff --git a/ggo.c b/ggo.c index 55f10430..d8d56c03 100644 --- a/ggo.c +++ b/ggo.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Andre Noll + * Copyright (C) 2008-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -9,8 +9,14 @@ #include "para.h" #include "ggo.h" +#include "version.h" -__printf_1_2 void printf_or_die(const char *fmt, ...) +/** + * Wrapper for printf() that exits on errors. + * + * \param fmt Usual format string. + */ +__printf_1_2 int printf_or_die(const char *fmt, ...) { va_list argp; int ret; @@ -19,23 +25,33 @@ __printf_1_2 void printf_or_die(const char *fmt, ...) ret = vprintf(fmt, argp); va_end(argp); if (ret >= 0) - return; - fprintf(stderr, "%s: %s\n", __FUNCTION__, strerror(errno)); + return ret; + exit(EXIT_FAILURE); } -void ggo_print_help(struct ggo_help *help, int detailed_help) +/** + * Print one of the two given help texts. + * + * \param help contains the help texts. + * \param flags What to print, see \ref ggo_print_help_flags. + */ +void ggo_print_help(struct ggo_help *help, unsigned flags) { const char **p; - if (!help) - return; - if (detailed_help) + if (flags & GPH_PRINT_NAME_VERSION) + printf_or_die("%s\n", version_single_line(help->prefix)); + 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); }