X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Fopt-help.c;h=64e143949f8cdfe9c2f1a567aa1116b6bc8fa762;hb=0fb5afd0064da21f5c11c08ee8ad69319f63242a;hp=5c4b44e850f7d94a4902130122ecc9de178a3220;hpb=924caf6f42990dc99c1d7e4a954da1533e37e537;p=libucw.git diff --git a/ucw/opt-help.c b/ucw/opt-help.c index 5c4b44e8..64e14394 100644 --- a/ucw/opt-help.c +++ b/ucw/opt-help.c @@ -30,42 +30,40 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt) { struct opt_item *item = opt->item; - if (opt->flags & OPT_NO_HELP) + if (!item->help) return; if (item->cls == OPT_CL_HELP) { - struct help_line *l = GARY_PUSH(h->lines, 1); - l->extra = item->help ? : ""; + struct help_line *l = GARY_PUSH(h->lines); + l->extra = item->help; return; } if (item->letter >= OPT_POSITIONAL_TAIL) return; - struct help_line *first = GARY_PUSH(h->lines, 1); - if (item->help) { - char *text = mp_strdup(h->pool, item->help); - struct help_line *l = first; - while (text) { - char *eol = strchr(text, '\n'); - if (eol) - *eol++ = 0; - - int field = (l == first ? 1 : 0); - char *f = text; - while (f) { - char *tab = strchr(f, '\t'); - if (tab) - *tab++ = 0; - if (field < 3) - l->fields[field++] = f; - f = tab; - } - - text = eol; - if (text) - l = GARY_PUSH(h->lines, 1); + struct help_line *first = GARY_PUSH(h->lines); + char *text = mp_strdup(h->pool, item->help); + struct help_line *l = first; + while (text) { + char *eol = strchr(text, '\n'); + if (eol) + *eol++ = 0; + + int field = (l == first ? 1 : 0); + char *f = text; + while (f) { + char *tab = strchr(f, '\t'); + if (tab) + *tab++ = 0; + if (field < 3) + l->fields[field++] = f; + f = tab; } + + text = eol; + if (text) + l = GARY_PUSH(h->lines); } if (item->name) { @@ -95,6 +93,8 @@ static void opt_help_scan(struct help *h, const struct opt_section *sec) for (struct opt_item * item = sec->opt; item->cls != OPT_CL_END; item++) { if (item->cls == OPT_CL_SECTION) opt_help_scan(h, item->u.section); + else if (item->cls == OPT_CL_HOOK) + ; else { struct opt_precomputed opt; opt_precompute(&opt, item); @@ -111,14 +111,14 @@ void opt_help(const struct opt_section * sec) { opt_help_scan(&h, sec); // Calculate natural width of each column - uns n = GARY_SIZE(h.lines); - uns widths[3] = { 0, 0, 0 }; - for (uns i=0; ifields[f]) l->fields[f] = ""; - uns w = strlen(l->fields[f]); + uint w = strlen(l->fields[f]); widths[f] = MAX(widths[f], w); } } @@ -133,13 +133,13 @@ void opt_help(const struct opt_section * sec) { widths[1] += 4; // Print columns - for (uns i=0; iextra) puts(l->extra); else { int t = 0; - for (uns f=0; f<3; f++) { + for (uint f=0; f<3; f++) { t += widths[f]; t -= printf("%s", l->fields[f]); while (t > 0) { @@ -158,6 +158,7 @@ void opt_help(const struct opt_section * sec) { void opt_handle_help(struct opt_item * opt UNUSED, const char * value UNUSED, void * data) { - opt_help(data); + struct opt_context *oc = data; + opt_help(oc->options); exit(0); }