]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/wwscroll.c
1 /* $NetBSD: wwscroll.c,v 1.4 1997/11/21 08:37:48 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
[] = "@(#)wwscroll.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: wwscroll.c,v 1.4 1997/11/21 08:37:48 lukem Exp $");
66 else if (top
+ w
->ww_b
.nr
< w
->ww_w
.b
)
67 top
= w
->ww_w
.b
- w
->ww_b
.nr
;
68 n
= abs(top
- w
->ww_b
.t
);
71 (void) wwscroll1(w
, w
->ww_i
.t
, w
->ww_i
.b
, dir
, 0);
77 w
->ww_buf
-= top
- w
->ww_b
.t
;
79 w
->ww_b
.b
= top
+ w
->ww_b
.nr
;
85 * Scroll one line, between 'row1' and 'row2', in direction 'dir'.
86 * Don't adjust ww_scroll.
87 * And don't redraw 'leaveit' lines.
90 wwscroll1(w
, row1
, row2
, dir
, leaveit
)
102 * See how many lines on the screen are affected.
103 * And calculate row1x, row2x, and left at the same time.
105 for (i
= row1
; i
< row2
&& w
->ww_nvis
[i
] == 0; i
++)
107 if (i
>= row2
) /* can't do any fancy stuff */
110 for (i
= row2
- 1; i
>= row1
&& w
->ww_nvis
[i
] == 0; i
--)
113 goto out
; /* just one line is easy */
117 * See how much of this window is visible.
119 nvismax
= wwncol
* (row2x
- row1x
);
121 for (i
= row1x
; i
< row2x
; i
++)
122 nvis
+= w
->ww_nvis
[i
];
125 * If it's a good idea to scroll and the terminal can, then do it.
127 if (nvis
< nvismax
/ 2)
128 goto no_scroll
; /* not worth it */
129 if ((dir
> 0 ? tt
.tt_scroll_down
== 0 : tt
.tt_scroll_up
== 0) ||
130 ((tt
.tt_scroll_top
!= row1x
|| tt
.tt_scroll_bot
!= row2x
- 1) &&
131 tt
.tt_setscroll
== 0))
132 if (tt
.tt_delline
== 0 || tt
.tt_insline
== 0)
134 xxscroll(dir
, row1x
, row2x
);
137 * Fix up the old screen.
141 union ww_char
**cpp
, **cqq
;
147 for (i
= row2x
- row1x
; --i
> 0;)
154 for (i
= row2x
- row1x
; --i
> 0;)
158 for (i
= wwncol
; --i
>= 0;)
164 * Fix the new screen.
166 if (nvis
== nvismax
) {
168 * Can shift whole lines.
173 union ww_char
**cpp
, **cqq
;
178 for (i
= row2x
- row1x
; --i
> 0;)
185 p
= &wwtouched
[row1x
];
187 for (i
= row2x
- row1x
; --i
> 0;)
193 p
= &wwtouched
[row1x
];
194 for (i
= row2x
- row1x
; --i
>= 0;)
197 wwredrawwin1(w
, row1
, row1x
, dir
);
198 wwredrawwin1(w
, row2x
- 1, row2
- leaveit
, dir
);
202 union ww_char
**cpp
, **cqq
;
207 for (i
= row2x
- row1x
; --i
> 0;)
214 p
= &wwtouched
[row2x
];
216 for (i
= row2x
- row1x
; --i
> 0;)
222 p
= &wwtouched
[row1x
];
223 for (i
= row2x
- row1x
; --i
>= 0;)
226 wwredrawwin1(w
, row1
+ leaveit
, row1x
+ 1, dir
);
227 wwredrawwin1(w
, row2x
, row2
, dir
);
233 p
= &wwtouched
[row1x
];
234 for (i
= row2x
- row1x
; --i
>= 0;)
239 wwredrawwin1(w
, row1
, row2
- leaveit
, dir
);
241 wwredrawwin1(w
, row1
+ leaveit
, row2
, dir
);