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