]> git.draconx.ca Git - dxcommon.git/blobdiff - src/help.c
xtra: Avoid undefined ## usage.
[dxcommon.git] / src / help.c
index d1dd5f5bc44055bf50a4599b0e1f24cf15ddc0bf..43bb266d4df4dc8c5dc17ed7519abd49d1bdb088 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021 Nick Bowler
+ * Copyright © 2021-2022 Nick Bowler
  *
  * Helper functions for formatting --help program output.
  *
@@ -28,6 +28,7 @@
 #endif
 
 #if ENABLE_NLS
+#      include <locale.h>
 #      include <gettext.h>
 #      include <mbswidth.h>
 #else
  */
 static int option_type(const struct option *opt)
 {
-       return ((opt->val <= CHAR_MAX) << 2) | (opt->has_arg & 3);
+       int ret = opt->has_arg & 3;
+
+       if (!opt->flag)
+               ret |= (opt->val <= CHAR_MAX) << 2;
+
+       return ret;
 }
 
 enum {
@@ -179,7 +185,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);