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