Home | History | Annotate | Line # | Download | only in libcurses
refresh.c revision 1.46
      1  1.46  christos /*	$NetBSD: refresh.c,v 1.46 2002/06/26 18:14:04 christos Exp $	*/
      2   1.8     mikel 
      3   1.1       cgd /*
      4   1.7       cgd  * Copyright (c) 1981, 1993, 1994
      5   1.5       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36   1.8     mikel #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38   1.8     mikel #if 0
     39   1.7       cgd static char sccsid[] = "@(#)refresh.c	8.7 (Berkeley) 8/13/94";
     40   1.8     mikel #else
     41  1.46  christos __RCSID("$NetBSD: refresh.c,v 1.46 2002/06/26 18:14:04 christos Exp $");
     42   1.8     mikel #endif
     43  1.11       mrg #endif				/* not lint */
     44   1.1       cgd 
     45  1.38      matt #include <stdlib.h>
     46   1.4   mycroft #include <string.h>
     47   1.1       cgd 
     48   1.7       cgd #include "curses.h"
     49  1.15     blymn #include "curses_private.h"
     50   1.7       cgd 
     51   1.4   mycroft static void	domvcur __P((int, int, int, int));
     52  1.23       jdc static int	makech __P((int));
     53  1.23       jdc static void	quickch __P((void));
     54  1.23       jdc static void	scrolln __P((int, int, int, int, int));
     55   1.1       cgd 
     56  1.17     blymn #ifndef _CURSES_USE_MACROS
     57  1.17     blymn 
     58  1.17     blymn /*
     59  1.17     blymn  * refresh --
     60  1.17     blymn  *	Make the current screen look like "stdscr" over the area covered by
     61  1.17     blymn  *	stdscr.
     62  1.17     blymn  */
     63  1.17     blymn int
     64  1.17     blymn refresh(void)
     65  1.17     blymn {
     66  1.17     blymn 	return wrefresh(stdscr);
     67  1.17     blymn }
     68  1.17     blymn 
     69  1.17     blymn #endif
     70  1.17     blymn 
     71   1.4   mycroft /*
     72  1.23       jdc  * wnoutrefresh --
     73  1.23       jdc  *	Add the contents of "win" to the virtual window.
     74  1.23       jdc  */
     75  1.23       jdc int
     76  1.23       jdc wnoutrefresh(WINDOW *win)
     77  1.23       jdc {
     78  1.44     blymn 	return _cursesi_wnoutrefresh(_cursesi_screen, win);
     79  1.44     blymn }
     80  1.44     blymn 
     81  1.44     blymn 
     82  1.44     blymn /*
     83  1.44     blymn  * _cursesi_wnoutrefresh --
     84  1.44     blymn  *      Does the grunt work for wnoutrefresh to the given screen.
     85  1.44     blymn  *
     86  1.44     blymn  */
     87  1.44     blymn int
     88  1.44     blymn _cursesi_wnoutrefresh(SCREEN *screen, WINDOW *win)
     89  1.44     blymn {
     90  1.45     blymn 
     91  1.33   mycroft 	short	wy, wx, x_off;
     92  1.33   mycroft 	__LINE	*wlp, *vlp;
     93  1.23       jdc 
     94  1.23       jdc #ifdef DEBUG
     95  1.23       jdc 	__CTRACE("wnoutrefresh: win %0.2o, flags 0x%08x\n", win, win->flags);
     96  1.23       jdc #endif
     97  1.23       jdc 
     98  1.44     blymn 	if (screen->curwin)
     99  1.23       jdc 		return(OK);
    100  1.44     blymn 	screen->__virtscr->cury = win->cury + win->begy;
    101  1.44     blymn 	screen->__virtscr->curx = win->curx + win->begx;
    102  1.23       jdc 
    103  1.23       jdc 	/* Copy the window flags from "win" to "__virtscr" */
    104  1.33   mycroft 	if (win->flags & __CLEAROK) {
    105  1.33   mycroft 		if (win->flags & __FULLWIN)
    106  1.44     blymn 			screen->__virtscr->flags |= __CLEAROK;
    107  1.23       jdc 		win->flags &= ~__CLEAROK;
    108  1.33   mycroft 	}
    109  1.44     blymn 	screen->__virtscr->flags &= ~__LEAVEOK;
    110  1.44     blymn 	screen->__virtscr->flags |= win->flags;
    111  1.23       jdc 
    112  1.44     blymn 	for (wy = 0; wy < win->maxy && wy < screen->__virtscr->maxy - win->begy; wy++) {
    113  1.33   mycroft 		wlp = win->lines[wy];
    114  1.23       jdc #ifdef DEBUG
    115  1.23       jdc 		__CTRACE("wnoutrefresh: wy %d\tf: %d\tl:%d\tflags %x\n", wy,
    116  1.33   mycroft 		    *wlp->firstchp, *wlp->lastchp, wlp->flags);
    117  1.23       jdc #endif
    118  1.35   mycroft 		if ((wlp->flags & __ISDIRTY) == 0)
    119  1.33   mycroft 			continue;
    120  1.44     blymn 		vlp = screen->__virtscr->lines[wy + win->begy];
    121  1.33   mycroft 
    122  1.33   mycroft 		if (*wlp->firstchp < win->maxx + win->ch_off &&
    123  1.33   mycroft 		    *wlp->lastchp >= win->ch_off) {
    124  1.23       jdc 			/* Copy line from "win" to "__virtscr". */
    125  1.29       jdc 			for (wx = 0, x_off = win->begx; wx < win->maxx &&
    126  1.44     blymn 			    x_off < screen->__virtscr->maxx; wx++, x_off++) {
    127  1.33   mycroft 				vlp->line[x_off].attr = wlp->line[wx].attr;
    128  1.36       jdc 				if (wlp->line[wx].attr & __COLOR)
    129  1.33   mycroft 					vlp->line[x_off].attr |=
    130  1.36       jdc 					    wlp->line[wx].battr & ~__COLOR;
    131  1.36       jdc 				else
    132  1.36       jdc 					vlp->line[x_off].attr |=
    133  1.36       jdc 					    wlp->line[wx].battr;
    134  1.33   mycroft 				if (wlp->line[wx].ch == ' ' &&
    135  1.33   mycroft 				    wlp->line[wx].bch != ' ')
    136  1.33   mycroft 					vlp->line[x_off].ch
    137  1.33   mycroft 					    = wlp->line[wx].bch;
    138  1.23       jdc 				else
    139  1.33   mycroft 					vlp->line[x_off].ch
    140  1.33   mycroft 					    = wlp->line[wx].ch;
    141  1.23       jdc 			}
    142  1.23       jdc 
    143  1.23       jdc 			/* Set flags on "__virtscr" and unset on "win". */
    144  1.33   mycroft 			if (wlp->flags & __ISPASTEOL)
    145  1.33   mycroft 				vlp->flags |= __ISPASTEOL;
    146  1.23       jdc 			else
    147  1.33   mycroft 				vlp->flags &= ~__ISPASTEOL;
    148  1.33   mycroft 			if (wlp->flags & __ISDIRTY)
    149  1.33   mycroft 				vlp->flags |= __ISDIRTY;
    150  1.23       jdc 
    151  1.23       jdc #ifdef DEBUG
    152  1.23       jdc 			__CTRACE("win: firstch = %d, lastch = %d\n",
    153  1.33   mycroft 			    *wlp->firstchp, *wlp->lastchp);
    154  1.23       jdc #endif
    155  1.23       jdc 			/* Set change pointers on "__virtscr". */
    156  1.33   mycroft 			if (*vlp->firstchp >
    157  1.33   mycroft 			    *wlp->firstchp + win->begx - win->ch_off)
    158  1.33   mycroft 				*vlp->firstchp =
    159  1.33   mycroft 				    *wlp->firstchp + win->begx - win->ch_off;
    160  1.33   mycroft 			if (*vlp->lastchp <
    161  1.33   mycroft 			    *wlp->lastchp + win->begx - win->ch_off)
    162  1.33   mycroft 				*vlp->lastchp =
    163  1.33   mycroft 				    *wlp->lastchp + win->begx - win->ch_off;
    164  1.23       jdc #ifdef DEBUG
    165  1.23       jdc 			__CTRACE("__virtscr: firstch = %d, lastch = %d\n",
    166  1.33   mycroft 			    *vlp->firstchp, *vlp->lastchp);
    167  1.23       jdc #endif
    168  1.23       jdc 
    169  1.23       jdc 			/* Set change pointers on "win". */
    170  1.33   mycroft 			if (*wlp->firstchp >= win->ch_off)
    171  1.33   mycroft 				*wlp->firstchp = win->maxx + win->ch_off;
    172  1.33   mycroft 			if (*wlp->lastchp < win->maxx + win->ch_off)
    173  1.33   mycroft 				*wlp->lastchp = win->ch_off;
    174  1.33   mycroft 			if (*wlp->lastchp < *wlp->firstchp) {
    175  1.23       jdc #ifdef DEBUG
    176  1.23       jdc 				__CTRACE("wnoutrefresh: line %d notdirty\n",
    177  1.23       jdc 				    wy);
    178  1.23       jdc #endif
    179  1.33   mycroft 				wlp->flags &= ~__ISDIRTY;
    180  1.23       jdc 			}
    181  1.23       jdc 		}
    182  1.23       jdc 	}
    183  1.23       jdc 
    184  1.23       jdc 	return (OK);
    185  1.23       jdc }
    186  1.23       jdc 
    187  1.23       jdc /*
    188   1.4   mycroft  * wrefresh --
    189   1.4   mycroft  *	Make the current screen look like "win" over the area coverd by
    190   1.4   mycroft  *	win.
    191   1.4   mycroft  */
    192   1.4   mycroft int
    193  1.17     blymn wrefresh(WINDOW *win)
    194   1.1       cgd {
    195  1.44     blymn 	int retval;
    196  1.45     blymn 
    197  1.44     blymn 	_cursesi_screen->curwin = (win == _cursesi_screen->curscr);
    198  1.43     blymn 	if (!_cursesi_screen->curwin)
    199  1.44     blymn 		retval = _cursesi_wnoutrefresh(_cursesi_screen, win);
    200  1.23       jdc 	else
    201  1.23       jdc 		retval = OK;
    202  1.23       jdc 	if (retval == OK) {
    203  1.23       jdc 		retval = doupdate();
    204  1.24       jdc 		if (!win->flags & __LEAVEOK) {
    205  1.24       jdc 			win->cury = max(0, curscr->cury - win->begy);
    206  1.24       jdc 			win->curx = max(0, curscr->curx - win->begx);
    207  1.24       jdc 		}
    208  1.23       jdc 	}
    209  1.43     blymn 	_cursesi_screen->curwin = 0;
    210  1.23       jdc 	return(retval);
    211  1.23       jdc }
    212  1.23       jdc 
    213  1.23       jdc /*
    214  1.23       jdc  * doupdate --
    215  1.23       jdc  *	Make the current screen look like the virtual window "__virtscr".
    216  1.23       jdc  */
    217  1.23       jdc int
    218  1.23       jdc doupdate(void)
    219  1.23       jdc {
    220  1.23       jdc 	WINDOW	*win;
    221  1.23       jdc 	__LINE	*wlp;
    222  1.23       jdc 	short	 wy;
    223  1.23       jdc 	int	 dnum;
    224   1.9      phil 
    225   1.9      phil 	/* Check if we need to restart ... */
    226  1.43     blymn 	if (_cursesi_screen->endwin)
    227   1.9      phil 		__restartwin();
    228   1.7       cgd 
    229  1.43     blymn 	if (_cursesi_screen->curwin)
    230  1.23       jdc 		win = curscr;
    231  1.23       jdc 	else
    232  1.44     blymn 		win = _cursesi_screen->__virtscr;
    233  1.23       jdc 
    234   1.4   mycroft 	/* Initialize loop parameters. */
    235  1.43     blymn 	_cursesi_screen->ly = curscr->cury;
    236  1.43     blymn 	_cursesi_screen->lx = curscr->curx;
    237   1.1       cgd 	wy = 0;
    238   1.1       cgd 
    239  1.43     blymn 	if (!_cursesi_screen->curwin)
    240   1.5       cgd 		for (wy = 0; wy < win->maxy; wy++) {
    241   1.5       cgd 			wlp = win->lines[wy];
    242   1.5       cgd 			if (wlp->flags & __ISDIRTY)
    243  1.12  christos 				wlp->hash = __hash((char *)(void *)wlp->line,
    244  1.11       mrg 				    (int) (win->maxx * __LDATASIZE));
    245   1.5       cgd 		}
    246   1.5       cgd 
    247  1.43     blymn 	if ((win->flags & __CLEAROK) || (curscr->flags & __CLEAROK) ||
    248  1.43     blymn 	    _cursesi_screen->curwin) {
    249  1.23       jdc 		if (curscr->wattr & __COLOR)
    250  1.23       jdc 			__unsetattr(0);
    251  1.41       jdc 		tputs(__tc_cl, 0, __cputchar);
    252  1.43     blymn 		_cursesi_screen->ly = 0;
    253  1.43     blymn 		_cursesi_screen->lx = 0;
    254  1.43     blymn 		if (!_cursesi_screen->curwin) {
    255  1.23       jdc 			curscr->flags &= ~__CLEAROK;
    256  1.23       jdc 			curscr->cury = 0;
    257  1.23       jdc 			curscr->curx = 0;
    258  1.23       jdc 			werase(curscr);
    259   1.1       cgd 		}
    260  1.23       jdc 		__touchwin(win);
    261   1.5       cgd 		win->flags &= ~__CLEAROK;
    262   1.1       cgd 	}
    263  1.41       jdc 	if (!__CA) {
    264   1.5       cgd 		if (win->curx != 0)
    265  1.39    itojun 			__cputchar('\n');
    266  1.43     blymn 		if (!_cursesi_screen->curwin)
    267   1.1       cgd 			werase(curscr);
    268   1.1       cgd 	}
    269   1.4   mycroft #ifdef DEBUG
    270  1.43     blymn 	__CTRACE("doupdate: (%0.2o): curwin = %d\n", win,
    271  1.43     blymn 		 _cursesi_screen->curwin);
    272  1.23       jdc 	__CTRACE("doupdate: \tfirstch\tlastch\n");
    273   1.5       cgd #endif
    274   1.5       cgd 
    275  1.43     blymn 	if (!_cursesi_screen->curwin) {
    276   1.5       cgd 		/*
    277   1.5       cgd 		 * Invoke quickch() only if more than a quarter of the lines
    278   1.5       cgd 		 * in the window are dirty.
    279   1.5       cgd 		 */
    280   1.5       cgd 		for (wy = 0, dnum = 0; wy < win->maxy; wy++)
    281  1.35   mycroft 			if (win->lines[wy]->flags & __ISDIRTY)
    282   1.5       cgd 				dnum++;
    283   1.5       cgd 		if (!__noqch && dnum > (int) win->maxy / 4)
    284  1.23       jdc 			quickch();
    285   1.5       cgd 	}
    286   1.5       cgd 
    287   1.5       cgd #ifdef DEBUG
    288  1.11       mrg 	{
    289  1.11       mrg 		int	i, j;
    290  1.11       mrg 
    291   1.5       cgd 		__CTRACE("#####################################\n");
    292   1.5       cgd 		for (i = 0; i < curscr->maxy; i++) {
    293   1.5       cgd 			__CTRACE("C: %d:", i);
    294   1.5       cgd 			__CTRACE(" 0x%x \n", curscr->lines[i]->hash);
    295   1.7       cgd 			for (j = 0; j < curscr->maxx; j++)
    296  1.11       mrg 				__CTRACE("%c", curscr->lines[i]->line[j].ch);
    297   1.5       cgd 			__CTRACE("\n");
    298  1.14    simonb 			__CTRACE(" attr:");
    299   1.7       cgd 			for (j = 0; j < curscr->maxx; j++)
    300  1.43     blymn 				__CTRACE(" %x",
    301  1.43     blymn 					 curscr->lines[i]->line[j].attr);
    302   1.5       cgd 			__CTRACE("\n");
    303   1.5       cgd 			__CTRACE("W: %d:", i);
    304  1.23       jdc 			__CTRACE(" 0x%x \n", win->lines[i]->hash);
    305  1.23       jdc 			__CTRACE(" 0x%x ", win->lines[i]->flags);
    306  1.23       jdc 			for (j = 0; j < win->maxx; j++)
    307  1.23       jdc 				__CTRACE("%c", win->lines[i]->line[j].ch);
    308  1.23       jdc 			__CTRACE("\n");
    309  1.23       jdc 			__CTRACE(" attr:");
    310  1.23       jdc 			for (j = 0; j < win->maxx; j++)
    311  1.23       jdc 				__CTRACE(" %x",
    312  1.23       jdc 				    win->lines[i]->line[j].attr);
    313  1.23       jdc 			__CTRACE("\n");
    314   1.5       cgd 		}
    315  1.11       mrg 	}
    316  1.11       mrg #endif				/* DEBUG */
    317   1.5       cgd 
    318   1.5       cgd 	for (wy = 0; wy < win->maxy; wy++) {
    319  1.33   mycroft 		wlp = win->lines[wy];
    320  1.23       jdc /* XXX: remove this debug */
    321   1.4   mycroft #ifdef DEBUG
    322  1.23       jdc 		__CTRACE("doupdate: wy %d\tf: %d\tl:%d\tflags %x\n", wy,
    323  1.33   mycroft 		    *wlp->firstchp, *wlp->lastchp, wlp->flags);
    324   1.4   mycroft #endif
    325  1.43     blymn 		if (!_cursesi_screen->curwin)
    326  1.33   mycroft 			curscr->lines[wy]->hash = wlp->hash;
    327  1.35   mycroft 		if (wlp->flags & __ISDIRTY) {
    328  1.23       jdc 			if (makech(wy) == ERR)
    329   1.4   mycroft 				return (ERR);
    330   1.1       cgd 			else {
    331  1.33   mycroft 				if (*wlp->firstchp >= 0)
    332  1.33   mycroft 					*wlp->firstchp = win->maxx;
    333  1.33   mycroft 				if (*wlp->lastchp < win->maxx)
    334  1.33   mycroft 					*wlp->lastchp = 0;
    335  1.33   mycroft 				if (*wlp->lastchp < *wlp->firstchp) {
    336   1.5       cgd #ifdef DEBUG
    337  1.23       jdc 					__CTRACE("doupdate: line %d notdirty\n", wy);
    338   1.5       cgd #endif
    339  1.33   mycroft 					wlp->flags &= ~__ISDIRTY;
    340   1.5       cgd 				}
    341   1.1       cgd 			}
    342   1.5       cgd 
    343   1.5       cgd 		}
    344   1.4   mycroft #ifdef DEBUG
    345  1.33   mycroft 		__CTRACE("\t%d\t%d\n", *wlp->firstchp, *wlp->lastchp);
    346   1.4   mycroft #endif
    347   1.1       cgd 	}
    348   1.7       cgd 
    349   1.5       cgd #ifdef DEBUG
    350  1.43     blymn 	__CTRACE("doupdate: ly=%d, lx=%d\n", _cursesi_screen->ly,
    351  1.43     blymn 		 _cursesi_screen->lx);
    352   1.5       cgd #endif
    353   1.1       cgd 
    354  1.43     blymn 	if (_cursesi_screen->curwin)
    355  1.43     blymn 		domvcur(_cursesi_screen->ly, _cursesi_screen->lx,
    356  1.43     blymn 			(int) win->cury, (int) win->curx);
    357   1.1       cgd 	else {
    358   1.5       cgd 		if (win->flags & __LEAVEOK) {
    359  1.43     blymn 			curscr->cury = _cursesi_screen->ly;
    360  1.43     blymn 			curscr->curx = _cursesi_screen->lx;
    361   1.4   mycroft 		} else {
    362  1.43     blymn 			domvcur(_cursesi_screen->ly, _cursesi_screen->lx,
    363  1.43     blymn 				win->cury, win->curx);
    364  1.23       jdc 			curscr->cury = win->cury;
    365  1.23       jdc 			curscr->curx = win->curx;
    366   1.1       cgd 		}
    367   1.1       cgd 	}
    368  1.23       jdc 
    369  1.28   mycroft 	/* Don't leave the screen with attributes set. */
    370  1.28   mycroft 	__unsetattr(0);
    371  1.43     blymn 	(void) fflush(_cursesi_screen->outfd);
    372  1.28   mycroft 	return (OK);
    373   1.1       cgd }
    374   1.1       cgd 
    375   1.1       cgd /*
    376   1.4   mycroft  * makech --
    377   1.4   mycroft  *	Make a change on the screen.
    378   1.1       cgd  */
    379   1.4   mycroft static int
    380  1.23       jdc makech(wy)
    381  1.11       mrg 	int	wy;
    382   1.1       cgd {
    383  1.23       jdc 	WINDOW	*win;
    384  1.34   mycroft 	static __LDATA blank = {' ', 0, ' ', 0};
    385   1.7       cgd 	__LDATA *nsp, *csp, *cp, *cep;
    386  1.11       mrg 	int	clsp, nlsp;	/* Last space in lines. */
    387  1.23       jdc 	int	lch, wx;
    388  1.35   mycroft 	char	*ce;
    389  1.23       jdc 	attr_t	lspc;		/* Last space colour */
    390  1.27   mycroft 	attr_t	off, on;
    391   1.5       cgd 
    392   1.8     mikel #ifdef __GNUC__
    393  1.23       jdc 	nlsp = lspc = 0;	/* XXX gcc -Wuninitialized */
    394   1.8     mikel #endif
    395  1.43     blymn 	if (_cursesi_screen->curwin)
    396  1.23       jdc 		win = curscr;
    397  1.23       jdc 	else
    398  1.23       jdc 		win = __virtscr;
    399   1.5       cgd 	/* Is the cursor still on the end of the last line? */
    400  1.40    itojun 	if (wy > 0 && curscr->lines[wy - 1]->flags & __ISPASTEOL) {
    401  1.43     blymn 		domvcur(_cursesi_screen->ly, _cursesi_screen->lx,
    402  1.43     blymn 			_cursesi_screen->ly + 1, 0);
    403  1.43     blymn 		_cursesi_screen->ly++;
    404  1.43     blymn 		_cursesi_screen->lx = 0;
    405   1.5       cgd 	}
    406  1.23       jdc 	wx = *win->lines[wy]->firstchp;
    407   1.5       cgd 	if (wx < 0)
    408   1.5       cgd 		wx = 0;
    409  1.11       mrg 	else
    410  1.11       mrg 		if (wx >= win->maxx)
    411  1.11       mrg 			return (OK);
    412  1.23       jdc 	lch = *win->lines[wy]->lastchp;
    413   1.1       cgd 	if (lch < 0)
    414   1.4   mycroft 		return (OK);
    415  1.11       mrg 	else
    416  1.11       mrg 		if (lch >= (int) win->maxx)
    417  1.11       mrg 			lch = win->maxx - 1;
    418   1.1       cgd 
    419  1.43     blymn 	if (_cursesi_screen->curwin)
    420   1.5       cgd 		csp = &blank;
    421   1.1       cgd 	else
    422  1.23       jdc 		csp = &curscr->lines[wy]->line[wx];
    423   1.1       cgd 
    424   1.5       cgd 	nsp = &win->lines[wy]->line[wx];
    425  1.43     blymn 	if (__tc_ce && !_cursesi_screen->curwin) {
    426  1.20       jdc 		cp = &win->lines[wy]->line[win->maxx - 1];
    427  1.23       jdc 		lspc = cp->attr & __COLOR;
    428  1.23       jdc 		while (cp->ch == ' ' && cp->attr == lspc)
    429  1.20       jdc 			if (cp-- <= win->lines[wy]->line)
    430   1.1       cgd 				break;
    431   1.5       cgd 		nlsp = cp - win->lines[wy]->line;
    432  1.42     blymn 		if (nlsp < 0)
    433  1.42     blymn 			nlsp = 0;
    434   1.1       cgd 	}
    435  1.43     blymn 	if (!_cursesi_screen->curwin)
    436  1.41       jdc 		ce = __tc_ce;
    437   1.1       cgd 	else
    438   1.4   mycroft 		ce = NULL;
    439   1.1       cgd 
    440   1.1       cgd 	while (wx <= lch) {
    441  1.35   mycroft 		if (memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
    442   1.4   mycroft 			if (wx <= lch) {
    443   1.5       cgd 				while (wx <= lch &&
    444   1.7       cgd 				    memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
    445   1.7       cgd 					nsp++;
    446  1.43     blymn 					if (!_cursesi_screen->curwin)
    447   1.7       cgd 						++csp;
    448   1.7       cgd 					++wx;
    449   1.7       cgd 				}
    450   1.4   mycroft 				continue;
    451   1.4   mycroft 			}
    452   1.4   mycroft 			break;
    453   1.4   mycroft 		}
    454  1.43     blymn 		domvcur(_cursesi_screen->ly, _cursesi_screen->lx, wy, wx);
    455   1.5       cgd 
    456   1.4   mycroft #ifdef DEBUG
    457  1.35   mycroft 		__CTRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d\n",
    458  1.43     blymn 		    wx, _cursesi_screen->ly, _cursesi_screen->lx, wy, wx);
    459   1.4   mycroft #endif
    460  1.43     blymn 		_cursesi_screen->ly = wy;
    461  1.43     blymn 		_cursesi_screen->lx = wx;
    462  1.35   mycroft 		while (memcmp(nsp, csp, sizeof(__LDATA)) != 0 && wx <= lch) {
    463   1.7       cgd 			if (ce != NULL &&
    464  1.23       jdc 			    wx >= nlsp && nsp->ch == ' ' && nsp->attr == lspc) {
    465   1.4   mycroft 				/* Check for clear to end-of-line. */
    466   1.5       cgd 				cep = &curscr->lines[wy]->line[win->maxx - 1];
    467  1.23       jdc 				while (cep->ch == ' ' && cep->attr == lspc)
    468   1.5       cgd 					if (cep-- <= csp)
    469   1.4   mycroft 						break;
    470   1.7       cgd 				clsp = cep - curscr->lines[wy]->line -
    471  1.11       mrg 				    win->begx * __LDATASIZE;
    472   1.4   mycroft #ifdef DEBUG
    473  1.20       jdc 				__CTRACE("makech: clsp = %d, nlsp = %d\n",
    474  1.20       jdc 				    clsp, nlsp);
    475   1.4   mycroft #endif
    476  1.41       jdc 				if (((clsp - nlsp >= strlen(__tc_ce) &&
    477  1.20       jdc 				    clsp < win->maxx * __LDATASIZE) ||
    478  1.20       jdc 				    wy == win->maxy - 1) &&
    479  1.23       jdc 				    (!(lspc & __COLOR) ||
    480  1.41       jdc 				    ((lspc & __COLOR) && __tc_ut))) {
    481  1.23       jdc 					__unsetattr(0);
    482  1.23       jdc 					if ((lspc & __COLOR) !=
    483  1.20       jdc 					    (curscr->wattr & __COLOR)) {
    484  1.23       jdc 						__set_color(lspc);
    485  1.20       jdc 						curscr->wattr &= ~__COLOR;
    486  1.23       jdc 						curscr->wattr |= lspc & __COLOR;
    487  1.20       jdc 					}
    488  1.41       jdc 					tputs(__tc_ce, 0, __cputchar);
    489  1.43     blymn 					_cursesi_screen->lx = wx + win->begx;
    490   1.5       cgd 					while (wx++ <= clsp) {
    491   1.5       cgd 						csp->ch = ' ';
    492  1.23       jdc 						csp->attr = lspc;
    493   1.5       cgd 						csp++;
    494   1.5       cgd 					}
    495   1.4   mycroft 					return (OK);
    496   1.1       cgd 				}
    497   1.4   mycroft 				ce = NULL;
    498   1.4   mycroft 			}
    499   1.4   mycroft 
    500   1.7       cgd 			/*
    501  1.16       jdc 			 * Unset colour if appropriate.  Check to see
    502  1.16       jdc 			 * if we also turn off standout, underscore and
    503  1.16       jdc 			 * attributes.
    504  1.16       jdc 			 */
    505  1.16       jdc 			if (!(nsp->attr & __COLOR) &&
    506  1.16       jdc 			    (curscr->wattr & __COLOR)) {
    507  1.41       jdc 				if (__tc_oc != NULL && __tc_cc == NULL)
    508  1.41       jdc 					tputs(__tc_oc, 0, __cputchar);
    509  1.41       jdc 				if (__tc_op != NULL) {
    510  1.41       jdc 					tputs(__tc_op, 0, __cputchar);
    511  1.41       jdc 					curscr->wattr &= __mask_op;
    512  1.16       jdc 				}
    513  1.27   mycroft 			}
    514  1.27   mycroft 
    515  1.27   mycroft 			off = ~nsp->attr & curscr->wattr;
    516  1.16       jdc 
    517  1.16       jdc 			/*
    518  1.11       mrg 			 * Unset attributes as appropriate.  Unset first
    519  1.11       mrg 			 * so that the relevant attributes can be reset
    520  1.16       jdc 			 * (because 'me' unsets 'mb', 'md', 'mh', 'mk',
    521  1.16       jdc 			 * 'mp' and 'mr').  Check to see if we also turn off
    522  1.27   mycroft 			 * standout, attributes and colour.
    523  1.11       mrg 			 */
    524  1.41       jdc 			if (off & __TERMATTR && __tc_me != NULL) {
    525  1.41       jdc 				tputs(__tc_me, 0, __cputchar);
    526  1.41       jdc 				curscr->wattr &= __mask_me;
    527  1.41       jdc 				off &= __mask_me;
    528  1.11       mrg 			}
    529  1.11       mrg 
    530  1.11       mrg 			/*
    531  1.11       mrg 			 * Exit underscore mode if appropriate.
    532  1.27   mycroft 			 * Check to see if we also turn off standout,
    533  1.27   mycroft 			 * attributes and colour.
    534  1.11       mrg 			 */
    535  1.41       jdc 			if (off & __UNDERSCORE && __tc_ue != NULL) {
    536  1.41       jdc 				tputs(__tc_ue, 0, __cputchar);
    537  1.41       jdc 				curscr->wattr &= __mask_ue;
    538  1.41       jdc 				off &= __mask_ue;
    539  1.11       mrg 			}
    540  1.11       mrg 
    541  1.11       mrg 			/*
    542  1.27   mycroft 			 * Exit standout mode as appropriate.
    543  1.27   mycroft 			 * Check to see if we also turn off underscore,
    544  1.27   mycroft 			 * attributes and colour.
    545   1.7       cgd 			 * XXX
    546  1.41       jdc 			 * Should use uc if so/se not available.
    547   1.7       cgd 			 */
    548  1.41       jdc 			if (off & __STANDOUT && __tc_se != NULL) {
    549  1.41       jdc 				tputs(__tc_se, 0, __cputchar);
    550  1.41       jdc 				curscr->wattr &= __mask_se;
    551  1.41       jdc 				off &= __mask_se;
    552  1.27   mycroft 			}
    553  1.27   mycroft 
    554  1.41       jdc 			if (off & __ALTCHARSET && __tc_ae != NULL) {
    555  1.41       jdc 				tputs(__tc_ae, 0, __cputchar);
    556  1.27   mycroft 				curscr->wattr &= ~__ALTCHARSET;
    557  1.27   mycroft 			}
    558  1.27   mycroft 
    559  1.27   mycroft 			on = nsp->attr & ~curscr->wattr;
    560  1.27   mycroft 
    561  1.27   mycroft 			/*
    562  1.27   mycroft 			 * Enter standout mode if appropriate.
    563  1.27   mycroft 			 */
    564  1.41       jdc 			if (on & __STANDOUT && __tc_so != NULL && __tc_se
    565  1.41       jdc 			    != NULL) {
    566  1.41       jdc 				tputs(__tc_so, 0, __cputchar);
    567  1.27   mycroft 				curscr->wattr |= __STANDOUT;
    568  1.11       mrg 			}
    569  1.11       mrg 
    570  1.11       mrg 			/*
    571  1.11       mrg 			 * Enter underscore mode if appropriate.
    572  1.11       mrg 			 * XXX
    573  1.41       jdc 			 * Should use uc if us/ue not available.
    574  1.11       mrg 			 */
    575  1.41       jdc 			if (on & __UNDERSCORE && __tc_us != NULL &&
    576  1.41       jdc 			    __tc_ue != NULL) {
    577  1.41       jdc 				tputs(__tc_us, 0, __cputchar);
    578  1.15     blymn 				curscr->wattr |= __UNDERSCORE;
    579  1.11       mrg 			}
    580  1.11       mrg 
    581  1.11       mrg 			/*
    582  1.11       mrg 			 * Set other attributes as appropriate.
    583  1.11       mrg 			 */
    584  1.41       jdc 			if (__tc_me != NULL) {
    585  1.41       jdc 				if (on & __BLINK && __tc_mb != NULL) {
    586  1.41       jdc 					tputs(__tc_mb, 0, __cputchar);
    587  1.27   mycroft 					curscr->wattr |= __BLINK;
    588  1.27   mycroft 				}
    589  1.41       jdc 				if (on & __BOLD && __tc_md != NULL) {
    590  1.41       jdc 					tputs(__tc_md, 0, __cputchar);
    591  1.27   mycroft 					curscr->wattr |= __BOLD;
    592  1.27   mycroft 				}
    593  1.41       jdc 				if (on & __DIM && __tc_mh != NULL) {
    594  1.41       jdc 					tputs(__tc_mh, 0, __cputchar);
    595  1.27   mycroft 					curscr->wattr |= __DIM;
    596  1.27   mycroft 				}
    597  1.41       jdc 				if (on & __BLANK && __tc_mk != NULL) {
    598  1.41       jdc 					tputs(__tc_mk, 0, __cputchar);
    599  1.27   mycroft 					curscr->wattr |= __BLANK;
    600  1.27   mycroft 				}
    601  1.41       jdc 				if (on & __PROTECT && __tc_mp != NULL) {
    602  1.41       jdc 					tputs(__tc_mp, 0, __cputchar);
    603  1.27   mycroft 					curscr->wattr |= __PROTECT;
    604  1.27   mycroft 				}
    605  1.41       jdc 				if (on & __REVERSE && __tc_mr != NULL) {
    606  1.41       jdc 					tputs(__tc_mr, 0, __cputchar);
    607  1.27   mycroft 					curscr->wattr |= __REVERSE;
    608  1.27   mycroft 				}
    609  1.15     blymn 			}
    610  1.15     blymn 
    611  1.16       jdc 			/* Set/change colour as appropriate. */
    612  1.41       jdc 			if ((nsp->attr & __COLOR) && __tc_Co != NULL &&
    613  1.41       jdc 			    (__tc_oc != NULL || __tc_op != NULL)) {
    614  1.23       jdc 				if ((nsp->attr & __COLOR) !=
    615  1.23       jdc 				    (curscr->wattr & __COLOR)) {
    616  1.23       jdc 					__set_color(nsp->attr);
    617  1.23       jdc 					curscr->wattr &= ~__COLOR;
    618  1.23       jdc 					curscr->wattr |= nsp->attr &
    619  1.23       jdc 					    __COLOR;
    620  1.16       jdc 				}
    621  1.16       jdc 			}
    622  1.16       jdc 
    623  1.15     blymn 			/* Enter/exit altcharset mode as appropriate. */
    624  1.41       jdc 			if (on & __ALTCHARSET && __tc_as != NULL &&
    625  1.41       jdc 			    __tc_ae != NULL) {
    626  1.41       jdc 				tputs(__tc_as, 0, __cputchar);
    627  1.27   mycroft 				curscr->wattr |= __ALTCHARSET;
    628  1.11       mrg 			}
    629   1.4   mycroft 
    630   1.4   mycroft 			wx++;
    631  1.23       jdc 			if (wx >= win->maxx &&
    632  1.43     blymn 			    wy == win->maxy - 1 && !_cursesi_screen->curwin)
    633   1.5       cgd 				if (win->flags & __SCROLLOK) {
    634  1.28   mycroft 					if (win->flags & __ENDLINE)
    635  1.23       jdc 						__unsetattr(1);
    636   1.5       cgd 					if (!(win->flags & __SCROLLWIN)) {
    637  1.43     blymn 						if (!_cursesi_screen->curwin) {
    638  1.23       jdc 							csp->attr = nsp->attr;
    639  1.39    itojun 							__cputchar((int)
    640  1.23       jdc 							    (csp->ch =
    641  1.23       jdc 							    nsp->ch));
    642   1.5       cgd 						} else
    643  1.39    itojun 							__cputchar((int) nsp->ch);
    644   1.5       cgd 					}
    645  1.23       jdc 					if (wx < curscr->maxx) {
    646  1.43     blymn 						domvcur(_cursesi_screen->ly, wx,
    647  1.23       jdc 						    (int) (win->maxy - 1),
    648  1.23       jdc 						    (int) (win->maxx - 1));
    649   1.5       cgd 					}
    650  1.43     blymn 					_cursesi_screen->ly = win->maxy - 1;
    651  1.43     blymn 					_cursesi_screen->lx = win->maxx - 1;
    652   1.4   mycroft 					return (OK);
    653   1.7       cgd 				}
    654   1.7       cgd 			if (wx < win->maxx || wy < win->maxy - 1 ||
    655   1.5       cgd 			    !(win->flags & __SCROLLWIN)) {
    656  1.43     blymn 				if (!_cursesi_screen->curwin) {
    657  1.23       jdc 					csp->attr = nsp->attr;
    658  1.39    itojun 					__cputchar((int) (csp->ch = nsp->ch));
    659   1.5       cgd 					csp++;
    660   1.7       cgd 				} else
    661  1.39    itojun 					__cputchar((int) nsp->ch);
    662   1.5       cgd 			}
    663   1.4   mycroft #ifdef DEBUG
    664   1.5       cgd 			__CTRACE("makech: putchar(%c)\n", nsp->ch & 0177);
    665   1.4   mycroft #endif
    666  1.41       jdc 			if (__tc_uc && ((nsp->attr & __STANDOUT) ||
    667  1.11       mrg 			    (nsp->attr & __UNDERSCORE))) {
    668  1.39    itojun 				__cputchar('\b');
    669  1.41       jdc 				tputs(__tc_uc, 0, __cputchar);
    670   1.1       cgd 			}
    671   1.4   mycroft 			nsp++;
    672   1.4   mycroft #ifdef DEBUG
    673  1.43     blymn 			__CTRACE("makech: 2: wx = %d, lx = %d\n", wx, _cursesi_screen->lx);
    674   1.4   mycroft #endif
    675   1.5       cgd 		}
    676  1.43     blymn 		if (_cursesi_screen->lx == wx)	/* If no change. */
    677   1.4   mycroft 			break;
    678  1.43     blymn 		_cursesi_screen->lx = wx;
    679  1.43     blymn 		if (_cursesi_screen->lx >= COLS && __tc_am)
    680  1.43     blymn 			_cursesi_screen->lx = COLS - 1;
    681  1.11       mrg 		else
    682  1.11       mrg 			if (wx >= win->maxx) {
    683  1.43     blymn 				domvcur(_cursesi_screen->ly,
    684  1.43     blymn 					_cursesi_screen->lx,
    685  1.43     blymn 					_cursesi_screen->ly,
    686  1.43     blymn 					(int) (win->maxx - 1));
    687  1.43     blymn 				_cursesi_screen->lx = win->maxx - 1;
    688  1.11       mrg 			}
    689   1.4   mycroft #ifdef DEBUG
    690  1.43     blymn 		__CTRACE("makech: 3: wx = %d, lx = %d\n", wx,
    691  1.43     blymn 			 _cursesi_screen->lx);
    692   1.4   mycroft #endif
    693   1.1       cgd 	}
    694   1.7       cgd 
    695   1.4   mycroft 	return (OK);
    696   1.1       cgd }
    697   1.1       cgd 
    698   1.1       cgd /*
    699   1.4   mycroft  * domvcur --
    700  1.19       jdc  *	Do a mvcur, leaving attributes if necessary.
    701   1.1       cgd  */
    702   1.4   mycroft static void
    703   1.1       cgd domvcur(oy, ox, ny, nx)
    704  1.11       mrg 	int	oy, ox, ny, nx;
    705   1.4   mycroft {
    706  1.23       jdc 	__unsetattr(1);
    707   1.5       cgd 	__mvcur(oy, ox, ny, nx, 1);
    708   1.5       cgd }
    709   1.5       cgd 
    710   1.5       cgd /*
    711   1.5       cgd  * Quickch() attempts to detect a pattern in the change of the window
    712   1.7       cgd  * in order to optimize the change, e.g., scroll n lines as opposed to
    713   1.5       cgd  * repainting the screen line by line.
    714   1.5       cgd  */
    715   1.5       cgd 
    716  1.46  christos static __LDATA buf[128];
    717  1.46  christos static  u_int last_hash;
    718  1.46  christos static  size_t last_hash_len;
    719  1.46  christos #define BLANKSIZE (sizeof(buf) / sizeof(buf[0]))
    720  1.46  christos 
    721   1.5       cgd static void
    722  1.23       jdc quickch(void)
    723   1.5       cgd {
    724  1.23       jdc #define THRESH		(int) __virtscr->maxy / 4
    725   1.5       cgd 
    726  1.10     perry 	__LINE *clp, *tmp1, *tmp2;
    727  1.11       mrg 	int	bsize, curs, curw, starts, startw, i, j;
    728  1.11       mrg 	int	n, target, cur_period, bot, top, sc_region;
    729  1.11       mrg 	u_int	blank_hash;
    730  1.22       jdc 	attr_t	bcolor;
    731   1.5       cgd 
    732   1.8     mikel #ifdef __GNUC__
    733  1.11       mrg 	curs = curw = starts = startw = 0;	/* XXX gcc -Wuninitialized */
    734   1.8     mikel #endif
    735   1.7       cgd 	/*
    736   1.5       cgd 	 * Find how many lines from the top of the screen are unchanged.
    737   1.5       cgd 	 */
    738  1.23       jdc 	for (top = 0; top < __virtscr->maxy; top++)
    739  1.35   mycroft 		if (__virtscr->lines[top]->flags & __ISDIRTY &&
    740  1.35   mycroft 		    (__virtscr->lines[top]->hash != curscr->lines[top]->hash ||
    741  1.35   mycroft 		     memcmp(__virtscr->lines[top]->line,
    742  1.32   mycroft 			  curscr->lines[top]->line,
    743  1.35   mycroft 			  (size_t) __virtscr->maxx * __LDATASIZE) != 0))
    744   1.5       cgd 			break;
    745   1.5       cgd 		else
    746  1.23       jdc 			__virtscr->lines[top]->flags &= ~__ISDIRTY;
    747  1.11       mrg 	/*
    748  1.11       mrg 	 * Find how many lines from bottom of screen are unchanged.
    749  1.11       mrg 	 */
    750  1.23       jdc 	for (bot = __virtscr->maxy - 1; bot >= 0; bot--)
    751  1.35   mycroft 		if (__virtscr->lines[bot]->flags & __ISDIRTY &&
    752  1.35   mycroft 		    (__virtscr->lines[bot]->hash != curscr->lines[bot]->hash ||
    753  1.35   mycroft 		     memcmp(__virtscr->lines[bot]->line,
    754  1.32   mycroft 			  curscr->lines[bot]->line,
    755  1.35   mycroft 			  (size_t) __virtscr->maxx * __LDATASIZE) != 0))
    756   1.5       cgd 			break;
    757   1.5       cgd 		else
    758  1.23       jdc 			__virtscr->lines[bot]->flags &= ~__ISDIRTY;
    759  1.23       jdc 
    760  1.23       jdc 	/*
    761  1.23       jdc 	 * Work round an xterm bug where inserting lines causes all the
    762  1.23       jdc 	 * inserted lines to be covered with the background colour we
    763  1.23       jdc 	 * set on the first line (even if we unset it for subsequent
    764  1.23       jdc 	 * lines).
    765  1.23       jdc 	 */
    766  1.23       jdc 	bcolor = __virtscr->lines[min(top,
    767  1.23       jdc 	    __virtscr->maxy - 1)]->line[0].attr & __COLOR;
    768  1.23       jdc 	for (i = top + 1, j = 0; i < bot; i++) {
    769  1.23       jdc 		if ((__virtscr->lines[i]->line[0].attr & __COLOR) != bcolor) {
    770  1.23       jdc 			bcolor = __virtscr->lines[i]->line[__virtscr->maxx].
    771  1.23       jdc 			    attr & __COLOR;
    772  1.23       jdc 			j = i - top;
    773  1.23       jdc 		} else
    774  1.23       jdc 			break;
    775  1.23       jdc 	}
    776  1.23       jdc 	top += j;
    777   1.5       cgd 
    778   1.5       cgd #ifdef NO_JERKINESS
    779   1.5       cgd 	/*
    780   1.5       cgd 	 * If we have a bottom unchanged region return.  Scrolling the
    781   1.5       cgd 	 * bottom region up and then back down causes a screen jitter.
    782   1.5       cgd 	 * This will increase the number of characters sent to the screen
    783   1.5       cgd 	 * but it looks better.
    784   1.5       cgd 	 */
    785  1.23       jdc 	if (bot < __virtscr->maxy - 1)
    786   1.5       cgd 		return;
    787  1.11       mrg #endif				/* NO_JERKINESS */
    788   1.5       cgd 
    789   1.5       cgd 	/*
    790   1.5       cgd 	 * Search for the largest block of text not changed.
    791   1.5       cgd 	 * Invariants of the loop:
    792  1.23       jdc 	 * - Startw is the index of the beginning of the examined block in
    793  1.23       jdc 	 *   __virtscr.
    794  1.11       mrg 	 * - Starts is the index of the beginning of the examined block in
    795  1.23       jdc 	 *   curscr.
    796   1.7       cgd 	 * - Curw is the index of one past the end of the exmined block in
    797  1.23       jdc 	 *   __virtscr.
    798  1.23       jdc 	 * - Curs is the index of one past the end of the exmined block in
    799   1.5       cgd 	 *   curscr.
    800   1.5       cgd 	 * - bsize is the current size of the examined block.
    801  1.11       mrg 	*/
    802  1.23       jdc 
    803   1.5       cgd 	for (bsize = bot - top; bsize >= THRESH; bsize--) {
    804   1.5       cgd 		for (startw = top; startw <= bot - bsize; startw++)
    805   1.7       cgd 			for (starts = top; starts <= bot - bsize;
    806  1.11       mrg 			    starts++) {
    807   1.5       cgd 				for (curw = startw, curs = starts;
    808  1.11       mrg 				    curs < starts + bsize; curw++, curs++)
    809  1.35   mycroft 					if (__virtscr->lines[curw]->hash !=
    810  1.35   mycroft 					    curscr->lines[curs]->hash)
    811  1.32   mycroft 						break;
    812  1.32   mycroft 				if (curs != starts + bsize)
    813  1.32   mycroft 					continue;
    814  1.32   mycroft 				for (curw = startw, curs = starts;
    815  1.32   mycroft 				    curs < starts + bsize; curw++, curs++)
    816  1.32   mycroft 					if (memcmp(__virtscr->lines[curw]->line,
    817  1.32   mycroft 					    curscr->lines[curs]->line,
    818  1.32   mycroft 					    (size_t) __virtscr->maxx *
    819  1.32   mycroft 					    __LDATASIZE) != 0)
    820   1.5       cgd 						break;
    821   1.5       cgd 				if (curs == starts + bsize)
    822   1.5       cgd 					goto done;
    823   1.5       cgd 			}
    824   1.5       cgd 	}
    825  1.11       mrg done:
    826  1.22       jdc 
    827   1.5       cgd 	/* Did not find anything */
    828   1.7       cgd 	if (bsize < THRESH)
    829   1.5       cgd 		return;
    830   1.5       cgd 
    831   1.5       cgd #ifdef DEBUG
    832   1.7       cgd 	__CTRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n",
    833  1.11       mrg 	    bsize, starts, startw, curw, curs, top, bot);
    834   1.5       cgd #endif
    835   1.5       cgd 
    836   1.7       cgd 	/*
    837   1.7       cgd 	 * Make sure that there is no overlap between the bottom and top
    838   1.5       cgd 	 * regions and the middle scrolled block.
    839   1.5       cgd 	 */
    840   1.5       cgd 	if (bot < curs)
    841   1.5       cgd 		bot = curs - 1;
    842   1.5       cgd 	if (top > starts)
    843   1.5       cgd 		top = starts;
    844   1.5       cgd 
    845   1.5       cgd 	n = startw - starts;
    846   1.5       cgd 
    847   1.5       cgd #ifdef DEBUG
    848  1.11       mrg 	__CTRACE("#####################################\n");
    849  1.11       mrg 	for (i = 0; i < curscr->maxy; i++) {
    850  1.11       mrg 		__CTRACE("C: %d:", i);
    851  1.11       mrg 		__CTRACE(" 0x%x \n", curscr->lines[i]->hash);
    852  1.11       mrg 		for (j = 0; j < curscr->maxx; j++)
    853  1.11       mrg 			__CTRACE("%c", curscr->lines[i]->line[j].ch);
    854  1.11       mrg 		__CTRACE("\n");
    855  1.14    simonb 		__CTRACE(" attr:");
    856  1.11       mrg 		for (j = 0; j < curscr->maxx; j++)
    857  1.14    simonb 			__CTRACE(" %x", curscr->lines[i]->line[j].attr);
    858  1.11       mrg 		__CTRACE("\n");
    859  1.11       mrg 		__CTRACE("W: %d:", i);
    860  1.23       jdc 		__CTRACE(" 0x%x \n", __virtscr->lines[i]->hash);
    861  1.23       jdc 		__CTRACE(" 0x%x ", __virtscr->lines[i]->flags);
    862  1.23       jdc 		for (j = 0; j < __virtscr->maxx; j++)
    863  1.23       jdc 			__CTRACE("%c", __virtscr->lines[i]->line[j].ch);
    864  1.11       mrg 		__CTRACE("\n");
    865  1.14    simonb 		__CTRACE(" attr:");
    866  1.23       jdc 		for (j = 0; j < __virtscr->maxx; j++)
    867  1.23       jdc 			__CTRACE(" %x", __virtscr->lines[i]->line[j].attr);
    868  1.11       mrg 		__CTRACE("\n");
    869  1.11       mrg 	}
    870   1.7       cgd #endif
    871   1.7       cgd 
    872  1.46  christos 	if (buf[0].ch != ' ') {
    873  1.46  christos 		for (i = 0; i < BLANKSIZE; i++) {
    874  1.46  christos 			buf[i].ch = ' ';
    875  1.46  christos 			buf[i].bch = ' ';
    876  1.46  christos 			buf[i].attr = 0;
    877  1.46  christos 			buf[i].battr = 0;
    878  1.46  christos 		}
    879   1.5       cgd 	}
    880  1.46  christos 
    881  1.46  christos 	if (__virtscr->maxx != last_hash_len) {
    882  1.46  christos 		blank_hash = 0;
    883  1.46  christos 		for (i = __virtscr->maxx; i > BLANKSIZE; i -= BLANKSIZE) {
    884  1.46  christos 			blank_hash = __hash_more((char *)(void *)buf, sizeof(buf),
    885  1.46  christos 			    blank_hash);
    886  1.46  christos 		}
    887  1.46  christos 		blank_hash = __hash_more((char *)(void *)buf,
    888  1.46  christos 		    i * sizeof(buf[0]), blank_hash);
    889  1.46  christos 		/* cache result in static data - screen width doesn't change often */
    890  1.46  christos 		last_hash_len = __virtscr->maxx;
    891  1.46  christos 		last_hash = blank_hash;
    892  1.46  christos 	} else
    893  1.46  christos 		blank_hash = last_hash;
    894   1.5       cgd 
    895   1.5       cgd 	/*
    896   1.5       cgd 	 * Perform the rotation to maintain the consistency of curscr.
    897   1.5       cgd 	 * This is hairy since we are doing an *in place* rotation.
    898   1.5       cgd 	 * Invariants of the loop:
    899   1.5       cgd 	 * - I is the index of the current line.
    900   1.5       cgd 	 * - Target is the index of the target of line i.
    901   1.5       cgd 	 * - Tmp1 points to current line (i).
    902   1.5       cgd 	 * - Tmp2 and points to target line (target);
    903   1.7       cgd 	 * - Cur_period is the index of the end of the current period.
    904   1.5       cgd 	 *   (see below).
    905   1.5       cgd 	 *
    906   1.5       cgd 	 * There are 2 major issues here that make this rotation non-trivial:
    907   1.5       cgd 	 * 1.  Scrolling in a scrolling region bounded by the top
    908   1.5       cgd 	 *     and bottom regions determined (whose size is sc_region).
    909   1.7       cgd 	 * 2.  As a result of the use of the mod function, there may be a
    910   1.5       cgd 	 *     period introduced, i.e., 2 maps to 4, 4 to 6, n-2 to 0, and
    911   1.5       cgd 	 *     0 to 2, which then causes all odd lines not to be rotated.
    912   1.7       cgd 	 *     To remedy this, an index of the end ( = beginning) of the
    913   1.7       cgd 	 *     current 'period' is kept, cur_period, and when it is reached,
    914   1.7       cgd 	 *     the next period is started from cur_period + 1 which is
    915   1.5       cgd 	 *     guaranteed not to have been reached since that would mean that
    916   1.5       cgd 	 *     all records would have been reached. (think about it...).
    917   1.7       cgd 	 *
    918   1.5       cgd 	 * Lines in the rotation can have 3 attributes which are marked on the
    919   1.5       cgd 	 * line so that curscr is consistent with the visual screen.
    920   1.5       cgd 	 * 1.  Not dirty -- lines inside the scrolled block, top region or
    921   1.5       cgd 	 *                  bottom region.
    922   1.7       cgd 	 * 2.  Blank lines -- lines in the differential of the scrolling
    923   1.7       cgd 	 *		      region adjacent to top and bot regions
    924   1.5       cgd 	 *                    depending on scrolling direction.
    925   1.5       cgd 	 * 3.  Dirty line -- all other lines are marked dirty.
    926   1.5       cgd 	 */
    927   1.5       cgd 	sc_region = bot - top + 1;
    928   1.5       cgd 	i = top;
    929   1.5       cgd 	tmp1 = curscr->lines[top];
    930   1.5       cgd 	cur_period = top;
    931   1.5       cgd 	for (j = top; j <= bot; j++) {
    932   1.5       cgd 		target = (i - top + n + sc_region) % sc_region + top;
    933   1.5       cgd 		tmp2 = curscr->lines[target];
    934   1.5       cgd 		curscr->lines[target] = tmp1;
    935   1.5       cgd 		/* Mark block as clean and blank out scrolled lines. */
    936   1.5       cgd 		clp = curscr->lines[target];
    937   1.5       cgd #ifdef DEBUG
    938   1.5       cgd 		__CTRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ",
    939  1.11       mrg 		    n, startw, curw, i, target);
    940   1.5       cgd #endif
    941   1.7       cgd 		if ((target >= startw && target < curw) || target < top
    942   1.5       cgd 		    || target > bot) {
    943   1.5       cgd #ifdef DEBUG
    944  1.22       jdc 			__CTRACE("-- notdirty\n");
    945   1.5       cgd #endif
    946  1.23       jdc 			__virtscr->lines[target]->flags &= ~__ISDIRTY;
    947  1.11       mrg 		} else
    948  1.11       mrg 			if ((n > 0 && target >= top && target < top + n) ||
    949  1.11       mrg 			    (n < 0 && target <= bot && target > bot + n)) {
    950  1.11       mrg 				if (clp->hash != blank_hash || memcmp(clp->line,
    951  1.46  christos 				    clp->line + 1, (__virtscr->maxx - 1) *
    952  1.46  christos 				    __LDATASIZE) || memcmp(clp->line, buf,
    953  1.46  christos 				    __LDATASIZE)) {
    954  1.46  christos 					for (i = __virtscr->maxx; i > BLANKSIZE;
    955  1.46  christos 					    i -= BLANKSIZE) {
    956  1.46  christos 						(void)memcpy(clp->line + i -
    957  1.46  christos 						    BLANKSIZE, buf, sizeof(buf));
    958  1.46  christos 					}
    959  1.46  christos 					(void)memcpy(clp->line , buf, i *
    960  1.46  christos 					    sizeof(buf[0]));
    961  1.11       mrg #ifdef DEBUG
    962  1.22       jdc 					__CTRACE("-- blanked out: dirty\n");
    963  1.11       mrg #endif
    964  1.11       mrg 					clp->hash = blank_hash;
    965  1.35   mycroft 					__touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1);
    966  1.11       mrg 				} else {
    967   1.5       cgd #ifdef DEBUG
    968  1.22       jdc 					__CTRACE(" -- blank line already: dirty\n");
    969   1.5       cgd #endif
    970  1.35   mycroft 					__touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1);
    971  1.11       mrg 				}
    972   1.5       cgd 			} else {
    973   1.5       cgd #ifdef DEBUG
    974  1.22       jdc 				__CTRACE(" -- dirty\n");
    975   1.5       cgd #endif
    976  1.35   mycroft 				__touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1);
    977   1.5       cgd 			}
    978   1.5       cgd 		if (target == cur_period) {
    979   1.5       cgd 			i = target + 1;
    980   1.5       cgd 			tmp1 = curscr->lines[i];
    981   1.5       cgd 			cur_period = i;
    982   1.5       cgd 		} else {
    983   1.5       cgd 			tmp1 = tmp2;
    984   1.5       cgd 			i = target;
    985   1.5       cgd 		}
    986   1.5       cgd 	}
    987   1.5       cgd #ifdef DEBUG
    988  1.11       mrg 	__CTRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
    989  1.11       mrg 	for (i = 0; i < curscr->maxy; i++) {
    990  1.11       mrg 		__CTRACE("C: %d:", i);
    991  1.11       mrg 		for (j = 0; j < curscr->maxx; j++)
    992  1.11       mrg 			__CTRACE("%c", curscr->lines[i]->line[j].ch);
    993  1.11       mrg 		__CTRACE("\n");
    994  1.11       mrg 		__CTRACE("W: %d:", i);
    995  1.23       jdc 		for (j = 0; j < __virtscr->maxx; j++)
    996  1.23       jdc 			__CTRACE("%c", __virtscr->lines[i]->line[j].ch);
    997  1.11       mrg 		__CTRACE("\n");
    998  1.11       mrg 	}
    999   1.5       cgd #endif
   1000  1.23       jdc 	if (n != 0)
   1001  1.23       jdc 		scrolln(starts, startw, curs, bot, top);
   1002   1.5       cgd }
   1003   1.5       cgd 
   1004   1.5       cgd /*
   1005   1.7       cgd  * scrolln --
   1006   1.7       cgd  *	Scroll n lines, where n is starts - startw.
   1007   1.5       cgd  */
   1008  1.11       mrg static void /* ARGSUSED */
   1009  1.23       jdc scrolln(starts, startw, curs, bot, top)
   1010  1.11       mrg 	int	starts, startw, curs, bot, top;
   1011   1.5       cgd {
   1012  1.11       mrg 	int	i, oy, ox, n;
   1013   1.5       cgd 
   1014   1.5       cgd 	oy = curscr->cury;
   1015   1.5       cgd 	ox = curscr->curx;
   1016   1.5       cgd 	n = starts - startw;
   1017   1.5       cgd 
   1018   1.7       cgd 	/*
   1019   1.7       cgd 	 * XXX
   1020   1.7       cgd 	 * The initial tests that set __noqch don't let us reach here unless
   1021  1.41       jdc 	 * we have either cs + ho + SF/sf/SR/sr, or AL + DL.  SF/sf and SR/sr
   1022   1.7       cgd 	 * scrolling can only shift the entire scrolling region, not just a
   1023   1.7       cgd 	 * part of it, which means that the quickch() routine is going to be
   1024  1.41       jdc 	 * sadly disappointed in us if we don't have cs as well.
   1025   1.7       cgd 	 *
   1026  1.41       jdc 	 * If cs, ho and SF/sf are set, can use the scrolling region.  Because
   1027  1.41       jdc 	 * the cursor position after cs is undefined, we need ho which gives us
   1028   1.7       cgd 	 * the ability to move to somewhere without knowledge of the current
   1029   1.7       cgd 	 * location of the cursor.  Still call __mvcur() anyway, to update its
   1030   1.7       cgd 	 * idea of where the cursor is.
   1031   1.7       cgd 	 *
   1032   1.7       cgd 	 * When the scrolling region has been set, the cursor has to be at the
   1033   1.7       cgd 	 * last line of the region to make the scroll happen.
   1034   1.7       cgd 	 *
   1035   1.7       cgd 	 * Doing SF/SR or AL/DL appears faster on the screen than either sf/sr
   1036  1.41       jdc 	 * or AL/DL, and, some terminals have AL/DL, sf/sr, and cs, but not
   1037   1.7       cgd 	 * SF/SR.  So, if we're scrolling almost all of the screen, try and use
   1038   1.7       cgd 	 * AL/DL, otherwise use the scrolling region.  The "almost all" is a
   1039   1.7       cgd 	 * shameless hack for vi.
   1040   1.7       cgd 	 */
   1041   1.5       cgd 	if (n > 0) {
   1042  1.41       jdc 		if (__tc_cs != NULL && __tc_ho != NULL && (__tc_SF != NULL ||
   1043  1.41       jdc 		    ((__tc_AL == NULL || __tc_DL == NULL ||
   1044  1.41       jdc 		    top > 3 || bot + 3 < __virtscr->maxy) &&
   1045  1.41       jdc 		    __tc_sf != NULL))) {
   1046  1.41       jdc 			tputs(__tscroll(__tc_cs, top, bot + 1), 0, __cputchar);
   1047   1.7       cgd 			__mvcur(oy, ox, 0, 0, 1);
   1048  1.41       jdc 			tputs(__tc_ho, 0, __cputchar);
   1049   1.7       cgd 			__mvcur(0, 0, bot, 0, 1);
   1050  1.41       jdc 			if (__tc_SF != NULL)
   1051  1.41       jdc 				tputs(__tscroll(__tc_SF, n, 0), 0, __cputchar);
   1052   1.7       cgd 			else
   1053   1.7       cgd 				for (i = 0; i < n; i++)
   1054  1.41       jdc 					tputs(__tc_sf, 0, __cputchar);
   1055  1.41       jdc 			tputs(__tscroll(__tc_cs, 0, (int) __virtscr->maxy), 0,
   1056  1.41       jdc 			    __cputchar);
   1057   1.7       cgd 			__mvcur(bot, 0, 0, 0, 1);
   1058  1.41       jdc 			tputs(__tc_ho, 0, __cputchar);
   1059   1.7       cgd 			__mvcur(0, 0, oy, ox, 1);
   1060   1.7       cgd 			return;
   1061   1.7       cgd 		}
   1062   1.7       cgd 
   1063   1.7       cgd 		/* Scroll up the block. */
   1064  1.41       jdc 		if (__tc_SF != NULL && top == 0) {
   1065   1.7       cgd 			__mvcur(oy, ox, bot, 0, 1);
   1066  1.41       jdc 			tputs(__tscroll(__tc_SF, n, 0), 0, __cputchar);
   1067   1.7       cgd 		} else
   1068  1.41       jdc 			if (__tc_DL != NULL) {
   1069  1.11       mrg 				__mvcur(oy, ox, top, 0, 1);
   1070  1.41       jdc 				tputs(__tscroll(__tc_DL, n, 0), 0, __cputchar);
   1071  1.11       mrg 			} else
   1072  1.41       jdc 				if (__tc_dl != NULL) {
   1073  1.11       mrg 					__mvcur(oy, ox, top, 0, 1);
   1074  1.11       mrg 					for (i = 0; i < n; i++)
   1075  1.41       jdc 						tputs(__tc_dl, 0, __cputchar);
   1076  1.11       mrg 				} else
   1077  1.41       jdc 					if (__tc_sf != NULL && top == 0) {
   1078  1.11       mrg 						__mvcur(oy, ox, bot, 0, 1);
   1079  1.11       mrg 						for (i = 0; i < n; i++)
   1080  1.41       jdc 							tputs(__tc_sf, 0,
   1081  1.41       jdc 							    __cputchar);
   1082  1.11       mrg 					} else
   1083  1.11       mrg 						abort();
   1084   1.5       cgd 
   1085   1.7       cgd 		/* Push down the bottom region. */
   1086   1.5       cgd 		__mvcur(top, 0, bot - n + 1, 0, 1);
   1087  1.41       jdc 		if (__tc_AL != NULL)
   1088  1.41       jdc 			tputs(__tscroll(__tc_AL, n, 0), 0, __cputchar);
   1089   1.5       cgd 		else
   1090  1.41       jdc 			if (__tc_al != NULL)
   1091  1.11       mrg 				for (i = 0; i < n; i++)
   1092  1.41       jdc 					tputs(__tc_al, 0, __cputchar);
   1093  1.11       mrg 			else
   1094  1.11       mrg 				abort();
   1095   1.5       cgd 		__mvcur(bot - n + 1, 0, oy, ox, 1);
   1096   1.5       cgd 	} else {
   1097   1.7       cgd 		/*
   1098   1.7       cgd 		 * !!!
   1099   1.7       cgd 		 * n < 0
   1100   1.7       cgd 		 *
   1101  1.41       jdc 		 * If cs, ho and SR/sr are set, can use the scrolling region.
   1102   1.7       cgd 		 * See the above comments for details.
   1103   1.7       cgd 		 */
   1104  1.41       jdc 		if (__tc_cs != NULL && __tc_ho != NULL && (__tc_SR != NULL ||
   1105  1.41       jdc 		    ((__tc_AL == NULL || __tc_DL == NULL || top > 3 ||
   1106  1.41       jdc 		    bot + 3 < __virtscr->maxy) && __tc_sr != NULL))) {
   1107  1.41       jdc 			tputs(__tscroll(__tc_cs, top, bot + 1), 0, __cputchar);
   1108   1.7       cgd 			__mvcur(oy, ox, 0, 0, 1);
   1109  1.41       jdc 			tputs(__tc_ho, 0, __cputchar);
   1110   1.7       cgd 			__mvcur(0, 0, top, 0, 1);
   1111   1.7       cgd 
   1112  1.41       jdc 			if (__tc_SR != NULL)
   1113  1.41       jdc 				tputs(__tscroll(__tc_SR, -n, 0), 0, __cputchar);
   1114   1.7       cgd 			else
   1115   1.7       cgd 				for (i = n; i < 0; i++)
   1116  1.41       jdc 					tputs(__tc_sr, 0, __cputchar);
   1117  1.41       jdc 			tputs(__tscroll(__tc_cs, 0, (int) __virtscr->maxy), 0,
   1118  1.41       jdc 			    __cputchar);
   1119   1.7       cgd 			__mvcur(top, 0, 0, 0, 1);
   1120  1.41       jdc 			tputs(__tc_ho, 0, __cputchar);
   1121   1.7       cgd 			__mvcur(0, 0, oy, ox, 1);
   1122   1.7       cgd 			return;
   1123   1.7       cgd 		}
   1124   1.7       cgd 
   1125   1.7       cgd 		/* Preserve the bottom lines. */
   1126   1.7       cgd 		__mvcur(oy, ox, bot + n + 1, 0, 1);
   1127  1.41       jdc 		if (__tc_SR != NULL && bot == __virtscr->maxy)
   1128  1.41       jdc 			tputs(__tscroll(__tc_SR, -n, 0), 0, __cputchar);
   1129   1.5       cgd 		else
   1130  1.41       jdc 			if (__tc_DL != NULL)
   1131  1.41       jdc 				tputs(__tscroll(__tc_DL, -n, 0), 0, __cputchar);
   1132  1.11       mrg 			else
   1133  1.41       jdc 				if (__tc_dl != NULL)
   1134  1.11       mrg 					for (i = n; i < 0; i++)
   1135  1.41       jdc 						tputs(__tc_dl, 0, __cputchar);
   1136  1.11       mrg 				else
   1137  1.41       jdc 					if (__tc_sr != NULL &&
   1138  1.41       jdc 					    bot == __virtscr->maxy)
   1139  1.11       mrg 						for (i = n; i < 0; i++)
   1140  1.41       jdc 							tputs(__tc_sr, 0,
   1141  1.41       jdc 							    __cputchar);
   1142  1.11       mrg 					else
   1143  1.11       mrg 						abort();
   1144   1.7       cgd 
   1145   1.7       cgd 		/* Scroll the block down. */
   1146   1.5       cgd 		__mvcur(bot + n + 1, 0, top, 0, 1);
   1147  1.41       jdc 		if (__tc_AL != NULL)
   1148  1.41       jdc 			tputs(__tscroll(__tc_AL, -n, 0), 0, __cputchar);
   1149   1.5       cgd 		else
   1150  1.41       jdc 			if (__tc_al != NULL)
   1151  1.11       mrg 				for (i = n; i < 0; i++)
   1152  1.41       jdc 					tputs(__tc_al, 0, __cputchar);
   1153  1.11       mrg 			else
   1154  1.11       mrg 				abort();
   1155   1.5       cgd 		__mvcur(top, 0, oy, ox, 1);
   1156  1.19       jdc 	}
   1157  1.19       jdc }
   1158  1.19       jdc 
   1159  1.19       jdc /*
   1160  1.23       jdc  * __unsetattr --
   1161  1.19       jdc  *	Unset attributes on curscr.  Leave standout, attribute and colour
   1162  1.41       jdc  *	modes if necessary (!ms).  Always leave altcharset (xterm at least
   1163  1.19       jdc  *	ignores a cursor move if we don't).
   1164  1.19       jdc  */
   1165  1.23       jdc void /* ARGSUSED */
   1166  1.23       jdc __unsetattr(int checkms)
   1167  1.19       jdc {
   1168  1.19       jdc 	int	isms;
   1169  1.19       jdc 
   1170  1.19       jdc 	if (checkms)
   1171  1.41       jdc 		if (!__tc_ms) {
   1172  1.19       jdc 			isms = 1;
   1173  1.19       jdc 		} else {
   1174  1.19       jdc 			isms = 0;
   1175  1.19       jdc 		}
   1176  1.19       jdc 	else
   1177  1.19       jdc 		isms = 1;
   1178  1.20       jdc #ifdef DEBUG
   1179  1.41       jdc 	__CTRACE("__unsetattr: checkms = %d, ms = %s, wattr = %08x\n",
   1180  1.41       jdc 	    checkms, __tc_ms ? "TRUE" : "FALSE", curscr->wattr);
   1181  1.20       jdc #endif
   1182  1.19       jdc 
   1183  1.20       jdc 	/*
   1184  1.41       jdc          * Don't leave the screen in standout mode (check against ms).  Check
   1185  1.27   mycroft 	 * to see if we also turn off underscore, attributes and colour.
   1186  1.20       jdc 	 */
   1187  1.19       jdc 	if (curscr->wattr & __STANDOUT && isms) {
   1188  1.41       jdc 		tputs(__tc_se, 0, __cputchar);
   1189  1.41       jdc 		curscr->wattr &= __mask_se;
   1190  1.19       jdc 	}
   1191  1.20       jdc 	/*
   1192  1.41       jdc 	 * Don't leave the screen in underscore mode (check against ms).
   1193  1.26       jdc 	 * Check to see if we also turn off attributes.  Assume that we
   1194  1.26       jdc 	 * also turn off colour.
   1195  1.20       jdc 	 */
   1196  1.19       jdc 	if (curscr->wattr & __UNDERSCORE && isms) {
   1197  1.41       jdc 		tputs(__tc_ue, 0, __cputchar);
   1198  1.41       jdc 		curscr->wattr &= __mask_ue;
   1199  1.19       jdc 	}
   1200  1.20       jdc 	/*
   1201  1.41       jdc 	 * Don't leave the screen with attributes set (check against ms).
   1202  1.26       jdc 	 * Assume that also turn off colour.
   1203  1.20       jdc 	 */
   1204  1.20       jdc 	if (curscr->wattr & __TERMATTR && isms) {
   1205  1.41       jdc 		tputs(__tc_me, 0, __cputchar);
   1206  1.41       jdc 		curscr->wattr &= __mask_me;
   1207  1.19       jdc 	}
   1208  1.41       jdc 	/* Don't leave the screen with altcharset set (don't check ms). */
   1209  1.19       jdc 	if (curscr->wattr & __ALTCHARSET) {
   1210  1.41       jdc 		tputs(__tc_ae, 0, __cputchar);
   1211  1.19       jdc 		curscr->wattr &= ~__ALTCHARSET;
   1212  1.19       jdc 	}
   1213  1.41       jdc 	/* Don't leave the screen with colour set (check against ms). */
   1214  1.19       jdc 	if (curscr->wattr & __COLOR && isms) {
   1215  1.41       jdc 		if (__tc_oc != NULL && __tc_cc == NULL)
   1216  1.41       jdc 			tputs(__tc_oc, 0, __cputchar);
   1217  1.41       jdc 		if (__tc_op != NULL) {
   1218  1.41       jdc 			tputs(__tc_op, 0, __cputchar);
   1219  1.41       jdc 			curscr->wattr &= __mask_op;
   1220  1.27   mycroft 		}
   1221   1.7       cgd 	}
   1222   1.1       cgd }
   1223