summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2018-08-23 10:13:17 +0200
committerKarel Zak2018-08-23 10:13:17 +0200
commit369be41bcd1240684d21535873910739fa74e298 (patch)
tree933e14cabec3ae2933bfaa1506b2dd3cd8f2b11d /libsmartcols
parentlibsmartcols: allow to add line to table without columns (diff)
downloadkernel-qcow2-util-linux-369be41bcd1240684d21535873910739fa74e298.tar.gz
kernel-qcow2-util-linux-369be41bcd1240684d21535873910739fa74e298.tar.xz
kernel-qcow2-util-linux-369be41bcd1240684d21535873910739fa74e298.zip
libsmartcols: don't mark as extreme where average is zero
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>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/column.c1
-rw-r--r--libsmartcols/src/table_print.c16
2 files changed, 9 insertions, 8 deletions
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index e9d6dc404..53521f6ad 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -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;
}
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index ae8d2da1c..a15bf90e3 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -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;
}