]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/wwupdate.c
1 /* $NetBSD: wwupdate.c,v 1.4 1997/11/21 08:37:59 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)wwupdate.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: wwupdate.c,v 1.4 1997/11/21 08:37:59 lukem Exp $");
59 struct ww_update
*upd
;
60 char check_clreos
= 0;
61 int scan_top
, scan_bot
;
65 char *t1
= wwtouched
+ top
, *t2
= wwtouched
+ bot
;
73 scan_top
= top
= t1
- wwtouched
- 1;
74 scan_bot
= bot
= t2
- wwtouched
+ 1;
75 if (scan_bot
- scan_top
> 1 &&
76 (tt
.tt_clreos
!= 0 || tt
.tt_clear
!= 0)) {
77 int st
= tt
.tt_clreos
!= 0 ? scan_top
: 0;
80 * t1 is one past the first touched row,
81 * t2 is on the last touched row.
83 for (t1
--, n
= 1; t1
< t2
;)
87 * If we can't clreos then we try for clearing
90 if ((check_clreos
= n
* 10 > (wwnrow
- st
) * 9)) {
96 if (tt
.tt_clreol
== 0 && !check_clreos
)
98 for (i
= scan_top
, touched
= &wwtouched
[i
], upd
= &wwupd
[i
];
100 i
++, touched
++, upd
++) {
104 union ww_char
*ns
, *os
;
108 if (!check_clreos
&& !*touched
)
116 * The cost of clearing is:
118 * The cost of straight update is, more or less:
120 * We clear if nblank - nsame > X
121 * X is the clreol overhead.
122 * So we make gain = nblank - nsame.
124 if ((--ns
)->c_w
== (--os
)->c_w
)
130 if (gain
> best_gain
) {
135 upd
->best_gain
= best_gain
;
136 upd
->best_col
= best_col
;
148 * gain is the advantage of clearing all the lines.
149 * best_gain is the advantage of clearing to eos
150 * at best_row and u->best_col.
151 * simple_gain is the advantage of using only clreol.
152 * We use g > best_gain because u->best_col can be
153 * undefined when u->best_gain is 0 so we can't use it.
155 for (j
= scan_bot
- 1, u
= wwupd
+ j
; j
>= top
; j
--, u
--) {
156 int g
= gain
+ u
->best_gain
;
163 if (tt
.tt_clreol
!= 0 && u
->best_gain
> 4)
164 simple_gain
+= u
->best_gain
- 4;
166 if (tt
.tt_clreos
== 0) {
167 if (gain
> simple_gain
&& gain
> 4) {
175 if (best_gain
> simple_gain
&& best_gain
> 4) {
177 xxclreos(i
, j
= wwupd
[i
].best_col
);
183 wwnupdclreosline
+= wwnrow
- i
;
185 while (i
< scan_bot
) {
186 union ww_char
*os
= &wwos
[i
][j
];
188 for (j
= wwncol
- j
; --j
>= 0;)
190 wwtouched
[i
++] |= WWU_TOUCHED
;
198 for (i
= top
, touched
= &wwtouched
[i
], upd
= &wwupd
[i
]; i
< bot
;
199 i
++, touched
++, upd
++) {
200 union ww_char
*os
, *ns
;
208 if (tt
.tt_clreol
!= 0 && upd
->best_gain
> 4) {
210 xxclreol(i
, j
= upd
->best_col
);
211 for (os
= &wwos
[i
][j
], j
= wwncol
- j
; --j
>= 0;)
217 for (j
= 0; j
< wwncol
;) {
222 char buf
[512]; /* > wwncol */
225 for (; j
++ < wwncol
&& ns
++->c_w
== os
++->c_w
;)
236 while (j
< wwncol
&& ns
->c_m
== m
) {
238 if (ns
->c_w
== os
->c_w
) {
252 if (!wwwrap
|| i
!= wwnrow
- 1 || c
+ n
!= wwncol
)
253 xxwrite(i
, c
, buf
, n
, m
);
254 else if (tt
.tt_inschar
|| tt
.tt_insspace
) {
260 xxwrite(i
, c
, buf
, n
, m
);
263 xxinschar(i
, c
, ns
[-2].c_c
,
267 xxwrite(i
, c
, &ns
[-2].c_c
, 1,
272 xxwrite(i
, c
, buf
, n
, m
);
274 *touched
= WWU_TOUCHED
;