]> git.draconx.ca Git - dxcommon.git/blobdiff - src/help.c
help_print_desc: Allow NULL option to disable localisation.
[dxcommon.git] / src / help.c
index 0ceb8f418fce80bfe166cd681ed52aa1c7d2ac06..b09833a4a1cbd3e0a48e2a436cb087876128dcd7 100644 (file)
@@ -71,6 +71,25 @@ int help_print_optstring(const struct option *opt, const char *argname, int l)
                goto no_translate;
 
        switch (option_type(opt)) {
+#if HELP_GETOPT_LONG_ONLY
+       case OPT_SHORT_WITH_OPTIONAL_ARG:
+       case OPT_LONG_WITH_OPTIONAL_ARG:
+               w = snprintf(optstring, sizeof optstring,
+                            _("  -%s [%s]"), opt->name,
+                            pgettext_expr(opt->name, argname));
+               break;
+       case OPT_SHORT_WITH_MANDATORY_ARG:
+       case OPT_LONG_WITH_MANDATORY_ARG:
+               w = snprintf(optstring, sizeof optstring,
+                            _("  -%s %s"), opt->name,
+                            pgettext_expr(opt->name, argname));
+               break;
+       case OPT_SHORT_WITHOUT_ARG:
+       case OPT_LONG_WITHOUT_ARG:
+               w = snprintf(optstring, sizeof optstring,
+                            _("  -%s"), opt->name);
+               break;
+#else
        case OPT_SHORT_WITH_OPTIONAL_ARG:
                w = snprintf(optstring, sizeof optstring,
                             _("  -%c, --%s[=%s]"), opt->val, opt->name,
@@ -99,6 +118,7 @@ int help_print_optstring(const struct option *opt, const char *argname, int l)
                w = snprintf(optstring, sizeof optstring,
                             _("  --%s"), opt->name);
                break;
+#endif
        default:
                assert(0);
        }
@@ -112,6 +132,20 @@ int help_print_optstring(const struct option *opt, const char *argname, int l)
 
 no_translate:
        switch (option_type(opt)) {
+#if HELP_GETOPT_LONG_ONLY
+       case OPT_SHORT_WITH_OPTIONAL_ARG:
+       case OPT_LONG_WITH_OPTIONAL_ARG:
+               w = printf("  -%s [%s]", opt->name, argname);
+               break;
+       case OPT_SHORT_WITH_MANDATORY_ARG:
+       case OPT_LONG_WITH_MANDATORY_ARG:
+               w = printf("  -%s %s", opt->name, argname);
+               break;
+       case OPT_SHORT_WITHOUT_ARG:
+       case OPT_LONG_WITHOUT_ARG:
+               w = printf("  -%s", opt->name);
+               break;
+#else
        case OPT_SHORT_WITH_OPTIONAL_ARG:
                w = printf("  -%c, --%s[=%s]", opt->val, opt->name, argname);
                break;
@@ -130,6 +164,7 @@ no_translate:
        case OPT_LONG_WITHOUT_ARG:
                w = printf("  --%s", opt->name);
                break;
+#endif
        default:
                assert(0);
        }
@@ -144,7 +179,10 @@ out:
 
 void help_print_desc(const struct option *opt, const char *s, int i, int w)
 {
-       for (s = pgettext_expr(opt->name, s); *s; w = 0) {
+       if (opt)
+               s = pgettext_expr(opt->name, s);
+
+       for (; *s; w = 0) {
                const char *nl = strchr(s, '\n');
                int n = (nl ? nl-s : -1);