summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2017-04-07 14:21:19 +0200
committerKarel Zak2017-04-07 14:34:11 +0200
commit14cd0a67a3e273db5b28ef786698320bab0962d2 (patch)
tree07632b69ebbed7d2007bd9c8c1b2550fb67e2711 /libsmartcols
parentlibsmartcols: column width reduction refactoring (diff)
downloadkernel-qcow2-util-linux-14cd0a67a3e273db5b28ef786698320bab0962d2.tar.gz
kernel-qcow2-util-linux-14cd0a67a3e273db5b28ef786698320bab0962d2.tar.xz
kernel-qcow2-util-linux-14cd0a67a3e273db5b28ef786698320bab0962d2.zip
libsmartcols: fix relative width interpretation
The non-defined width hint (=0) should not be interpreted as relative width. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/table.c6
-rw-r--r--libsmartcols/src/table_print.c4
2 files changed, 5 insertions, 5 deletions
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c
index 066a1e9a7..a67028d43 100644
--- a/libsmartcols/src/table.c
+++ b/libsmartcols/src/table.c
@@ -306,7 +306,7 @@ int scols_table_move_column(struct libscols_table *tb,
* scols_table_new_column:
* @tb: table
* @name: column header
- * @whint: column width hint (absolute width: N > 1; relative width: N < 1)
+ * @whint: column width hint (absolute width: N > 1; relative width: 0 < N < 1)
* @flags: flags integer
*
* This is shortcut for
@@ -317,9 +317,9 @@ int scols_table_move_column(struct libscols_table *tb,
*
* The column width is possible to define by:
*
- * @whint = 0..1 : relative width, percent of terminal width
+ * @whint: 0 < N < 1 : relative width, percent of terminal width
*
- * @whint = 1..N : absolute width, empty column will be truncated to
+ * @whint: N >= 1 : absolute width, empty column will be truncated to
* the column header width if no specified STRICTWIDTH flag
*
* Note that if table has disabled "maxout" flag (disabled by default) than
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 6b4b727c0..2377a0063 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -1270,7 +1270,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
case 1:
if (!trunc_flag) /* ignore: missing flag */
break;
- if (cl->width_hint >= 1) /* ignore: no relative */
+ if (cl->width_hint <= 0 || cl->width_hint >= 1) /* ignore: no relative */
break;
if (cl->width < (size_t) (cl->width_hint * tb->termwidth)) /* ignore: smaller than expected width */
break;
@@ -1292,7 +1292,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
/* #3 stage - trunc relative without flag */
case 3:
- if (cl->width_hint >= 1) /* ignore: no relative */
+ if (cl->width_hint <= 0 || cl->width_hint >= 1) /* ignore: no relative */
break;
DBG(TAB, ul_debugobj(tb, " reducing (relative without flag)"));