NetBSD Problem Report #2965

Received: (qmail-queue invoked from smtpd); 26 Nov 1996 12:48:47 -0000
Message-Id: <m0vSMtp-00008uC@druid.druid.com>
Date: Tue, 26 Nov 1996 07:46:05 -0500 (EST)
From: darcy@druid.com
Reply-To: darcy@druid.com
To: gnats-bugs@gnats.netbsd.org,darcy@druid.com
Subject: Layout of ls wide listing
X-Send-Pr-Version: 3.95

>Number:         2965
>Category:       bin
>Synopsis:       Sometimes ls won't line up evenly.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 26 04:50:00 +0000 1996
>Closed-Date:    Wed Dec 11 03:23:34 +0000 1996
>Last-Modified:  Wed Dec 11 03:25:49 +0000 1996
>Originator:     D'Arcy J.M. Cain
>Release:        NetBSD-current
>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  --                       
>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');
  	}
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: thorpej 
State-Changed-When: Tue Dec 10 19:23:34 PST 1996 
State-Changed-Why:  
Patch applied.  Thanks! 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.