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/06/2006 20:05:03
The following reply was made to PR bin/34717; it has been noted by GNATS.

From: Alan Barrett <apb@cequrux.com>
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
Cc: gnats-bugs@NetBSD.org
Subject: Re: bin/34717: [dM] top demands termcap entry with li#
Date: Fri, 6 Oct 2006 22:03:19 +0200

 On Thu, 05 Oct 2006, der Mouse wrote:
 > > Please try the attached patch, which tries to get the size from ioctl
 > > TIOCGWINSZ or similar before falling back to the size from termcap.
 > 
 > Seems to work as far as basic display goes, though when I type q to
 > exit the resulting binary, rather than the cursor going to the lower
 > left and getting my prompt, it prints "no fmt" where it was on the
 > sixth line of the screen and then gives me my prompt (still on the
 > sixth line of the screen).
 
 lower_left is not set properly.  Hmm, cursor_motion was not yet set when
 get_screensize() tried to set lower_left; I think that explains it.
 
 Here's a new patch, relative to -current.
 
 Index: src/usr.bin/top/screen.c
 ===================================================================
 --- screen.c	23 Jun 2003 13:05:53 -0000	1.8
 +++ screen.c	6 Oct 2006 19:58:00 -0000
 @@ -174,21 +174,30 @@
  	return;
      }
  
 -    /* set up common terminal capabilities */
 -    if ((screen_length = t_getnum(info, "li")) <= 0)
 -    {
 -	screen_length = smart_terminal = 0;
 -	return;
 -    }
 +    /* set screen_width and screen_length from an ioctl, if possible. */
 +    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 */
 @@ -221,12 +230,8 @@
      /* set convenience strings */
      home[0] = '\0';
      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();
 +    lower_left[0] = '\0';
 +    t_goto(info, cursor_motion, 0, screen_length - 1, lower_left, 14);
  
      /* if stdout is not a terminal, pretend we are a dumb terminal */
  #ifdef SGTTY
 @@ -439,8 +444,6 @@
  
  #endif /* TIOCGSIZE */
  #endif /* TIOCGWINSZ */
 -    lower_left[0] = '\0';
 -    t_goto(info, cursor_motion, 0, screen_length - 1, lower_left, 14);
  }
  
  void