]> mj.ucw.cz Git - libucw.git/commitdiff
Opt: Added OPT_HELP_COLUMNS
authorMartin Mares <mj@ucw.cz>
Fri, 27 Jun 2014 15:50:47 +0000 (17:50 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 27 Jun 2014 15:50:47 +0000 (17:50 +0200)
ucw/opt-help.c
ucw/opt.h

index f71fec14d93bef28eafaeadcc8c6f8982e1be9d7..fdd3ec74108a9e5d543431de306a7c7a500b2c55 100644 (file)
@@ -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');
index 3f1be8127511327eeb8b9ba0c5b36ffdf1f1b3cd..20df7fd7b340d5277c4e34ed175d2b39988c8b36 100644 (file)
--- 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")