]> git.saurik.com Git - apple/shell_cmds.git/blob - window/xxflush.c
shell_cmds-17.1.tar.gz
[apple/shell_cmds.git] / window / xxflush.c
1 /* $NetBSD: xxflush.c,v 1.4 1997/11/21 08:38:05 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
25 *
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
36 * SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)xxflush.c 8.1 (Berkeley) 6/6/93";
43 #else
44 __RCSID("$NetBSD: xxflush.c,v 1.4 1997/11/21 08:38:05 lukem Exp $");
45 #endif
46 #endif /* not lint */
47
48 #include "ww.h"
49 #include "xx.h"
50 #include "tt.h"
51
52 void
53 xxflush(intr)
54 int intr;
55 {
56 struct xx *xp, *xq;
57
58 for (xp = xx_head; xp != 0 && !(intr && wwinterrupt()); xp = xq) {
59 switch (xp->cmd) {
60 case xc_move:
61 if (xp->link == 0)
62 (*tt.tt_move)(xp->arg0, xp->arg1);
63 break;
64 case xc_scroll:
65 xxflush_scroll(xp);
66 break;
67 case xc_inschar:
68 (*tt.tt_move)(xp->arg0, xp->arg1);
69 tt.tt_nmodes = xp->arg3;
70 (*tt.tt_inschar)(xp->arg2);
71 break;
72 case xc_insspace:
73 (*tt.tt_move)(xp->arg0, xp->arg1);
74 (*tt.tt_insspace)(xp->arg2);
75 break;
76 case xc_delchar:
77 (*tt.tt_move)(xp->arg0, xp->arg1);
78 (*tt.tt_delchar)(xp->arg2);
79 break;
80 case xc_clear:
81 (*tt.tt_clear)();
82 break;
83 case xc_clreos:
84 (*tt.tt_move)(xp->arg0, xp->arg1);
85 (*tt.tt_clreos)();
86 break;
87 case xc_clreol:
88 (*tt.tt_move)(xp->arg0, xp->arg1);
89 (*tt.tt_clreol)();
90 break;
91 case xc_write:
92 (*tt.tt_move)(xp->arg0, xp->arg1);
93 tt.tt_nmodes = xp->arg3;
94 (*tt.tt_write)(xp->buf, xp->arg2);
95 break;
96 }
97 xq = xp->link;
98 xxfree(xp);
99 }
100 if ((xx_head = xp) == 0) {
101 xx_tail = 0;
102 xxbufp = xxbuf;
103 }
104 ttflush();
105 }
106
107 void
108 xxflush_scroll(xp)
109 struct xx *xp;
110 {
111 struct xx *xq;
112
113 top:
114 if (xp->arg0 == 0)
115 return;
116 /*
117 * We handle retain (da and db) by putting the burden on scrolling up,
118 * which is the less common operation. It must ensure that
119 * text is not pushed below the screen, so scrolling down doesn't
120 * have to worry about it.
121 *
122 * Try scrolling region (or scrolling the whole screen) first.
123 * Can we assume "sr" doesn't push text below the screen
124 * so we don't have to worry about retain below?
125 * What about scrolling down with a newline? It probably does
126 * push text above (with da). Scrolling up would then have
127 * to take care of that.
128 * It's easy to be fool proof, but that slows things down.
129 * The current solution is to disallow tt_scroll_up if da or db is true
130 * but cs (scrolling region) is not. Again, we sacrifice scrolling
131 * up in favor of scrolling down. The idea is having scrolling regions
132 * probably means we can scroll (even the whole screen) with impunity.
133 * This lets us work efficiently on simple terminals (use newline
134 * on the bottom to scroll), on any terminal without retain, and
135 * on vt100 style scrolling regions (I think).
136 */
137 if (xp->arg0 > 0) {
138 if ((xq = xp->link) != 0 && xq->cmd == xc_scroll &&
139 xp->arg2 == xq->arg2 && xq->arg0 < 0) {
140 if (xp->arg1 < xq->arg1) {
141 if (xp->arg2 - xp->arg0 <= xq->arg1) {
142 xq->arg0 = xp->arg0;
143 xq->arg1 = xp->arg1;
144 xq->arg2 = xp->arg2;
145 return;
146 }
147 xp->arg2 = xq->arg1 + xp->arg0;
148 xq->arg0 += xp->arg0;
149 xq->arg1 = xp->arg2;
150 if (xq->arg0 > 0)
151 xq->arg1 -= xq->arg0;
152 goto top;
153 } else {
154 if (xp->arg1 - xq->arg0 >= xp->arg2)
155 return;
156 xq->arg2 = xp->arg1 - xq->arg0;
157 xp->arg0 += xq->arg0;
158 xp->arg1 = xq->arg2;
159 if (xp->arg0 < 0)
160 xp->arg1 += xp->arg0;
161 goto top;
162 }
163 }
164 if (xp->arg0 > xp->arg2 - xp->arg1)
165 xp->arg0 = xp->arg2 - xp->arg1;
166 if (tt.tt_scroll_down) {
167 if (tt.tt_scroll_top != xp->arg1 ||
168 tt.tt_scroll_bot != xp->arg2 - 1) {
169 if (tt.tt_setscroll == 0)
170 goto down;
171 (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1);
172 }
173 tt.tt_scroll_down(xp->arg0);
174 } else {
175 down:
176 (*tt.tt_move)(xp->arg1, 0);
177 (*tt.tt_delline)(xp->arg0);
178 if (xp->arg2 < tt.tt_nrow) {
179 (*tt.tt_move)(xp->arg2 - xp->arg0, 0);
180 (*tt.tt_insline)(xp->arg0);
181 }
182 }
183 } else {
184 xp->arg0 = - xp->arg0;
185 if (xp->arg0 > xp->arg2 - xp->arg1)
186 xp->arg0 = xp->arg2 - xp->arg1;
187 if (tt.tt_scroll_up) {
188 if (tt.tt_scroll_top != xp->arg1 ||
189 tt.tt_scroll_bot != xp->arg2 - 1) {
190 if (tt.tt_setscroll == 0)
191 goto up;
192 (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1);
193 }
194 tt.tt_scroll_up(xp->arg0);
195 } else {
196 up:
197 if (tt.tt_retain || xp->arg2 != tt.tt_nrow) {
198 (*tt.tt_move)(xp->arg2 - xp->arg0, 0);
199 (*tt.tt_delline)(xp->arg0);
200 }
201 (*tt.tt_move)(xp->arg1, 0);
202 (*tt.tt_insline)(xp->arg0);
203 }
204 }
205 }