libtabular-c

C tabular formatting library
git clone https://git.sinitax.com/sinitax/libtabular-c
Log | Files | Refs | Submodules | sfeed.txt

commit cf78bbc8205688626487cb15f83aa351a6f07864
parent c8a02eac6a5c17087b5f0c64f4b3d732bb16649b
Author: Louis Burda <quent.burda@gmail.com>
Date:   Tue,  6 Jun 2023 02:11:11 +0200

Fix col calculation for cfgs with hseplen != 1

Diffstat:
Msrc/tabular.c | 14+++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/tabular.c b/src/tabular.c @@ -40,7 +40,7 @@ static void calc_word_aware(struct tabular_entry *entry, size_t maxwidth, static size_t recalc_col_word_aware(const struct tabular_cfg *cfg, struct tabular_row *rows, size_t limit, size_t col, size_t maxwidth, size_t remaining); -static size_t calc_row_width(struct col_state *cols, size_t count); +static size_t calc_row_width(struct fmt_state *fmt); static size_t calc_output_lines(const struct tabular_cfg *cfg, struct fmt_state *fmt, struct tabular_row *rows, size_t limit); static bool recalc_cols(const struct tabular_cfg *cfg, @@ -157,14 +157,14 @@ recalc_col_word_aware(const struct tabular_cfg *cfg, } size_t -calc_row_width(struct col_state *cols, size_t count) +calc_row_width(struct fmt_state *fmt) { size_t sum, i; sum = 0; - for (i = 0; i < count; i++) { - if (cols[i].hidden) continue; - sum += cols[i].width + (sum ? 1 : 0); + for (i = 0; i < fmt->column_count; i++) { + if (fmt->columns[i].hidden) continue; + sum += fmt->columns[i].width + (sum ? fmt->hseplen : 0); } return sum; @@ -228,7 +228,7 @@ recalc_cols(const struct tabular_cfg *cfg, struct tabular_stats *stats, } /* could not fit all necessary columns at minimum width */ - width = calc_row_width(fmt->columns, fmt->column_count); + width = calc_row_width(fmt); while (width > fullwidth) { /* remove non-essential columns */ for (i = cfg->column_count - 1; i >= 0; i--) { @@ -243,7 +243,7 @@ recalc_cols(const struct tabular_cfg *cfg, struct tabular_stats *stats, if (i < 0) return false; stats->cols_truncated = true; - width = calc_row_width(fmt->columns, fmt->column_count); + width = calc_row_width(fmt); } /* redistribute excess width to columns, left to right */