Subject: Re: bin/34717: [dM] top demands termcap entry with li#
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,>
From: Alan Barrett <apb@cequrux.com>
List: netbsd-bugs
Date: 10/05/2006 21:10:08
The following reply was made to PR bin/34717; it has been noted by GNATS.

From: Alan Barrett <apb@cequrux.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/34717: [dM] top demands termcap entry with li#
Date: Thu, 5 Oct 2006 23:07:10 +0200

 > >Description:
 > 	top(1) demands that the termcap entry for $TERM contain a li#
 > 	attribute, or it considers the terminal "dumb", even when stty
 > 	size holds a perfectly good size and there is no other reason
 > 	to treat it as dumb.
 
 Please try the attached patch, which tries to get the size from ioctl
 TIOCGWINSZ or similar before falling back to the size from termcap.
 
 --apb (Alan Barrett)
 
 Index: src/usr.bin/top/screen.c
 --- screen.c	23 Jun 2003 13:05:53 -0000	1.8
 +++ screen.c	5 Oct 2006 21:02:49 -0000
 @@ -174,21 +174,32 @@
  	return;
      }
  
 -    /* set up common terminal capabilities */
 -    if ((screen_length = t_getnum(info, "li")) <= 0)
 -    {
 -	screen_length = smart_terminal = 0;
 -	return;
 -    }
 +    /* get the actual screen size with an ioctl, if needed */
 +    /* This may change screen_width and screen_length, and it always
 +       sets lower_left. */
 +    get_screensize();
  
 +    /* get size from terminal capabilities if not yet set properly. */
      /* screen_width is a little different */
 -    if ((screen_width = t_getnum(info, "co")) == -1)
 +    if (screen_width < 0)
      {
 -	screen_width = 79;
 +	if ((screen_width = t_getnum(info, "co")) == -1)
 +	{
 +	    screen_width = 79;
 +	}
 +	else
 +	{
 +	    screen_width -= 1;
 +	}
      }
 -    else
 +
 +    if (screen_length <= 0)
      {
 -	screen_width -= 1;
 +	if ((screen_length = t_getnum(info, "li")) <= 0)
 +	{
 +	    screen_length = smart_terminal = 0;
 +	    return;
 +	}
      }
  
      /* terminals that overstrike need special attention */
 @@ -223,11 +234,6 @@
      t_goto(info, cursor_motion, 0, 0, home, 14);
      /* (lower_left is set in get_screensize) */
  
 -    /* get the actual screen size with an ioctl, if needed */
 -    /* This may change screen_width and screen_length, and it always
 -       sets lower_left. */
 -    get_screensize();
 -
      /* if stdout is not a terminal, pretend we are a dumb terminal */
  #ifdef SGTTY
      if (ioctl(STDOUT, TIOCGETP, &old_settings) == -1)
 Index: src/usr.bin/top/screen.h
 --- screen.h	16 Jul 2002 00:40:51 -0000	1.6
 +++ screen.h	5 Oct 2006 21:02:49 -0000
 @@ -56,7 +56,7 @@
  extern char *clear_line;
  extern char *clear_to_end;
  
 -/* rows and columns on the screen according to termcap */
 +/* rows and columns on the screen according to termcap or ioctl */
  extern int  screen_length;
  extern int  screen_width;