[BACK]Return to xxflush.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / window

Annotation of src/usr.bin/window/xxflush.c, Revision 1.4

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