]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: don't mark as extreme where average is zero
authorKarel Zak <kzak@redhat.com>
Thu, 23 Aug 2018 08:13:17 +0000 (10:13 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Aug 2018 08:13:17 +0000 (10:13 +0200)
The columns with NOEXTREME flag are internally marked as extreme
(=contains extreme width) if maximal with is greater than 2 *
average_width. This detection has to sure that the average is non-zero
otherwise the column is always "extreme".

Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/column.c
libsmartcols/src/table_print.c

index e9d6dc4041590af3f2c935e93684bb2efdfea0c1..53521f6adc85395dfccaa1d4184514cb17777a23 100644 (file)
@@ -167,6 +167,7 @@ int scols_column_set_flags(struct libscols_column *cl, int flags)
                        cl->table->ntreecols--;
        }
 
+       DBG(COL, ul_debugobj(cl, "setting flags from 0%x to 0%x", cl->flags, flags));
        cl->flags = flags;
        return 0;
 }
index ae8d2da1cc90a7bf51659e66a3fb419af820c580..a15bf90e341993aa5481277e273a2763042cfeed 100644 (file)
@@ -1067,8 +1067,8 @@ static int count_column_width(struct libscols_table *tb,
 {
        struct libscols_line *ln;
        struct libscols_iter itr;
-       int count = 0, rc = 0, no_header = 0;
-       size_t sum = 0;
+       int extreme_count = 0, rc = 0, no_header = 0;
+       size_t extreme_sum = 0;
 
        assert(tb);
        assert(cl);
@@ -1112,11 +1112,11 @@ static int count_column_width(struct libscols_table *tb,
                        len = 0;
                cl->width_max = max(len, cl->width_max);
 
-               if (cl->is_extreme && len > cl->width_avg * 2)
+               if (cl->is_extreme && cl->width_avg && len > cl->width_avg * 2)
                        continue;
                else if (scols_column_is_noextremes(cl)) {
-                       sum += len;
-                       count++;
+                       extreme_sum += len;
+                       extreme_count++;
                }
                cl->width = max(len, cl->width);
                if (scols_column_is_tree(cl)) {
@@ -1125,9 +1125,9 @@ static int count_column_width(struct libscols_table *tb,
                }
        }
 
-       if (count && cl->width_avg == 0) {
-               cl->width_avg = sum / count;
-               if (cl->width_max > cl->width_avg * 2)
+       if (extreme_count && cl->width_avg == 0) {
+               cl->width_avg = extreme_sum / extreme_count;
+               if (cl->width_avg && cl->width_max > cl->width_avg * 2)
                        cl->is_extreme = 1;
        }