refresh.c revision 1.48 1 1.48 blymn /* $NetBSD: refresh.c,v 1.48 2002/10/22 11:37:34 blymn 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.48 blymn __RCSID("$NetBSD: refresh.c,v 1.48 2002/10/22 11:37:34 blymn 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.48 blymn (size_t) (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 = ␣
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.47 jdc if (__using_color &&
483 1.47 jdc ((lspc & __COLOR) !=
484 1.47 jdc (curscr->wattr & __COLOR)))
485 1.47 jdc __set_color(curscr, lspc &
486 1.47 jdc __COLOR);
487 1.41 jdc tputs(__tc_ce, 0, __cputchar);
488 1.43 blymn _cursesi_screen->lx = wx + win->begx;
489 1.5 cgd while (wx++ <= clsp) {
490 1.5 cgd csp->ch = ' ';
491 1.23 jdc csp->attr = lspc;
492 1.5 cgd csp++;
493 1.5 cgd }
494 1.4 mycroft return (OK);
495 1.1 cgd }
496 1.4 mycroft ce = NULL;
497 1.4 mycroft }
498 1.4 mycroft
499 1.47 jdc #ifdef DEBUG
500 1.47 jdc __CTRACE("makech: have attributes %08x, need attributes %08x\n", curscr->wattr, nsp->attr);
501 1.47 jdc #endif
502 1.27 mycroft
503 1.27 mycroft off = ~nsp->attr & curscr->wattr;
504 1.16 jdc
505 1.16 jdc /*
506 1.11 mrg * Unset attributes as appropriate. Unset first
507 1.11 mrg * so that the relevant attributes can be reset
508 1.16 jdc * (because 'me' unsets 'mb', 'md', 'mh', 'mk',
509 1.16 jdc * 'mp' and 'mr'). Check to see if we also turn off
510 1.27 mycroft * standout, attributes and colour.
511 1.11 mrg */
512 1.41 jdc if (off & __TERMATTR && __tc_me != NULL) {
513 1.41 jdc tputs(__tc_me, 0, __cputchar);
514 1.41 jdc curscr->wattr &= __mask_me;
515 1.41 jdc off &= __mask_me;
516 1.11 mrg }
517 1.11 mrg
518 1.11 mrg /*
519 1.11 mrg * Exit underscore mode if appropriate.
520 1.27 mycroft * Check to see if we also turn off standout,
521 1.27 mycroft * attributes and colour.
522 1.11 mrg */
523 1.41 jdc if (off & __UNDERSCORE && __tc_ue != NULL) {
524 1.41 jdc tputs(__tc_ue, 0, __cputchar);
525 1.41 jdc curscr->wattr &= __mask_ue;
526 1.41 jdc off &= __mask_ue;
527 1.11 mrg }
528 1.11 mrg
529 1.11 mrg /*
530 1.27 mycroft * Exit standout mode as appropriate.
531 1.27 mycroft * Check to see if we also turn off underscore,
532 1.27 mycroft * attributes and colour.
533 1.7 cgd * XXX
534 1.41 jdc * Should use uc if so/se not available.
535 1.7 cgd */
536 1.41 jdc if (off & __STANDOUT && __tc_se != NULL) {
537 1.41 jdc tputs(__tc_se, 0, __cputchar);
538 1.41 jdc curscr->wattr &= __mask_se;
539 1.41 jdc off &= __mask_se;
540 1.27 mycroft }
541 1.27 mycroft
542 1.41 jdc if (off & __ALTCHARSET && __tc_ae != NULL) {
543 1.41 jdc tputs(__tc_ae, 0, __cputchar);
544 1.27 mycroft curscr->wattr &= ~__ALTCHARSET;
545 1.27 mycroft }
546 1.27 mycroft
547 1.47 jdc /* Set/change colour as appropriate. */
548 1.47 jdc if (__using_color)
549 1.47 jdc __set_color(curscr, nsp->attr & __COLOR);
550 1.47 jdc
551 1.27 mycroft on = nsp->attr & ~curscr->wattr;
552 1.27 mycroft
553 1.27 mycroft /*
554 1.27 mycroft * Enter standout mode if appropriate.
555 1.27 mycroft */
556 1.41 jdc if (on & __STANDOUT && __tc_so != NULL && __tc_se
557 1.41 jdc != NULL) {
558 1.41 jdc tputs(__tc_so, 0, __cputchar);
559 1.27 mycroft curscr->wattr |= __STANDOUT;
560 1.11 mrg }
561 1.11 mrg
562 1.11 mrg /*
563 1.11 mrg * Enter underscore mode if appropriate.
564 1.11 mrg * XXX
565 1.41 jdc * Should use uc if us/ue not available.
566 1.11 mrg */
567 1.41 jdc if (on & __UNDERSCORE && __tc_us != NULL &&
568 1.41 jdc __tc_ue != NULL) {
569 1.41 jdc tputs(__tc_us, 0, __cputchar);
570 1.15 blymn curscr->wattr |= __UNDERSCORE;
571 1.11 mrg }
572 1.11 mrg
573 1.11 mrg /*
574 1.11 mrg * Set other attributes as appropriate.
575 1.11 mrg */
576 1.41 jdc if (__tc_me != NULL) {
577 1.41 jdc if (on & __BLINK && __tc_mb != NULL) {
578 1.41 jdc tputs(__tc_mb, 0, __cputchar);
579 1.27 mycroft curscr->wattr |= __BLINK;
580 1.27 mycroft }
581 1.41 jdc if (on & __BOLD && __tc_md != NULL) {
582 1.41 jdc tputs(__tc_md, 0, __cputchar);
583 1.27 mycroft curscr->wattr |= __BOLD;
584 1.27 mycroft }
585 1.41 jdc if (on & __DIM && __tc_mh != NULL) {
586 1.41 jdc tputs(__tc_mh, 0, __cputchar);
587 1.27 mycroft curscr->wattr |= __DIM;
588 1.27 mycroft }
589 1.41 jdc if (on & __BLANK && __tc_mk != NULL) {
590 1.41 jdc tputs(__tc_mk, 0, __cputchar);
591 1.27 mycroft curscr->wattr |= __BLANK;
592 1.27 mycroft }
593 1.41 jdc if (on & __PROTECT && __tc_mp != NULL) {
594 1.41 jdc tputs(__tc_mp, 0, __cputchar);
595 1.27 mycroft curscr->wattr |= __PROTECT;
596 1.27 mycroft }
597 1.41 jdc if (on & __REVERSE && __tc_mr != NULL) {
598 1.41 jdc tputs(__tc_mr, 0, __cputchar);
599 1.27 mycroft curscr->wattr |= __REVERSE;
600 1.27 mycroft }
601 1.15 blymn }
602 1.15 blymn
603 1.15 blymn /* Enter/exit altcharset mode as appropriate. */
604 1.41 jdc if (on & __ALTCHARSET && __tc_as != NULL &&
605 1.41 jdc __tc_ae != NULL) {
606 1.41 jdc tputs(__tc_as, 0, __cputchar);
607 1.27 mycroft curscr->wattr |= __ALTCHARSET;
608 1.11 mrg }
609 1.4 mycroft
610 1.4 mycroft wx++;
611 1.23 jdc if (wx >= win->maxx &&
612 1.43 blymn wy == win->maxy - 1 && !_cursesi_screen->curwin)
613 1.5 cgd if (win->flags & __SCROLLOK) {
614 1.28 mycroft if (win->flags & __ENDLINE)
615 1.23 jdc __unsetattr(1);
616 1.5 cgd if (!(win->flags & __SCROLLWIN)) {
617 1.43 blymn if (!_cursesi_screen->curwin) {
618 1.23 jdc csp->attr = nsp->attr;
619 1.39 itojun __cputchar((int)
620 1.23 jdc (csp->ch =
621 1.23 jdc nsp->ch));
622 1.5 cgd } else
623 1.39 itojun __cputchar((int) nsp->ch);
624 1.5 cgd }
625 1.23 jdc if (wx < curscr->maxx) {
626 1.43 blymn domvcur(_cursesi_screen->ly, wx,
627 1.23 jdc (int) (win->maxy - 1),
628 1.23 jdc (int) (win->maxx - 1));
629 1.5 cgd }
630 1.43 blymn _cursesi_screen->ly = win->maxy - 1;
631 1.43 blymn _cursesi_screen->lx = win->maxx - 1;
632 1.4 mycroft return (OK);
633 1.7 cgd }
634 1.7 cgd if (wx < win->maxx || wy < win->maxy - 1 ||
635 1.5 cgd !(win->flags & __SCROLLWIN)) {
636 1.43 blymn if (!_cursesi_screen->curwin) {
637 1.23 jdc csp->attr = nsp->attr;
638 1.39 itojun __cputchar((int) (csp->ch = nsp->ch));
639 1.5 cgd csp++;
640 1.7 cgd } else
641 1.39 itojun __cputchar((int) nsp->ch);
642 1.5 cgd }
643 1.4 mycroft #ifdef DEBUG
644 1.5 cgd __CTRACE("makech: putchar(%c)\n", nsp->ch & 0177);
645 1.4 mycroft #endif
646 1.41 jdc if (__tc_uc && ((nsp->attr & __STANDOUT) ||
647 1.11 mrg (nsp->attr & __UNDERSCORE))) {
648 1.39 itojun __cputchar('\b');
649 1.41 jdc tputs(__tc_uc, 0, __cputchar);
650 1.1 cgd }
651 1.4 mycroft nsp++;
652 1.4 mycroft #ifdef DEBUG
653 1.43 blymn __CTRACE("makech: 2: wx = %d, lx = %d\n", wx, _cursesi_screen->lx);
654 1.4 mycroft #endif
655 1.5 cgd }
656 1.43 blymn if (_cursesi_screen->lx == wx) /* If no change. */
657 1.4 mycroft break;
658 1.43 blymn _cursesi_screen->lx = wx;
659 1.43 blymn if (_cursesi_screen->lx >= COLS && __tc_am)
660 1.43 blymn _cursesi_screen->lx = COLS - 1;
661 1.11 mrg else
662 1.11 mrg if (wx >= win->maxx) {
663 1.43 blymn domvcur(_cursesi_screen->ly,
664 1.43 blymn _cursesi_screen->lx,
665 1.43 blymn _cursesi_screen->ly,
666 1.43 blymn (int) (win->maxx - 1));
667 1.43 blymn _cursesi_screen->lx = win->maxx - 1;
668 1.11 mrg }
669 1.4 mycroft #ifdef DEBUG
670 1.43 blymn __CTRACE("makech: 3: wx = %d, lx = %d\n", wx,
671 1.43 blymn _cursesi_screen->lx);
672 1.4 mycroft #endif
673 1.1 cgd }
674 1.7 cgd
675 1.4 mycroft return (OK);
676 1.1 cgd }
677 1.1 cgd
678 1.1 cgd /*
679 1.4 mycroft * domvcur --
680 1.19 jdc * Do a mvcur, leaving attributes if necessary.
681 1.1 cgd */
682 1.4 mycroft static void
683 1.1 cgd domvcur(oy, ox, ny, nx)
684 1.11 mrg int oy, ox, ny, nx;
685 1.4 mycroft {
686 1.23 jdc __unsetattr(1);
687 1.5 cgd __mvcur(oy, ox, ny, nx, 1);
688 1.5 cgd }
689 1.5 cgd
690 1.5 cgd /*
691 1.5 cgd * Quickch() attempts to detect a pattern in the change of the window
692 1.7 cgd * in order to optimize the change, e.g., scroll n lines as opposed to
693 1.5 cgd * repainting the screen line by line.
694 1.5 cgd */
695 1.5 cgd
696 1.46 christos static __LDATA buf[128];
697 1.46 christos static u_int last_hash;
698 1.46 christos static size_t last_hash_len;
699 1.46 christos #define BLANKSIZE (sizeof(buf) / sizeof(buf[0]))
700 1.46 christos
701 1.5 cgd static void
702 1.23 jdc quickch(void)
703 1.5 cgd {
704 1.23 jdc #define THRESH (int) __virtscr->maxy / 4
705 1.5 cgd
706 1.10 perry __LINE *clp, *tmp1, *tmp2;
707 1.11 mrg int bsize, curs, curw, starts, startw, i, j;
708 1.11 mrg int n, target, cur_period, bot, top, sc_region;
709 1.11 mrg u_int blank_hash;
710 1.22 jdc attr_t bcolor;
711 1.5 cgd
712 1.8 mikel #ifdef __GNUC__
713 1.11 mrg curs = curw = starts = startw = 0; /* XXX gcc -Wuninitialized */
714 1.8 mikel #endif
715 1.7 cgd /*
716 1.5 cgd * Find how many lines from the top of the screen are unchanged.
717 1.5 cgd */
718 1.23 jdc for (top = 0; top < __virtscr->maxy; top++)
719 1.35 mycroft if (__virtscr->lines[top]->flags & __ISDIRTY &&
720 1.35 mycroft (__virtscr->lines[top]->hash != curscr->lines[top]->hash ||
721 1.35 mycroft memcmp(__virtscr->lines[top]->line,
722 1.32 mycroft curscr->lines[top]->line,
723 1.35 mycroft (size_t) __virtscr->maxx * __LDATASIZE) != 0))
724 1.5 cgd break;
725 1.5 cgd else
726 1.23 jdc __virtscr->lines[top]->flags &= ~__ISDIRTY;
727 1.11 mrg /*
728 1.11 mrg * Find how many lines from bottom of screen are unchanged.
729 1.11 mrg */
730 1.23 jdc for (bot = __virtscr->maxy - 1; bot >= 0; bot--)
731 1.35 mycroft if (__virtscr->lines[bot]->flags & __ISDIRTY &&
732 1.35 mycroft (__virtscr->lines[bot]->hash != curscr->lines[bot]->hash ||
733 1.35 mycroft memcmp(__virtscr->lines[bot]->line,
734 1.32 mycroft curscr->lines[bot]->line,
735 1.35 mycroft (size_t) __virtscr->maxx * __LDATASIZE) != 0))
736 1.5 cgd break;
737 1.5 cgd else
738 1.23 jdc __virtscr->lines[bot]->flags &= ~__ISDIRTY;
739 1.23 jdc
740 1.23 jdc /*
741 1.23 jdc * Work round an xterm bug where inserting lines causes all the
742 1.23 jdc * inserted lines to be covered with the background colour we
743 1.23 jdc * set on the first line (even if we unset it for subsequent
744 1.23 jdc * lines).
745 1.23 jdc */
746 1.23 jdc bcolor = __virtscr->lines[min(top,
747 1.23 jdc __virtscr->maxy - 1)]->line[0].attr & __COLOR;
748 1.23 jdc for (i = top + 1, j = 0; i < bot; i++) {
749 1.23 jdc if ((__virtscr->lines[i]->line[0].attr & __COLOR) != bcolor) {
750 1.23 jdc bcolor = __virtscr->lines[i]->line[__virtscr->maxx].
751 1.23 jdc attr & __COLOR;
752 1.23 jdc j = i - top;
753 1.23 jdc } else
754 1.23 jdc break;
755 1.23 jdc }
756 1.23 jdc top += j;
757 1.5 cgd
758 1.5 cgd #ifdef NO_JERKINESS
759 1.5 cgd /*
760 1.5 cgd * If we have a bottom unchanged region return. Scrolling the
761 1.5 cgd * bottom region up and then back down causes a screen jitter.
762 1.5 cgd * This will increase the number of characters sent to the screen
763 1.5 cgd * but it looks better.
764 1.5 cgd */
765 1.23 jdc if (bot < __virtscr->maxy - 1)
766 1.5 cgd return;
767 1.11 mrg #endif /* NO_JERKINESS */
768 1.5 cgd
769 1.5 cgd /*
770 1.5 cgd * Search for the largest block of text not changed.
771 1.5 cgd * Invariants of the loop:
772 1.23 jdc * - Startw is the index of the beginning of the examined block in
773 1.23 jdc * __virtscr.
774 1.11 mrg * - Starts is the index of the beginning of the examined block in
775 1.23 jdc * curscr.
776 1.7 cgd * - Curw is the index of one past the end of the exmined block in
777 1.23 jdc * __virtscr.
778 1.23 jdc * - Curs is the index of one past the end of the exmined block in
779 1.5 cgd * curscr.
780 1.5 cgd * - bsize is the current size of the examined block.
781 1.11 mrg */
782 1.23 jdc
783 1.5 cgd for (bsize = bot - top; bsize >= THRESH; bsize--) {
784 1.5 cgd for (startw = top; startw <= bot - bsize; startw++)
785 1.7 cgd for (starts = top; starts <= bot - bsize;
786 1.11 mrg starts++) {
787 1.5 cgd for (curw = startw, curs = starts;
788 1.11 mrg curs < starts + bsize; curw++, curs++)
789 1.35 mycroft if (__virtscr->lines[curw]->hash !=
790 1.35 mycroft curscr->lines[curs]->hash)
791 1.32 mycroft break;
792 1.32 mycroft if (curs != starts + bsize)
793 1.32 mycroft continue;
794 1.32 mycroft for (curw = startw, curs = starts;
795 1.32 mycroft curs < starts + bsize; curw++, curs++)
796 1.32 mycroft if (memcmp(__virtscr->lines[curw]->line,
797 1.32 mycroft curscr->lines[curs]->line,
798 1.32 mycroft (size_t) __virtscr->maxx *
799 1.32 mycroft __LDATASIZE) != 0)
800 1.5 cgd break;
801 1.5 cgd if (curs == starts + bsize)
802 1.5 cgd goto done;
803 1.5 cgd }
804 1.5 cgd }
805 1.11 mrg done:
806 1.22 jdc
807 1.5 cgd /* Did not find anything */
808 1.7 cgd if (bsize < THRESH)
809 1.5 cgd return;
810 1.5 cgd
811 1.5 cgd #ifdef DEBUG
812 1.7 cgd __CTRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n",
813 1.11 mrg bsize, starts, startw, curw, curs, top, bot);
814 1.5 cgd #endif
815 1.5 cgd
816 1.7 cgd /*
817 1.7 cgd * Make sure that there is no overlap between the bottom and top
818 1.5 cgd * regions and the middle scrolled block.
819 1.5 cgd */
820 1.5 cgd if (bot < curs)
821 1.5 cgd bot = curs - 1;
822 1.5 cgd if (top > starts)
823 1.5 cgd top = starts;
824 1.5 cgd
825 1.5 cgd n = startw - starts;
826 1.5 cgd
827 1.5 cgd #ifdef DEBUG
828 1.11 mrg __CTRACE("#####################################\n");
829 1.11 mrg for (i = 0; i < curscr->maxy; i++) {
830 1.11 mrg __CTRACE("C: %d:", i);
831 1.11 mrg __CTRACE(" 0x%x \n", curscr->lines[i]->hash);
832 1.11 mrg for (j = 0; j < curscr->maxx; j++)
833 1.11 mrg __CTRACE("%c", curscr->lines[i]->line[j].ch);
834 1.11 mrg __CTRACE("\n");
835 1.14 simonb __CTRACE(" attr:");
836 1.11 mrg for (j = 0; j < curscr->maxx; j++)
837 1.14 simonb __CTRACE(" %x", curscr->lines[i]->line[j].attr);
838 1.11 mrg __CTRACE("\n");
839 1.11 mrg __CTRACE("W: %d:", i);
840 1.23 jdc __CTRACE(" 0x%x \n", __virtscr->lines[i]->hash);
841 1.23 jdc __CTRACE(" 0x%x ", __virtscr->lines[i]->flags);
842 1.23 jdc for (j = 0; j < __virtscr->maxx; j++)
843 1.23 jdc __CTRACE("%c", __virtscr->lines[i]->line[j].ch);
844 1.11 mrg __CTRACE("\n");
845 1.14 simonb __CTRACE(" attr:");
846 1.23 jdc for (j = 0; j < __virtscr->maxx; j++)
847 1.23 jdc __CTRACE(" %x", __virtscr->lines[i]->line[j].attr);
848 1.11 mrg __CTRACE("\n");
849 1.11 mrg }
850 1.7 cgd #endif
851 1.7 cgd
852 1.46 christos if (buf[0].ch != ' ') {
853 1.46 christos for (i = 0; i < BLANKSIZE; i++) {
854 1.46 christos buf[i].ch = ' ';
855 1.46 christos buf[i].bch = ' ';
856 1.46 christos buf[i].attr = 0;
857 1.46 christos buf[i].battr = 0;
858 1.46 christos }
859 1.5 cgd }
860 1.46 christos
861 1.46 christos if (__virtscr->maxx != last_hash_len) {
862 1.46 christos blank_hash = 0;
863 1.46 christos for (i = __virtscr->maxx; i > BLANKSIZE; i -= BLANKSIZE) {
864 1.46 christos blank_hash = __hash_more((char *)(void *)buf, sizeof(buf),
865 1.46 christos blank_hash);
866 1.46 christos }
867 1.46 christos blank_hash = __hash_more((char *)(void *)buf,
868 1.46 christos i * sizeof(buf[0]), blank_hash);
869 1.46 christos /* cache result in static data - screen width doesn't change often */
870 1.46 christos last_hash_len = __virtscr->maxx;
871 1.46 christos last_hash = blank_hash;
872 1.46 christos } else
873 1.46 christos blank_hash = last_hash;
874 1.5 cgd
875 1.5 cgd /*
876 1.5 cgd * Perform the rotation to maintain the consistency of curscr.
877 1.5 cgd * This is hairy since we are doing an *in place* rotation.
878 1.5 cgd * Invariants of the loop:
879 1.5 cgd * - I is the index of the current line.
880 1.5 cgd * - Target is the index of the target of line i.
881 1.5 cgd * - Tmp1 points to current line (i).
882 1.5 cgd * - Tmp2 and points to target line (target);
883 1.7 cgd * - Cur_period is the index of the end of the current period.
884 1.5 cgd * (see below).
885 1.5 cgd *
886 1.5 cgd * There are 2 major issues here that make this rotation non-trivial:
887 1.5 cgd * 1. Scrolling in a scrolling region bounded by the top
888 1.5 cgd * and bottom regions determined (whose size is sc_region).
889 1.7 cgd * 2. As a result of the use of the mod function, there may be a
890 1.5 cgd * period introduced, i.e., 2 maps to 4, 4 to 6, n-2 to 0, and
891 1.5 cgd * 0 to 2, which then causes all odd lines not to be rotated.
892 1.7 cgd * To remedy this, an index of the end ( = beginning) of the
893 1.7 cgd * current 'period' is kept, cur_period, and when it is reached,
894 1.7 cgd * the next period is started from cur_period + 1 which is
895 1.5 cgd * guaranteed not to have been reached since that would mean that
896 1.5 cgd * all records would have been reached. (think about it...).
897 1.7 cgd *
898 1.5 cgd * Lines in the rotation can have 3 attributes which are marked on the
899 1.5 cgd * line so that curscr is consistent with the visual screen.
900 1.5 cgd * 1. Not dirty -- lines inside the scrolled block, top region or
901 1.5 cgd * bottom region.
902 1.7 cgd * 2. Blank lines -- lines in the differential of the scrolling
903 1.7 cgd * region adjacent to top and bot regions
904 1.5 cgd * depending on scrolling direction.
905 1.5 cgd * 3. Dirty line -- all other lines are marked dirty.
906 1.5 cgd */
907 1.5 cgd sc_region = bot - top + 1;
908 1.5 cgd i = top;
909 1.5 cgd tmp1 = curscr->lines[top];
910 1.5 cgd cur_period = top;
911 1.5 cgd for (j = top; j <= bot; j++) {
912 1.5 cgd target = (i - top + n + sc_region) % sc_region + top;
913 1.5 cgd tmp2 = curscr->lines[target];
914 1.5 cgd curscr->lines[target] = tmp1;
915 1.5 cgd /* Mark block as clean and blank out scrolled lines. */
916 1.5 cgd clp = curscr->lines[target];
917 1.5 cgd #ifdef DEBUG
918 1.5 cgd __CTRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ",
919 1.11 mrg n, startw, curw, i, target);
920 1.5 cgd #endif
921 1.7 cgd if ((target >= startw && target < curw) || target < top
922 1.5 cgd || target > bot) {
923 1.5 cgd #ifdef DEBUG
924 1.22 jdc __CTRACE("-- notdirty\n");
925 1.5 cgd #endif
926 1.23 jdc __virtscr->lines[target]->flags &= ~__ISDIRTY;
927 1.11 mrg } else
928 1.11 mrg if ((n > 0 && target >= top && target < top + n) ||
929 1.11 mrg (n < 0 && target <= bot && target > bot + n)) {
930 1.11 mrg if (clp->hash != blank_hash || memcmp(clp->line,
931 1.46 christos clp->line + 1, (__virtscr->maxx - 1) *
932 1.46 christos __LDATASIZE) || memcmp(clp->line, buf,
933 1.46 christos __LDATASIZE)) {
934 1.46 christos for (i = __virtscr->maxx; i > BLANKSIZE;
935 1.46 christos i -= BLANKSIZE) {
936 1.46 christos (void)memcpy(clp->line + i -
937 1.46 christos BLANKSIZE, buf, sizeof(buf));
938 1.46 christos }
939 1.46 christos (void)memcpy(clp->line , buf, i *
940 1.46 christos sizeof(buf[0]));
941 1.11 mrg #ifdef DEBUG
942 1.22 jdc __CTRACE("-- blanked out: dirty\n");
943 1.11 mrg #endif
944 1.11 mrg clp->hash = blank_hash;
945 1.35 mycroft __touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1);
946 1.11 mrg } else {
947 1.5 cgd #ifdef DEBUG
948 1.22 jdc __CTRACE(" -- blank line already: dirty\n");
949 1.5 cgd #endif
950 1.35 mycroft __touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1);
951 1.11 mrg }
952 1.5 cgd } else {
953 1.5 cgd #ifdef DEBUG
954 1.22 jdc __CTRACE(" -- dirty\n");
955 1.5 cgd #endif
956 1.35 mycroft __touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1);
957 1.5 cgd }
958 1.5 cgd if (target == cur_period) {
959 1.5 cgd i = target + 1;
960 1.5 cgd tmp1 = curscr->lines[i];
961 1.5 cgd cur_period = i;
962 1.5 cgd } else {
963 1.5 cgd tmp1 = tmp2;
964 1.5 cgd i = target;
965 1.5 cgd }
966 1.5 cgd }
967 1.5 cgd #ifdef DEBUG
968 1.11 mrg __CTRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
969 1.11 mrg for (i = 0; i < curscr->maxy; i++) {
970 1.11 mrg __CTRACE("C: %d:", i);
971 1.11 mrg for (j = 0; j < curscr->maxx; j++)
972 1.11 mrg __CTRACE("%c", curscr->lines[i]->line[j].ch);
973 1.11 mrg __CTRACE("\n");
974 1.11 mrg __CTRACE("W: %d:", i);
975 1.23 jdc for (j = 0; j < __virtscr->maxx; j++)
976 1.23 jdc __CTRACE("%c", __virtscr->lines[i]->line[j].ch);
977 1.11 mrg __CTRACE("\n");
978 1.11 mrg }
979 1.5 cgd #endif
980 1.23 jdc if (n != 0)
981 1.23 jdc scrolln(starts, startw, curs, bot, top);
982 1.5 cgd }
983 1.5 cgd
984 1.5 cgd /*
985 1.7 cgd * scrolln --
986 1.7 cgd * Scroll n lines, where n is starts - startw.
987 1.5 cgd */
988 1.11 mrg static void /* ARGSUSED */
989 1.23 jdc scrolln(starts, startw, curs, bot, top)
990 1.11 mrg int starts, startw, curs, bot, top;
991 1.5 cgd {
992 1.11 mrg int i, oy, ox, n;
993 1.5 cgd
994 1.5 cgd oy = curscr->cury;
995 1.5 cgd ox = curscr->curx;
996 1.5 cgd n = starts - startw;
997 1.5 cgd
998 1.7 cgd /*
999 1.7 cgd * XXX
1000 1.7 cgd * The initial tests that set __noqch don't let us reach here unless
1001 1.41 jdc * we have either cs + ho + SF/sf/SR/sr, or AL + DL. SF/sf and SR/sr
1002 1.7 cgd * scrolling can only shift the entire scrolling region, not just a
1003 1.7 cgd * part of it, which means that the quickch() routine is going to be
1004 1.41 jdc * sadly disappointed in us if we don't have cs as well.
1005 1.7 cgd *
1006 1.41 jdc * If cs, ho and SF/sf are set, can use the scrolling region. Because
1007 1.41 jdc * the cursor position after cs is undefined, we need ho which gives us
1008 1.7 cgd * the ability to move to somewhere without knowledge of the current
1009 1.7 cgd * location of the cursor. Still call __mvcur() anyway, to update its
1010 1.7 cgd * idea of where the cursor is.
1011 1.7 cgd *
1012 1.7 cgd * When the scrolling region has been set, the cursor has to be at the
1013 1.7 cgd * last line of the region to make the scroll happen.
1014 1.7 cgd *
1015 1.7 cgd * Doing SF/SR or AL/DL appears faster on the screen than either sf/sr
1016 1.41 jdc * or AL/DL, and, some terminals have AL/DL, sf/sr, and cs, but not
1017 1.7 cgd * SF/SR. So, if we're scrolling almost all of the screen, try and use
1018 1.7 cgd * AL/DL, otherwise use the scrolling region. The "almost all" is a
1019 1.7 cgd * shameless hack for vi.
1020 1.7 cgd */
1021 1.5 cgd if (n > 0) {
1022 1.41 jdc if (__tc_cs != NULL && __tc_ho != NULL && (__tc_SF != NULL ||
1023 1.41 jdc ((__tc_AL == NULL || __tc_DL == NULL ||
1024 1.41 jdc top > 3 || bot + 3 < __virtscr->maxy) &&
1025 1.41 jdc __tc_sf != NULL))) {
1026 1.41 jdc tputs(__tscroll(__tc_cs, top, bot + 1), 0, __cputchar);
1027 1.7 cgd __mvcur(oy, ox, 0, 0, 1);
1028 1.41 jdc tputs(__tc_ho, 0, __cputchar);
1029 1.7 cgd __mvcur(0, 0, bot, 0, 1);
1030 1.41 jdc if (__tc_SF != NULL)
1031 1.41 jdc tputs(__tscroll(__tc_SF, n, 0), 0, __cputchar);
1032 1.7 cgd else
1033 1.7 cgd for (i = 0; i < n; i++)
1034 1.41 jdc tputs(__tc_sf, 0, __cputchar);
1035 1.41 jdc tputs(__tscroll(__tc_cs, 0, (int) __virtscr->maxy), 0,
1036 1.41 jdc __cputchar);
1037 1.7 cgd __mvcur(bot, 0, 0, 0, 1);
1038 1.41 jdc tputs(__tc_ho, 0, __cputchar);
1039 1.7 cgd __mvcur(0, 0, oy, ox, 1);
1040 1.7 cgd return;
1041 1.7 cgd }
1042 1.7 cgd
1043 1.7 cgd /* Scroll up the block. */
1044 1.41 jdc if (__tc_SF != NULL && top == 0) {
1045 1.7 cgd __mvcur(oy, ox, bot, 0, 1);
1046 1.41 jdc tputs(__tscroll(__tc_SF, n, 0), 0, __cputchar);
1047 1.7 cgd } else
1048 1.41 jdc if (__tc_DL != NULL) {
1049 1.11 mrg __mvcur(oy, ox, top, 0, 1);
1050 1.41 jdc tputs(__tscroll(__tc_DL, n, 0), 0, __cputchar);
1051 1.11 mrg } else
1052 1.41 jdc if (__tc_dl != NULL) {
1053 1.11 mrg __mvcur(oy, ox, top, 0, 1);
1054 1.11 mrg for (i = 0; i < n; i++)
1055 1.41 jdc tputs(__tc_dl, 0, __cputchar);
1056 1.11 mrg } else
1057 1.41 jdc if (__tc_sf != NULL && top == 0) {
1058 1.11 mrg __mvcur(oy, ox, bot, 0, 1);
1059 1.11 mrg for (i = 0; i < n; i++)
1060 1.41 jdc tputs(__tc_sf, 0,
1061 1.41 jdc __cputchar);
1062 1.11 mrg } else
1063 1.11 mrg abort();
1064 1.5 cgd
1065 1.7 cgd /* Push down the bottom region. */
1066 1.5 cgd __mvcur(top, 0, bot - n + 1, 0, 1);
1067 1.41 jdc if (__tc_AL != NULL)
1068 1.41 jdc tputs(__tscroll(__tc_AL, n, 0), 0, __cputchar);
1069 1.5 cgd else
1070 1.41 jdc if (__tc_al != NULL)
1071 1.11 mrg for (i = 0; i < n; i++)
1072 1.41 jdc tputs(__tc_al, 0, __cputchar);
1073 1.11 mrg else
1074 1.11 mrg abort();
1075 1.5 cgd __mvcur(bot - n + 1, 0, oy, ox, 1);
1076 1.5 cgd } else {
1077 1.7 cgd /*
1078 1.7 cgd * !!!
1079 1.7 cgd * n < 0
1080 1.7 cgd *
1081 1.41 jdc * If cs, ho and SR/sr are set, can use the scrolling region.
1082 1.7 cgd * See the above comments for details.
1083 1.7 cgd */
1084 1.41 jdc if (__tc_cs != NULL && __tc_ho != NULL && (__tc_SR != NULL ||
1085 1.41 jdc ((__tc_AL == NULL || __tc_DL == NULL || top > 3 ||
1086 1.41 jdc bot + 3 < __virtscr->maxy) && __tc_sr != NULL))) {
1087 1.41 jdc tputs(__tscroll(__tc_cs, top, bot + 1), 0, __cputchar);
1088 1.7 cgd __mvcur(oy, ox, 0, 0, 1);
1089 1.41 jdc tputs(__tc_ho, 0, __cputchar);
1090 1.7 cgd __mvcur(0, 0, top, 0, 1);
1091 1.7 cgd
1092 1.41 jdc if (__tc_SR != NULL)
1093 1.41 jdc tputs(__tscroll(__tc_SR, -n, 0), 0, __cputchar);
1094 1.7 cgd else
1095 1.7 cgd for (i = n; i < 0; i++)
1096 1.41 jdc tputs(__tc_sr, 0, __cputchar);
1097 1.41 jdc tputs(__tscroll(__tc_cs, 0, (int) __virtscr->maxy), 0,
1098 1.41 jdc __cputchar);
1099 1.7 cgd __mvcur(top, 0, 0, 0, 1);
1100 1.41 jdc tputs(__tc_ho, 0, __cputchar);
1101 1.7 cgd __mvcur(0, 0, oy, ox, 1);
1102 1.7 cgd return;
1103 1.7 cgd }
1104 1.7 cgd
1105 1.7 cgd /* Preserve the bottom lines. */
1106 1.7 cgd __mvcur(oy, ox, bot + n + 1, 0, 1);
1107 1.41 jdc if (__tc_SR != NULL && bot == __virtscr->maxy)
1108 1.41 jdc tputs(__tscroll(__tc_SR, -n, 0), 0, __cputchar);
1109 1.5 cgd else
1110 1.41 jdc if (__tc_DL != NULL)
1111 1.41 jdc tputs(__tscroll(__tc_DL, -n, 0), 0, __cputchar);
1112 1.11 mrg else
1113 1.41 jdc if (__tc_dl != NULL)
1114 1.11 mrg for (i = n; i < 0; i++)
1115 1.41 jdc tputs(__tc_dl, 0, __cputchar);
1116 1.11 mrg else
1117 1.41 jdc if (__tc_sr != NULL &&
1118 1.41 jdc bot == __virtscr->maxy)
1119 1.11 mrg for (i = n; i < 0; i++)
1120 1.41 jdc tputs(__tc_sr, 0,
1121 1.41 jdc __cputchar);
1122 1.11 mrg else
1123 1.11 mrg abort();
1124 1.7 cgd
1125 1.7 cgd /* Scroll the block down. */
1126 1.5 cgd __mvcur(bot + n + 1, 0, top, 0, 1);
1127 1.41 jdc if (__tc_AL != NULL)
1128 1.41 jdc tputs(__tscroll(__tc_AL, -n, 0), 0, __cputchar);
1129 1.5 cgd else
1130 1.41 jdc if (__tc_al != NULL)
1131 1.11 mrg for (i = n; i < 0; i++)
1132 1.41 jdc tputs(__tc_al, 0, __cputchar);
1133 1.11 mrg else
1134 1.11 mrg abort();
1135 1.5 cgd __mvcur(top, 0, oy, ox, 1);
1136 1.19 jdc }
1137 1.19 jdc }
1138 1.19 jdc
1139 1.19 jdc /*
1140 1.23 jdc * __unsetattr --
1141 1.19 jdc * Unset attributes on curscr. Leave standout, attribute and colour
1142 1.41 jdc * modes if necessary (!ms). Always leave altcharset (xterm at least
1143 1.19 jdc * ignores a cursor move if we don't).
1144 1.19 jdc */
1145 1.23 jdc void /* ARGSUSED */
1146 1.23 jdc __unsetattr(int checkms)
1147 1.19 jdc {
1148 1.19 jdc int isms;
1149 1.19 jdc
1150 1.19 jdc if (checkms)
1151 1.41 jdc if (!__tc_ms) {
1152 1.19 jdc isms = 1;
1153 1.19 jdc } else {
1154 1.19 jdc isms = 0;
1155 1.19 jdc }
1156 1.19 jdc else
1157 1.19 jdc isms = 1;
1158 1.20 jdc #ifdef DEBUG
1159 1.41 jdc __CTRACE("__unsetattr: checkms = %d, ms = %s, wattr = %08x\n",
1160 1.41 jdc checkms, __tc_ms ? "TRUE" : "FALSE", curscr->wattr);
1161 1.20 jdc #endif
1162 1.19 jdc
1163 1.20 jdc /*
1164 1.41 jdc * Don't leave the screen in standout mode (check against ms). Check
1165 1.27 mycroft * to see if we also turn off underscore, attributes and colour.
1166 1.20 jdc */
1167 1.19 jdc if (curscr->wattr & __STANDOUT && isms) {
1168 1.41 jdc tputs(__tc_se, 0, __cputchar);
1169 1.41 jdc curscr->wattr &= __mask_se;
1170 1.19 jdc }
1171 1.20 jdc /*
1172 1.41 jdc * Don't leave the screen in underscore mode (check against ms).
1173 1.26 jdc * Check to see if we also turn off attributes. Assume that we
1174 1.26 jdc * also turn off colour.
1175 1.20 jdc */
1176 1.19 jdc if (curscr->wattr & __UNDERSCORE && isms) {
1177 1.41 jdc tputs(__tc_ue, 0, __cputchar);
1178 1.41 jdc curscr->wattr &= __mask_ue;
1179 1.19 jdc }
1180 1.20 jdc /*
1181 1.41 jdc * Don't leave the screen with attributes set (check against ms).
1182 1.26 jdc * Assume that also turn off colour.
1183 1.20 jdc */
1184 1.20 jdc if (curscr->wattr & __TERMATTR && isms) {
1185 1.41 jdc tputs(__tc_me, 0, __cputchar);
1186 1.41 jdc curscr->wattr &= __mask_me;
1187 1.19 jdc }
1188 1.41 jdc /* Don't leave the screen with altcharset set (don't check ms). */
1189 1.19 jdc if (curscr->wattr & __ALTCHARSET) {
1190 1.41 jdc tputs(__tc_ae, 0, __cputchar);
1191 1.19 jdc curscr->wattr &= ~__ALTCHARSET;
1192 1.19 jdc }
1193 1.41 jdc /* Don't leave the screen with colour set (check against ms). */
1194 1.47 jdc if (__using_color && isms)
1195 1.47 jdc __unset_color(curscr);
1196 1.1 cgd }
1197