[net.bugs.4bsd] Another problem with more ul filter.

rick@wucs.UUCP (Rick Bubenik) (07/17/84)

Index:	ucb/more/more.c

Description:
	A previous bug report described and proposed a fix for the
	following problem:

>	On certain terminals, such as the tvi925, more(1) incorrectly
>	handles underlining.  When the last word on a line is underlined
>	more(1) sends a CR followed by the underline-off code instead of
>	an underline-off code then a CR.
>
>	On certain terminals this causes the remainder of the line up to
>	the edge of the screen to be underlined.
>
>	This bug is present in 4.1BSD as well.

	The fix included with this previous report solves only half of 
	the problem.  The other problem is that some terminals, such
	as the tvi925, print a space each time underline mode is entered
	or exited.  This results in an extra space before and after each
	underlined word.  For this reason, the previously given fix solves
	the underlining to the end of screen problem but introduces
	two spaces between each underlined letter.

Repeat-By:
	Log on to a tvi925 and man off a few manual pages.  Sooner or
	later one will have a line that ends with an underlined word
	and the underlining will continue to the end of the screen.
	The other problem is visible around all underlined words.

Fix:
	A space is printed each time underlining mode is entered
	or exited.  The space can not simply be backspaced over as
	this causes the mode change command just sent to the terminal
	to be ignored.  Therefore the following fix assumes that the
	when underlining mode is being entered, the previous character
	was a space (this could have been checked) and backspaces
	over it before entering ul mode.  When exiting ul mode, the 
	next character is checked.  If it is a space, it isn't printed.
	The result is a better looking display most of the time.
	This fix also solves another problem with more, that being
	more never initializes the backspace character.

*** /tmp/,RCSt1027472	Mon Jul 16 16:22:58 1984
--- more.c	Mon Jul 16 15:55:32 1984
***************
*** 80,85
  char		cursorhome[40];	/* contains cursor movement to home */
  char		*EodClr;	/* clear rest of screen */
  char		*tgetstr();
  int		Mcol = 80;	/* number of columns */
  int		Wrap = 1;	/* set if automargins */
  long		fseek();

--- 80,86 -----
  char		cursorhome[40];	/* contains cursor movement to home */
  char		*EodClr;	/* clear rest of screen */
  char		*tgetstr();
+ int		intUG;		/* # of spaces printed with ULenter & ULexit */
  int		Mcol = 80;	/* number of columns */
  int		Wrap = 1;	/* set if automargins */
  long		fseek();
***************
*** 819,826
  		c = *s++;
  		state = 0;
  	    }
! 	    if (state != pstate)
! 		tputs(state ? ULenter : ULexit, 1, putch);
  	    pstate = state;
  	    putchar(c);
  	    if (state && *chUL) {

--- 820,851 -----
  		c = *s++;
  		state = 0;
  	    }
! 	    /*
! 	     * Some terminals (e.g. tvi925) print a space whenever underlining
! 	     * mode is entered or exited.  Backspacing over this space after
! 	     * entering/exiting underlining mode cancels the mode change just
! 	     * make.  Therefore, a space is assumed to have been the previous
! 	     * character typed when entering underlining mode and if a space
! 	     * is to be the next character typed when exiting underlining mode,
! 	     * it isn't printed.  Also, it is assumed that no terminal will
! 	     * print more than one space when entering or exiting underlining
! 	     * mode.
! 	     */
! 	    if (state != pstate) {
! 		int i;
! 
! 		if (state) {
! 			for (i = intUG; i > 0; i--)
! 				pr(chBS); /* backspace over spaces just typed */
! 			tputs(ULenter, 1, putch);
! 		} else {
! 			tputs(ULexit, 1, putch);
! 			if (intUG && c == ' ') { 
! 				pstate = 0;
! 				continue;
! 			}
! 		}
! 	    }
  	    pstate = state;
  	    putchar(c);
  	    if (state && *chUL) {
***************
*** 827,832
  		pr(chBS);
  		tputs(chUL, 1, putch);
  	    }
  	}
  }
  

--- 852,865 -----
  		pr(chBS);
  		tputs(chUL, 1, putch);
  	    }
+ 	    /*
+ 	     * If the last character in this line (buffer) has just been 
+ 	     * printed and underlining mode is on, turn it off.
+ 	     */
+ 	    if (pstate && n == 0) {
+ 		tputs(ULexit, 1, putch);
+ 		pstate = 0;
+ 	    }
  	}
  }
  
***************
*** 1363,1368
  	    if ((ULexit = tgetstr("ue", &clearptr)) == NULL &&
  		(!*chUL) && (ULexit = tgetstr("se", &clearptr)) == NULL)
  		ULexit = "";
  	    
  	    if (padstr = tgetstr("pc", &clearptr))
  		PC = *padstr;

--- 1396,1407 -----
  	    if ((ULexit = tgetstr("ue", &clearptr)) == NULL &&
  		(!*chUL) && (ULexit = tgetstr("se", &clearptr)) == NULL)
  		ULexit = "";
+ 	    if (tgetflag("bs"))
+ 		chBS = "^H";	/* should be changed to a control-H */
+ 	    else if ((chBS = tgetstr("bc", &clearptr)) == NULL )
+ 		chBS = "";
+ 	    if ((intUG = tgetnum("ug")) == -1 )
+ 		intUG = 0;
  	    
  	    if (padstr = tgetstr("pc", &clearptr))
  		PC = *padstr;

-- 

Rick Bubenik				..!ihnp4!wucs!rick
Box 1045 Washington University		(314)-889-5053
St. Louis, MO 63130   USA