From 14cd0a67a3e273db5b28ef786698320bab0962d2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 7 Apr 2017 14:21:19 +0200 Subject: libsmartcols: fix relative width interpretation The non-defined width hint (=0) should not be interpreted as relative width. Signed-off-by: Karel Zak --- libsmartcols/src/table.c | 6 +++--- libsmartcols/src/table_print.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'libsmartcols') 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)")); -- cgit v1.2.3-55-g7522