#include "private.h"
/* We only use this for pointer comparisons. */
-const char opt_table_hidden[1];
+const char opt_hidden[1];
static unsigned write_short_options(char *str)
{
unsigned int i, num = 0;
+ const char *p;
- for (i = 0; i < opt_count; i++) {
- if (opt_table[i].flags == OPT_SUBTABLE) {
- if (opt_table[i].desc == opt_table_hidden) {
- /* Skip these options. */
- i += (intptr_t)opt_table[i].arg - 1;
- continue;
- }
- } else if (opt_table[i].shortopt)
- str[num++] = opt_table[i].shortopt;
+ for (p = first_sopt(&i); p; p = next_sopt(p, &i)) {
+ if (opt_table[i].desc != opt_hidden)
+ str[num++] = *p;
}
return num;
}
/* An overestimate of our length. */
len = strlen("Usage: %s ") + strlen(argv0)
- + strlen("[-%.*s]") + opt_count + 1
+ + strlen("[-%.*s]") + opt_num_short + 1
+ strlen(" ") + strlen(extra)
+ strlen("\n");
if (opt_table[i].flags == OPT_SUBTABLE) {
len += strlen("\n") + strlen(opt_table[i].desc)
+ strlen(":\n");
- } else {
- len += strlen("--%s/-%c") + strlen(" <arg>");
- if (opt_table[i].longopt)
- len += strlen(opt_table[i].longopt);
+ } else if (opt_table[i].desc != opt_hidden) {
+ len += strlen(opt_table[i].names) + strlen(" <arg>");
if (opt_table[i].desc) {
len += strlen(OPT_SPACE_PAD)
+ strlen(opt_table[i].desc) + 1;
p += sprintf(p, "\n");
for (i = 0; i < opt_count; i++) {
+ if (opt_table[i].desc == opt_hidden)
+ continue;
if (opt_table[i].flags == OPT_SUBTABLE) {
- if (opt_table[i].desc == opt_table_hidden) {
- /* Skip these options. */
- i += (intptr_t)opt_table[i].arg - 1;
- continue;
- }
p += sprintf(p, "%s:\n", opt_table[i].desc);
continue;
}
- if (opt_table[i].shortopt && opt_table[i].longopt)
- len = sprintf(p, "--%s/-%c",
- opt_table[i].longopt,
- opt_table[i].shortopt);
- else if (opt_table[i].shortopt)
- len = sprintf(p, "-%c", opt_table[i].shortopt);
- else
- len = sprintf(p, "--%s", opt_table[i].longopt);
+ len = sprintf(p, "%s", opt_table[i].names);
if (opt_table[i].flags == OPT_HASARG)
len += sprintf(p + len, " <arg>");
if (opt_table[i].desc || opt_table[i].show)