]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/opt-help.c
tableprinter: first shot on update of internals
[libucw.git] / ucw / opt-help.c
index 199427d08d4ef77538d7829bcab9481da3b7ea15..64e143949f8cdfe9c2f1a567aa1116b6bc8fa762 100644 (file)
@@ -30,12 +30,12 @@ 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);
-    l->extra = item->help ? : "";
+    l->extra = item->help;
     return;
   }
 
@@ -43,29 +43,27 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
     return;
 
   struct help_line *first = GARY_PUSH(h->lines);
-  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);
+  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) {
@@ -113,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; 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);
     }
   }
@@ -135,13 +133,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) {