top v2.1 fix for RISC Ultrix 3.1/4.0

jim brown jim at mango.miami.edu
Sat Aug 25 14:28:39 AEST 1990


The following patch to top v2.1 was found to be necessary for both
RISC Ultrix 3.1 and 4.0.  Top was treating a normal ASCII tube
(say a vt200 or vt100) as 'dumb' because ws.ws_row was coming back 0.

If the ioctl works and ws.ws_row is 0 then use "li" and "co" to size
the 'dumb'er (but not stupid) terminal.

*** screen.c.orig	Mon Sep  5 22:35:05 1988
--- screen.c	Sat Aug 25 00:19:39 1990
***************
*** 8,13 ****
--- 8,14 ----
  
  #include <stdio.h>
  #include <sgtty.h>
+ #include <errno.h>
  #include "screen.h"
  #include "boolean.h"
  
***************
*** 89,102 ****
  #if defined(TIOCGWINSZ)
      {
          struct winsize ws;
  
!         ioctl(0, TIOCGWINSZ, &ws);
!         if (!(screen_length = ws.ws_row)) {		/* yes I mean "=" */
  		screen_length = smart_terminal = 0;
  		return;
! 	}
!         if (!(screen_width = ws.ws_col - 1)) {		/* uh huh */
  		screen_width = 79;
  	}
      }
  #else
--- 90,132 ----
  #if defined(TIOCGWINSZ)
      {
          struct winsize ws;
+ 	int		stat;
  
! 	stat = ioctl(0, TIOCGWINSZ, &ws);
! 	if (stat != -1 && ws.ws_row == 0) {
! 	    stat = -1; errno = ENOTTY;			/* values no good */
! 	}
! 	if (stat != -1) {
! 	    if (!(screen_length = ws.ws_row)) {		/* yes I mean "=" */
! 		    screen_length = smart_terminal = 0;
! 		    return;
! 	    }
! 	    if (!(screen_width = ws.ws_col - 1)) {	/* uh huh */
! 		    screen_width = 79;
! 	    }
! 	}
! 	else if (errno == ENOTTY) {
! 	    /* set up common terminal capabilities */
! 	    if ((screen_length = tgetnum("li")) <= 0)
! 	    {
  		screen_length = smart_terminal = 0;
  		return;
! 	    }
! 
! 	    /* screen_width is a little different */
! 	    if ((screen_width = tgetnum("co")) == -1)
! 	    {
  		screen_width = 79;
+ 	    }
+ 	    else
+ 	    {
+ 		screen_width -= 1;
+ 	    }
+ 	}
+ 	else {
+ 	    fprintf("Can't ioctl TTY: %d\n", errno);
+ 	    screen_length = smart_terminal = 0;
+ 	    return;
  	}
      }
  #else

=========== end of patch for screen.c ============
--
Jim Brown, University of Miami, RSMAS/MPO
[send mail to jim at umigw.miami.edu]



More information about the Comp.sources.bugs mailing list