[comp.bugs.sys5] Nethack Problems

guy%gorodish@Sun.COM (Guy Harris) (08/11/87)

>  I have nethack working fine on our BSD system. However in trying
> to make it work on our 3b2/310 running system V I always get
> "Terminal must Backspace" in trying to run nethack.  I use vt100
> for my terminal type. Is it a problem with the terminal library

Probably.

> if so what terminal library did you other sysV users use. 

One with the problem fixed.

The trick here is that the part of the "curses" library that's being used is
the part that emulates the old "termcap" routines.  "nethack" is checking the
"bs" capability; this capability has no direct equivalent in "terminfo".  To
determine whether it should say the "bs" capability is present or not, the
emulation library looks at the "cub1" capability; if it is the string "\b", it
says that the "bs" capability is present, otherwise it doesn't.

The version distributed with the VAX S5R2 just looks directly at the
capability; if there are any delays in the string, it says "this string is not
just a backspace, so this terminal can't backspace".  The "cub1" capability in
the S5R2 "terminfo" entry for the VT100 has no delays, so that version may
work.)

The S5R3 and S5R3.1 versions fix the problem by stripping the delays;
unfortunately, the fix has a bug.  There is a routine "stripdelay" (in the S5R3
version) or "_stripdelay" (in the S5R3.1 version) that makes a copy of a
capability string after stripping all delays out.  Unfortunately, it doesn't
properly null-terminate the string.  These versions run the risk of screwing up
even if "cub1" has no delays in it.

I don't know if the 3B2 S5R2 has the same "terminfo" or "curses" that the VAX
S5R2 does; if it has a later version, this bug may exist in the 3B2 S5R2.

Here's the fix to the S5R3 "termcap.form":

*** /arch/s5r3/usr/src/lib/libcurses/screen/termcap.form	Fri Jan 30 15:36:38 1987
--- ./termcap.form	Tue Aug 11 10:32:56 1987
***************
*** 41,47 ****
  	
  	if (inbuf == NULL)
  		return 0;
! 	else
  		while (size && *inbuf)
  			if (*inbuf == '$' && *(inbuf+1) == '<')
  				while (*inbuf && *inbuf++ != '>')
--- 41,47 ----
  	
  	if (inbuf == NULL)
  		return 0;
! 	else {
  		while (size && *inbuf)
  			if (*inbuf == '$' && *(inbuf+1) == '<')
  				while (*inbuf && *inbuf++ != '>')
***************
*** 50,55 ****
--- 50,58 ----
  				size--;
  				*outbuf++ = *inbuf++;
  			}
+ 		if (size)
+ 			*outbuf = '\0';
+ 	}
  	return saveoutbuf;
  }
  


and the fix to the S5R3.1 "termcap.ed":

*** /arch/s5r3.1/usr/src/lib/libcurses/screen/termcap.ed	Wed Oct 29 06:52:39 1986
--- ./termcap.ed	Tue Aug 11 10:28:10 1987
***************
*** 46,52 ****
  
      if (inbuf == NULL)
  	return (0);
!     else
  	while (size && *inbuf)
  	    if (*inbuf == '$' && *(inbuf+1) == '<')
  		while (*inbuf && *inbuf++ != '>')
--- 46,52 ----
  
      if (inbuf == NULL)
  	return (0);
!     else {
  	while (size && *inbuf)
  	    if (*inbuf == '$' && *(inbuf+1) == '<')
  		while (*inbuf && *inbuf++ != '>')
***************
*** 56,61 ****
--- 56,64 ----
  		size--;
  		*outbuf++ = *inbuf++;
  	    }
+ 	if (size)
+ 	    *outbuf = '\0';
+     }
      return (saveoutbuf);
  }
  
***************
*** 165,171 ****
      if (offset == -1)
  	return (0);
      rv = str_array[offset];
!     if (area && *area)
      {
  	(void) strcpy(*area, rv);
  	*area += strlen(rv) + 1;
--- 168,174 ----
      if (offset == -1)
  	return (0);
      rv = str_array[offset];
!     if (area && *area && rv)
      {
  	(void) strcpy(*area, rv);
  	*area += strlen(rv) + 1;

The latter also includes a fix to another null pointer dereferencing problem
(sigh - WHEN will they make the damn "-z" flag to the linker the default, so
that these bugs get caught *before* the code gets in the hands of people whose
systems never map in location 0?).
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com

meissner@xyzzy.UUCP (Michael Meissner) (08/17/87)

>  I have nethack working fine on our BSD system. However in trying
> to make it work on our 3b2/310 running system V I always get
> "Terminal must Backspace" in trying to run nethack.  I use vt100
> for my terminal type. Is it a problem with the terminal library

The problem is the standard system V.2 curses library (which includes the
termcap emulation routines), does not return the termcap string "bc" or
the flag "bs".  If you change "bc" (backspace char) to "le" (move cursor
left) everything will be fine, assuming you apply the TERMINFO patches
posted earlier.
-- 
Michael Meissner, Data General.		Uucp: ...!mcnc!rti!xyzzy!meissner
					Arpa/Csnet:  meissner@dg-rtp.DG.COM