[rec.games.hack] Re^2: More info on inventory bug in NetHack

polder@cs.vu.nl (Polderman Paul) (12/18/87)

In article <528@silver.bacs.indiana.edu> creps@silver.UUCP (Steve Creps) writes:
> 
>    I said I had the problem with the columns lining up on an inventory
> fixed. Yes, I do. I also said there is still a bug in that when it prints
> more than one stackable item (e.g. "3 food rations") it omits the number
> of items (and prints "food rations").
>    Well, this bug does not occur in doing an inventory. It's when you go
> to a square that has more than one thing on the ground ("There are
> several items here:") that it does this. Sorry I didn't have the info
> straight before.
> 
> -	-	-	-	-	-	-	-	-
> Steve Creps on the VAX 8650 running Ultrix 2.0-1 at Indiana University.
> 	creps@silver.bacs.indiana.edu
> "F-14 Tomcat! There IS no substitute."

  The function cornline() uses the function tputs() to output strings
on the screen. It uses tputs() to ensure that if the standout-mode sequence
is included in the string, it is output correctly (with padding etc.).
  Now, when tputs() is asked to output "3 food rations", it assumes "3"
to be padding information. Thus it outputs three (invisible) pad-
characters followed by the string "<space>food rations".
  The fix for this is not trivial. The easiest "fix" is: replace the call
to tputs() by a call to putstr() which will just output the string as it is,
but will not pad correctly.

  The fix below is the following: I added a new mode to cornline() which
tells cornline that the string given to it contains termcap information.
When cornline() puts it on the screen, it will take care to use tputs(),
ordinary strings will be output using putstr(). This also gets rid of
an ugly piece of code in "termcap.c".

-- Paul Polderman (polder@cs.vu.nl) (Hi mum!)

----- <Fix #1 follows> -----
*** pager.new.c	Thu Dec 17 22:14:31 1987
--- pager.c	Thu Dec 17 22:10:33 1987
***************
*** 251,257
  			cl_eos();
  		}
  	}
! 	puts(s);
  	cury++;
  	return(0);
  }

--- 251,257 -----
  			cl_eos();
  		}
  	}
! 	xputs(s); xputc('\n');
  	cury++;
  	return(0);
  }
***************
*** 265,271
   *	cornline(1, text)	: add text to the chain of texts
   *	cornline(2, morcs)	: output everything and cleanup
   *	cornline(3, 0)		: cleanup
-  *	cornline(4, text)	: add text to the chain and set highlight-flag.
   */
  
  cornline(mode, text)

--- 265,270 -----
   *	cornline(1, text)	: add text to the chain of texts
   *	cornline(2, morcs)	: output everything and cleanup
   *	cornline(3, 0)		: cleanup
   */
  
  cornline(mode, text)
***************
*** 275,281
  	static struct line {
  		struct line *next_line;
  		char *line_text;
- 		boolean highlighted;
  	} *texthead, *texttail;
  	static int maxlen;
  	static int linect;

--- 274,279 -----
  	static struct line {
  		struct line *next_line;
  		char *line_text;
  	} *texthead, *texttail;
  	static int maxlen;
  	static int linect;
***************
*** 280,286
  	static int maxlen;
  	static int linect;
  	register struct line *tl;
- 	register int p;
  
  	if(mode == 0) {
  		texthead = 0;

--- 278,283 -----
  	static int maxlen;
  	static int linect;
  	register struct line *tl;
  
  	if(mode == 0) {
  		texthead = 0;
***************
*** 293,299
  		return;
  	}
  
! 	if(mode == 1 || mode == 4) {
  	    register int len;
  
  	    if(!text) return;	/* superfluous, just to be sure */

--- 290,296 -----
  		return;
  	}
  
! 	if(mode == 1) {
  	    register int len;
  
  	    if(!text) return;	/* superfluous, just to be sure */
***************
*** 306,312
  	    tl->next_line = 0;
  	    tl->line_text = (char *)(tl + 1);
  	    (void) strcpy(tl->line_text, text);
- 	    tl->highlighted = (mode == 4);
  	    if(!texthead)
  		texthead = tl;
  	    else

--- 303,308 -----
  	    tl->next_line = 0;
  	    tl->line_text = (char *)(tl + 1);
  	    (void) strcpy(tl->line_text, text);
  	    if(!texthead)
  		texthead = tl;
  	    else
***************
*** 336,347
  		    if(curline > 1)
  			cl_end ();
  		    putsym(' ');
! 		    if (HI && tl->highlighted) {
! 			    xputs(HI);
! 			    putstr(tl->line_text);
! 			    xputs(HE);
! 		    } else
! 			    putstr(tl->line_text);
  		    curline++;
  		}
  		curs (lth, curline);

--- 332,338 -----
  		    if(curline > 1)
  			cl_end ();
  		    putsym(' ');
! 		    xputs(tl->line_text);
  		    curline++;
  		}
  		curs (lth, curline);
***************
*** 353,365
  	    } else {					/* feed to pager */
  		set_pager(0);
  		for (tl = texthead; tl; tl = tl->next_line) {
! 		    if (HI && tl->highlighted) {
! 			xputs(HI);
! 		        p = page_line(tl->line_text);
! 			xputs(HE);
! 		    } else
! 		        p = page_line(tl->line_text);
! 		    if (p) {
  			set_pager(2);
  			goto cleanup;
  		    }

--- 344,350 -----
  	    } else {					/* feed to pager */
  		set_pager(0);
  		for (tl = texthead; tl; tl = tl->next_line) {
! 		    if (page_line (tl->line_text)) {
  			set_pager(2);
  			goto cleanup;
  		    }
----- <Fix #2 follows> -----
*** termcap.new.c	Thu Dec 17 22:21:15 1987
--- termcap.c	Thu Dec 17 22:21:39 1987
***************
*** 129,136
  	 */
  	    HI = (char *) alloc(strlen(SO) + 1);
  	    HE = (char *) alloc(strlen(SE) + 1);
! 	    strcpy(HI, SO);
! 	    strcpy(HE, SE);
  # endif
  	CD = tgetstr("cd", &tbufptr);
  	set_whole_screen();		/* uses LI and CD */

--- 129,140 -----
  	 */
  	    HI = (char *) alloc(strlen(SO) + 1);
  	    HE = (char *) alloc(strlen(SE) + 1);
! 	    i = 0;
! 	    while(isdigit(SO[i])) i++;
! 	    strcpy(HI, &SO[i]);
! 	    i = 0;
! 	    while(isdigit(SE[i])) i++;
! 	    strcpy(HE, &SE[i]);
  # endif
  	CD = tgetstr("cd", &tbufptr);
  	set_whole_screen();		/* uses LI and CD */