From df6aaa39fbf7baa82e27e7eb83673629284966d0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 12 Nov 2019 08:53:29 -0600 Subject: Replace a test I took out last commit because it seemed impossible to trigger, but the problem is some vertical sort arrangements are impossible, and that's what it was testing for. For example, showing 29 entries in 9 columns with horizontal sort requires 4 rows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 29 x x x x x x x But with vertical sort that would be: 1 5 9 13 17 21 25 29 x 2 6 10 14 18 22 26 x x 3 7 11 15 19 23 27 x x 4 8 12 16 20 24 28 x x It still doesn't fit in 3 rows (3x9=27) but with 4 rows the 7 leftover spaces eats a whole column, so you _can't_ have 9 columns with vertical sort. --- toys/posix/ls.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 9d282acc..8bf9f693 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -356,13 +356,14 @@ static void listfiles(int dirfd, struct dirtree *indir) // Try to fit as many columns as we can, dropping down by one each time for (;columns > 1; columns--) { - unsigned c, totlen = columns; + unsigned c, cc, totlen = columns; memset(colsizes, 0, columns*sizeof(unsigned)); for (ul = 0; ul=dtlen) break; // tilt: remainder bigger than height + entrylen(sort[cc], len); + if (c colsizes[c]) { totlen += (*len)-colsizes[c]; -- cgit v1.2.3