X-Git-Url: https://git.draconx.ca/gitweb/dxcommon.git/blobdiff_plain/ac9f1d42b0caa9411e4e8e493c9919c1aaa9ac4f..HEAD:/src/help.c diff --git a/src/help.c b/src/help.c index c537eef..2e6043b 100644 --- a/src/help.c +++ b/src/help.c @@ -1,5 +1,5 @@ /* - * Copyright © 2021-2023 Nick Bowler + * Copyright © 2021-2024 Nick Bowler * * Helper functions for formatting --help program output. * @@ -72,38 +72,44 @@ enum { OPT_SHORT_WITHOUT_ARG = 4, OPT_LONG_WITH_OPTIONAL_ARG = 2, OPT_LONG_WITH_MANDATORY_ARG = 1, - OPT_LONG_WITHOUT_ARG = 0, + OPT_LONG_WITHOUT_ARG = 0 }; #if HELP_GETOPT_LONG_ONLY /* String table generated by gen-strtab.awk from help-glo.str */ #define STRTAB_INITIALIZER \ - N_(" -%s [%s]") \ - "\0" N_(" -%s %s") \ - "\0" N_(" -%s") \ + N_(" -%s [%s]") \ + "\0" "%*s%.*s\n" \ + "\0" N_(" -%s %s") \ + "\0" N_(" -%s") \ "" enum { fmt_long_optional_arg = 0, - fmt_long_mandatory_arg = 11, - fmt_long_without_arg = 20 + fmt_long_mandatory_arg = 19, + fmt_long_without_arg = 27, + fmt_desc = 10, + fmt_nl = 17 }; #else /* String table generated by gen-strtab.awk from help-std.str */ #define STRTAB_INITIALIZER \ - N_(" -%c, --%s[=%s]") \ - "\0" N_(" -%c, --%s=%s") \ - "\0" N_(" --%s[=%s]") \ - "\0" N_(" -%c, --%s") \ - "\0" N_(" --%s=%s") \ - "\0" N_(" --%s") \ + STR_L10N_(N_(" --%s[=%s]")) \ + STR_L10N_(N_(" --%s=%s")) \ + STR_L10N_(N_(" --%s")) \ + N_(" -%c, --%s[=%s]") \ + "\0" N_(" -%c, --%s=%s") \ + "\0" N_(" -%c, --%s") \ + "\0" "%*s%.*s\n" \ "" enum { fmt_short_optional_arg = 0, - fmt_long_optional_arg = 32, - fmt_short_mandatory_arg = 17, - fmt_long_mandatory_arg = 56, - fmt_short_without_arg = 44, - fmt_long_without_arg = 66 + fmt_long_optional_arg = 5, + fmt_short_mandatory_arg = 16, + fmt_long_mandatory_arg = 21, + fmt_short_without_arg = 30, + fmt_long_without_arg = 35, + fmt_desc = 41, + fmt_nl = 48 }; #endif @@ -177,7 +183,7 @@ no_translate: w = printf(fmt, opt->name, argname); } out: - if (w < 0 || w > l) { + if (w <= 0 || w > l) { putchar('\n'); return 0; } @@ -191,9 +197,9 @@ void help_print_desc(const struct option *opt, const char *s, int i, int w) s = pgettext_expr(opt->name, s); do { - size_t n = strcspn(s, "\n"); + size_t n = strcspn(s, &optstr.tab[fmt_nl]); - printf("%*s%.*s\n", n ? i-w : 0, "", (int)n, s); + printf(&optstr.tab[fmt_desc], n ? i-w : 0, "", (int)n, s); s += n + (s[n] != '\0'); w = 0; } while (*s);