]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/window/xxflush.c
This commit was generated by cvs2svn to compensate for changes in r73188,
[FreeBSD/FreeBSD.git] / usr.bin / window / xxflush.c
1 /*
2  * Copyright (c) 1989, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #ifndef lint
38 static char sccsid[] = "@(#)xxflush.c   8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
40 #endif /* not lint */
41
42 #include "ww.h"
43 #include "xx.h"
44 #include "tt.h"
45
46 xxflush(intr)
47         register intr;
48 {
49         register struct xx *xp, *xq;
50
51         for (xp = xx_head; xp != 0 && !(intr && wwinterrupt()); xp = xq) {
52                 switch (xp->cmd) {
53                 case xc_move:
54                         if (xp->link == 0)
55                                 (*tt.tt_move)(xp->arg0, xp->arg1);
56                         break;
57                 case xc_scroll:
58                         xxflush_scroll(xp);
59                         break;
60                 case xc_inschar:
61                         (*tt.tt_move)(xp->arg0, xp->arg1);
62                         tt.tt_nmodes = xp->arg3;
63                         (*tt.tt_inschar)(xp->arg2);
64                         break;
65                 case xc_insspace:
66                         (*tt.tt_move)(xp->arg0, xp->arg1);
67                         (*tt.tt_insspace)(xp->arg2);
68                         break;
69                 case xc_delchar:
70                         (*tt.tt_move)(xp->arg0, xp->arg1);
71                         (*tt.tt_delchar)(xp->arg2);
72                         break;
73                 case xc_clear:
74                         (*tt.tt_clear)();
75                         break;
76                 case xc_clreos:
77                         (*tt.tt_move)(xp->arg0, xp->arg1);
78                         (*tt.tt_clreos)();
79                         break;
80                 case xc_clreol:
81                         (*tt.tt_move)(xp->arg0, xp->arg1);
82                         (*tt.tt_clreol)();
83                         break;
84                 case xc_write:
85                         (*tt.tt_move)(xp->arg0, xp->arg1);
86                         tt.tt_nmodes = xp->arg3;
87                         (*tt.tt_write)(xp->buf, xp->arg2);
88                         break;
89                 }
90                 xq = xp->link;
91                 xxfree(xp);
92         }
93         if ((xx_head = xp) == 0) {
94                 xx_tail = 0;
95                 xxbufp = xxbuf;
96         }
97         ttflush();
98 }
99
100 xxflush_scroll(xp)
101         register struct xx *xp;
102 {
103         register struct xx *xq;
104
105  top:
106         if (xp->arg0 == 0)
107                 return;
108         /*
109          * We handle retain (da and db) by putting the burden on scrolling up,
110          * which is the less common operation.  It must ensure that
111          * text is not pushed below the screen, so scrolling down doesn't
112          * have to worry about it.
113          *
114          * Try scrolling region (or scrolling the whole screen) first.
115          * Can we assume "sr" doesn't push text below the screen
116          * so we don't have to worry about retain below?
117          * What about scrolling down with a newline?  It probably does
118          * push text above (with da).  Scrolling up would then have
119          * to take care of that.
120          * It's easy to be fool proof, but that slows things down.
121          * The current solution is to disallow tt_scroll_up if da or db is true
122          * but cs (scrolling region) is not.  Again, we sacrifice scrolling
123          * up in favor of scrolling down.  The idea is having scrolling regions
124          * probably means we can scroll (even the whole screen) with impunity.
125          * This lets us work efficiently on simple terminals (use newline
126          * on the bottom to scroll), on any terminal without retain, and
127          * on vt100 style scrolling regions (I think).
128          */
129         if (xp->arg0 > 0) {
130                 if ((xq = xp->link) != 0 && xq->cmd == xc_scroll &&
131                     xp->arg2 == xq->arg2 && xq->arg0 < 0) {
132                         if (xp->arg1 < xq->arg1) {
133                                 if (xp->arg2 - xp->arg0 <= xq->arg1) {
134                                         xq->arg0 = xp->arg0;
135                                         xq->arg1 = xp->arg1;
136                                         xq->arg2 = xp->arg2;
137                                         return;
138                                 }
139                                 xp->arg2 = xq->arg1 + xp->arg0;
140                                 xq->arg0 += xp->arg0;
141                                 xq->arg1 = xp->arg2;
142                                 if (xq->arg0 > 0)
143                                         xq->arg1 -= xq->arg0;
144                                 goto top;
145                         } else {
146                                 if (xp->arg1 - xq->arg0 >= xp->arg2)
147                                         return;
148                                 xq->arg2 = xp->arg1 - xq->arg0;
149                                 xp->arg0 += xq->arg0;
150                                 xp->arg1 = xq->arg2;
151                                 if (xp->arg0 < 0)
152                                         xp->arg1 += xp->arg0;
153                                 goto top;
154                         }
155                 }
156                 if (xp->arg0 > xp->arg2 - xp->arg1)
157                         xp->arg0 = xp->arg2 - xp->arg1;
158                 if (tt.tt_scroll_down) {
159                         if (tt.tt_scroll_top != xp->arg1 ||
160                             tt.tt_scroll_bot != xp->arg2 - 1) {
161                                 if (tt.tt_setscroll == 0)
162                                         goto down;
163                                 (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1);
164                         }
165                         tt.tt_scroll_down(xp->arg0);
166                 } else {
167                 down:
168                         (*tt.tt_move)(xp->arg1, 0);
169                         (*tt.tt_delline)(xp->arg0);
170                         if (xp->arg2 < tt.tt_nrow) {
171                                 (*tt.tt_move)(xp->arg2 - xp->arg0, 0);
172                                 (*tt.tt_insline)(xp->arg0);
173                         }
174                 }
175         } else {
176                 xp->arg0 = - xp->arg0;
177                 if (xp->arg0 > xp->arg2 - xp->arg1)
178                         xp->arg0 = xp->arg2 - xp->arg1;
179                 if (tt.tt_scroll_up) {
180                         if (tt.tt_scroll_top != xp->arg1 ||
181                             tt.tt_scroll_bot != xp->arg2 - 1) {
182                                 if (tt.tt_setscroll == 0)
183                                         goto up;
184                                 (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1);
185                         }
186                         tt.tt_scroll_up(xp->arg0);
187                 } else  {
188                 up:
189                         if (tt.tt_retain || xp->arg2 != tt.tt_nrow) {
190                                 (*tt.tt_move)(xp->arg2 - xp->arg0, 0);
191                                 (*tt.tt_delline)(xp->arg0);
192                         }
193                         (*tt.tt_move)(xp->arg1, 0);
194                         (*tt.tt_insline)(xp->arg0);
195                 }
196         }
197 }