]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/opt-help.c
Redblack: Added search_up
[libucw.git] / ucw / opt-help.c
index 74ea18b2185373c055a91c07b61f1e47bbc44e66..fdd3ec74108a9e5d543431de306a7c7a500b2c55 100644 (file)
@@ -28,15 +28,20 @@ struct help_line {
 
 static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
 {
-  struct opt_item *item = opt->item;
+  const struct opt_item *item = opt->item;
 
   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');
@@ -90,7 +95,7 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
 
 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++) {
+  for (const 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)
@@ -111,14 +116,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; i<n; i++) {
+  uint n = GARY_SIZE(h.lines);
+  uint widths[3] = { 0, 0, 0 };
+  for (uint i=0; i<n; i++) {
     struct help_line *l = &h.lines[i];
-    for (uns f=0; f<3; f++) {
+    for (uint f=0; f<3; f++) {
       if (!l->fields[f])
        l->fields[f] = "";
-      uns w = strlen(l->fields[f]);
+      uint w = strlen(l->fields[f]);
       widths[f] = MAX(widths[f], w);
     }
   }
@@ -133,13 +138,13 @@ void opt_help(const struct opt_section * sec) {
   widths[1] += 4;
 
   // Print columns
-  for (uns i=0; i<n; i++) {
+  for (uint i=0; i<n; i++) {
     struct help_line *l = &h.lines[i];
     if (l->extra)
       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) {
@@ -156,7 +161,7 @@ void opt_help(const struct opt_section * sec) {
   mp_delete(h.pool);
 }
 
-void opt_handle_help(struct opt_item * opt UNUSED, const char * value UNUSED, void * data)
+void opt_handle_help(const struct opt_item * opt UNUSED, const char * value UNUSED, void * data)
 {
   struct opt_context *oc = data;
   opt_help(oc->options);