From 959566090f98dd31eaa67d3d5959b641e5fe902b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 27 Jun 2014 17:50:47 +0200 Subject: [PATCH] Opt: Added OPT_HELP_COLUMNS --- ucw/opt-help.c | 13 +++++++++---- ucw/opt.h | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ucw/opt-help.c b/ucw/opt-help.c index f71fec14..fdd3ec74 100644 --- a/ucw/opt-help.c +++ b/ucw/opt-help.c @@ -33,10 +33,15 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt) if (!item->help) return; + bool force_col1 = 0; if (item->cls == OPT_CL_HELP) { - struct help_line *l = GARY_PUSH(h->lines); - l->extra = item->help; - return; + if (item->flags & OPT_HELP_COL) { + force_col1 = 1; + } else { + struct help_line *l = GARY_PUSH(h->lines); + l->extra = item->help; + return; + } } if (item->letter >= OPT_POSITIONAL_TAIL) @@ -50,7 +55,7 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt) if (eol) *eol++ = 0; - int field = (l == first ? 1 : 0); + int field = (l == first && !force_col1 ? 1 : 0); char *f = text; while (f) { char *tab = strchr(f, '\t'); diff --git a/ucw/opt.h b/ucw/opt.h index 3f1be812..20df7fd7 100644 --- a/ucw/opt.h +++ b/ucw/opt.h @@ -134,6 +134,7 @@ struct opt_item { #define OPT_MULTIPLE 0x200 /** The option may appear multiple times; will save all the values into a simple list. **/ #define OPT_SEEN_AS_LONG 0x400 // Used internally to signal that we currently process the long form of the option #define OPT_BEFORE_CONFIG 0x800 /** The option may appear before a config file is loaded. **/ +#define OPT_HELP_COL 0x1000 /** Used for OPT_CL_HELP to signal that tabs switch columns. **/ #define OPT_INTERNAL 0x4000 // Used internally to ask for passing of struct opt_context to OPT_CALL /** @@ -161,6 +162,9 @@ struct opt_item { /** No option, just a piece of help text. **/ #define OPT_HELP(line) { .help = line, .cls = OPT_CL_HELP } +/** Like OPT_HELP, but the help text uses tab characters to switch columns like help text for ordinary options does. **/ +#define OPT_HELP_COLUMNS(line) { .help = line, .flags = OPT_HELP_COL, .cls = OPT_CL_HELP } + /** Standard `--help` option. **/ #define OPT_HELP_OPTION OPT_CALL(0, "help", opt_handle_help, NULL, OPT_BEFORE_CONFIG | OPT_INTERNAL | OPT_NO_VALUE, "\tShow this help") -- 2.39.5