diff options
author | 2000-01-06 21:32:40 +0000 | |
---|---|---|
committer | 2000-01-06 21:32:40 +0000 | |
commit | b60c9e496be96ccc0ef79de355d740912bc2ff2a (patch) | |
tree | d1e56dc27d357b34d5f07bd68757d806305b4b41 /bin/ls/print.c | |
parent | use everything in libc_r (sorry, todd) (diff) | |
download | wireguard-openbsd-b60c9e496be96ccc0ef79de355d740912bc2ff2a.tar.xz wireguard-openbsd-b60c9e496be96ccc0ef79de355d740912bc2ff2a.zip |
In multi-column output, don't bother filling up last column before '\n'.
As a result, we gain one extra position to format multi-column output,
since there is no added space at the end of the last column. For instance,
26 long filenames now print in 3 columns instead of 2.
At first, both millert@ and I thought that ending the line on the last
column might trigger trouble on some terminals, but then I realized that
current ls may already fill the last column with a space, with no apparent
grief anywhere, and Todd agreed.
Diffstat (limited to 'bin/ls/print.c')
-rw-r--r-- | bin/ls/print.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c index 345fc42925c..c02aa56c843 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.14 2000/01/05 16:02:11 espie Exp $ */ +/* $OpenBSD: print.c,v 1.15 2000/01/06 21:32:40 espie Exp $ */ /* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94"; #else -static char rcsid[] = "$OpenBSD: print.c,v 1.14 2000/01/05 16:02:11 espie Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.15 2000/01/06 21:32:40 espie Exp $"; #endif #endif /* not lint */ @@ -144,6 +144,7 @@ compute_columns(dp, pnum) { int colwidth; extern int termwidth; + int mywidth; colwidth = dp->maxlen; if (f_inode) @@ -154,14 +155,15 @@ compute_columns(dp, pnum) colwidth += 1; colwidth += 1; + mywidth = termwidth + 1; /* no extra space for last column */ - if (termwidth < 2 * colwidth) { + if (mywidth < 2 * colwidth) { printscol(dp); return (0); } - *pnum = termwidth / colwidth; - return (termwidth / *pnum); /* spread out if possible */ + *pnum = mywidth / colwidth; + return (mywidth / *pnum); /* spread out if possible */ } void @@ -176,7 +178,6 @@ printcol(dp) if ( (colwidth = compute_columns(dp, &numcols)) == 0) return; - /* * Have to do random access in the linked list -- build a table * of pointers. @@ -204,10 +205,12 @@ printcol(dp) if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); for (row = 0; row < numrows; ++row) { - for (base = row, col = 0; col < numcols; ++col) { + for (base = row, col = 0;;) { chcnt = printaname(array[base], dp->s_inode, dp->s_block); if ((base += numrows) >= num) break; + if (++col == numcols) + break; while (chcnt++ < colwidth) putchar(' '); } @@ -285,13 +288,14 @@ printacol(dp) if (IS_NOPRINT(p)) continue; if (col >= numcols) { - chcnt = col = 0; + col = 0; (void)putchar('\n'); } chcnt = printaname(p, dp->s_inode, dp->s_block); - while (chcnt++ < colwidth) - (void)putchar(' '); col++; + if (col < numcols) + while (chcnt++ < colwidth) + (void)putchar(' '); } (void)putchar('\n'); } |