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