]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: fix relative width interpretation
authorKarel Zak <kzak@redhat.com>
Fri, 7 Apr 2017 12:21:19 +0000 (14:21 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Apr 2017 12:34:11 +0000 (14:34 +0200)
The non-defined width hint (=0) should not be interpreted as relative width.

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

index 066a1e9a74801fe73a77e075d6a481351d10ebfe..a67028d4372533a4cb8bad7608e88f8f16026c60 100644 (file)
@@ -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
index 6b4b727c0d3c4fd96fe864d39aca0287c9e1ec01..2377a0063adc623bfea45c2ab97d5fc99db0877d 100644 (file)
@@ -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)"));