From: Karel Zak Date: Mon, 4 Jun 2018 13:20:28 +0000 (+0200) Subject: libsmartcols: don't print empty column X-Git-Tag: v2.32.1~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=998f61f9340e32d2b39c55cd346222a6ae52ef76;p=thirdparty%2Futil-linux.git libsmartcols: don't print empty column The commit 0f9f927b6f62cb7f488fadfad76c4a5defdefe36 forces libsmartcols to use one byte as a minimal column width. This seems like a bug if the column is empty and without header. $ printf ':a:b\n' | column -t -s ':' -o ':' :a:b Fixed version: $ printf ':a:b\n' | column -t -s ':' -o ':' :a:b Reported-by: Sami Kerola Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 67e51076ea..8ecfc30e2d 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -1051,7 +1051,7 @@ static int count_column_width(struct libscols_table *tb, { struct libscols_line *ln; struct libscols_iter itr; - int count = 0, rc = 0; + int count = 0, rc = 0, no_header = 0; size_t sum = 0; assert(tb); @@ -1067,7 +1067,9 @@ static int count_column_width(struct libscols_table *tb, if (scols_cell_get_data(&cl->header)) { size_t len = mbs_safe_width(scols_cell_get_data(&cl->header)); cl->width_min = max(cl->width_min, len); - } + } else + no_header = 1; + if (!cl->width_min) cl->width_min = 1; } @@ -1123,6 +1125,11 @@ static int count_column_width(struct libscols_table *tb, cl->width = (size_t) cl->width_hint; + + /* Column without header and data, set minimal size to zero (default is 1) */ + if (cl->width_max == 0 && no_header && cl->width_min == 1 && cl->width <= 1) + cl->width = cl->width_min = 0; + done: ON_DBG(COL, dbg_column(tb, cl)); return rc;