Subject: bin/2965: Layout of ls wide listing
To: None <gnats-bugs@gnats.netbsd.org, darcy@druid.com>
From: None <darcy@druid.com>
List: netbsd-bugs
Date: 11/26/1996 07:46:05
>Number: 2965
>Category: bin
>Synopsis: Sometimes ls won't line up evenly.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Nov 26 04:50:00 1996
>Last-Modified:
>Originator: D'Arcy J.M. Cain
>Organization:
D'Arcy J.M. Cain | Democracy is three wolves
darcy@{druid.com|vex.net} | and a sheep voting on
+1 416 943 5281 (DoD#0082) (eNTP) | what's for dinner.
-- http://www.druid.com/darcy --
>Release: NetBSD-current
>Environment:
System: NetBSD druid.com 1.2B NetBSD 1.2B (DRUID) #0: Sun Nov 24 10:11:21 EST 1996 darcy@druid.com:/usr/src/sys/arch/i386/compile/DRUID i386
>Description:
It is possible for the tty to get into a state where it doesn't handle
tabs correctly. When that happens a wide ls can display unevenly.
>How-To-Repeat:
This is tricky to repeat. It happens with a quircky combination of
stty settings and length of filenames. Try "stty -tabs" and a directory
where the first filename is less than 8 characters. I realize that
the terminal should be set correctly but sometimes it isn't and having
the system do the write thing anyway seems like a good idea. As a
side benefit, my fixes below will sometimes make a shorter listing
by allowing an extra column. It spreads the listing across the screen
as evenly and as tightly as possible. I find that this generally is
suitable for any listing I do.
>Fix:
*** ../src.original/./bin/ls/print.c Mon Nov 18 18:01:16 1996
--- ./bin/ls/print.c Fri Sep 8 05:08:08 1995
***************
*** 135,142 ****
}
}
- #define TAB 8
-
void
printcol(dp)
DISPLAY *dp;
--- 135,140 ----
***************
*** 146,152 ****
static int lastentries = -1;
FTSENT *p;
int base, chcnt, cnt, col, colwidth, num;
! int endcol, numcols, numrows, row;
/*
* Have to do random access in the linked list -- build a table
--- 144,150 ----
static int lastentries = -1;
FTSENT *p;
int base, chcnt, cnt, col, colwidth, num;
! int numcols, numrows, row;
/*
* Have to do random access in the linked list -- build a table
***************
*** 172,184 ****
if (f_type)
colwidth += 1;
! colwidth = (colwidth + TAB) & ~(TAB - 1);
if (termwidth < 2 * colwidth) {
printscol(dp);
return;
}
numcols = termwidth / colwidth;
numrows = num / numcols;
if (num % numcols)
++numrows;
--- 170,184 ----
if (f_type)
colwidth += 1;
! colwidth += 1;
!
if (termwidth < 2 * colwidth) {
printscol(dp);
return;
}
numcols = termwidth / colwidth;
+ colwidth = termwidth / numcols; /* spread out if possible */
numrows = num / numcols;
if (num % numcols)
++numrows;
***************
*** 186,202 ****
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) {
- endcol = colwidth;
for (base = row, chcnt = col = 0; col < numcols; ++col) {
! chcnt += printaname(array[base], dp->s_inode,
! dp->s_block);
if ((base += numrows) >= num)
break;
! while ((cnt = (chcnt + TAB & ~(TAB - 1))) <= endcol) {
! (void)putchar('\t');
! chcnt = cnt;
! }
! endcol += colwidth;
}
(void)putchar('\n');
}
--- 186,197 ----
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, chcnt = col = 0; col < numcols; ++col) {
! chcnt = printaname(array[base], dp->s_inode, dp->s_block);
if ((base += numrows) >= num)
break;
! while (chcnt++ < colwidth)
! putchar(' ');
}
(void)putchar('\n');
}
>Audit-Trail:
>Unformatted: