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

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

1.4     ! millert     1: /*     $OpenBSD: xx.c,v 1.3 1997/02/25 00:05:15 downsj Exp $   */
1.1       deraadt     2: /*     $NetBSD: xx.c,v 1.3 1995/09/28 10:36:03 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[] = "@(#)xx.c       8.1 (Berkeley) 6/6/93";
                     43: #else
1.4     ! millert    44: static char rcsid[] = "$OpenBSD: xx.c,v 1.3 1997/02/25 00:05:15 downsj Exp $";
1.1       deraadt    45: #endif
                     46: #endif /* not lint */
                     47:
1.3       downsj     48: #include <stdlib.h>
1.1       deraadt    49: #include "ww.h"
                     50: #include "xx.h"
                     51: #include "tt.h"
                     52:
                     53: xxinit()
                     54: {
                     55:        if (ttinit() < 0)
                     56:                return -1;
                     57:        xxbufsize = tt.tt_nrow * tt.tt_ncol * 2;
                     58:        /* ccinit may choose to change xxbufsize */
                     59:        if (tt.tt_ntoken > 0 && ccinit() < 0)
                     60:                return -1;
1.4     ! millert    61:        xxbuf = malloc(xxbufsize * sizeof *xxbuf);
1.1       deraadt    62:        if (xxbuf == 0) {
                     63:                wwerrno = WWE_NOMEM;
                     64:                return -1;
                     65:        }
                     66:        xxbufp = xxbuf;
                     67:        xxbufe = xxbuf + xxbufsize;
                     68:        return 0;
                     69: }
                     70:
                     71: xxstart()
                     72: {
                     73:        (*tt.tt_start)();
                     74:        if (tt.tt_ntoken > 0)
                     75:                ccstart();
                     76:        xxreset1();                     /* might be a restart */
                     77: }
                     78:
                     79: xxreset()
                     80: {
                     81:        if (tt.tt_ntoken > 0)
                     82:                ccreset();
                     83:        xxreset1();
                     84:        (*tt.tt_reset)();
                     85: }
                     86:
                     87: xxreset1()
                     88: {
                     89:        register struct xx *xp, *xq;
                     90:
                     91:        for (xp = xx_head; xp != 0; xp = xq) {
                     92:                xq = xp->link;
                     93:                xxfree(xp);
                     94:        }
                     95:        xx_tail = xx_head = 0;
                     96:        xxbufp = xxbuf;
                     97: }
                     98:
                     99: xxend()
                    100: {
                    101:        if (tt.tt_scroll_top != 0 || tt.tt_scroll_bot != tt.tt_nrow - 1)
                    102:                /* tt.tt_setscroll is known to be defined */
                    103:                (*tt.tt_setscroll)(0, tt.tt_nrow - 1);
                    104:        if (tt.tt_modes)
                    105:                (*tt.tt_setmodes)(0);
                    106:        if (tt.tt_scroll_down)
                    107:                (*tt.tt_scroll_down)(1);
                    108:        (*tt.tt_move)(tt.tt_nrow - 1, 0);
                    109:        if (tt.tt_ntoken > 0)
                    110:                ccend();
                    111:        (*tt.tt_end)();
                    112:        ttflush();
                    113: }
                    114:
                    115: struct xx *
                    116: xxalloc()
                    117: {
                    118:        register struct xx *xp;
                    119:
                    120:        if (xxbufp > xxbufe)
                    121:                abort();
                    122:        if ((xp = xx_freelist) == 0)
                    123:                /* XXX can't deal with failure */
1.4     ! millert   124:                xp = (struct xx *) malloc(sizeof *xp);
1.1       deraadt   125:        else
                    126:                xx_freelist = xp->link;
                    127:        if (xx_head == 0)
                    128:                xx_head = xp;
                    129:        else
                    130:                xx_tail->link = xp;
                    131:        xx_tail = xp;
                    132:        xp->link = 0;
                    133:        return xp;
                    134: }
                    135:
                    136: xxfree(xp)
                    137:        register struct xx *xp;
                    138: {
                    139:        xp->link = xx_freelist;
                    140:        xx_freelist = xp;
                    141: }
                    142:
                    143: xxmove(row, col)
                    144: {
                    145:        register struct xx *xp = xx_tail;
                    146:
                    147:        if (xp == 0 || xp->cmd != xc_move) {
                    148:                xp = xxalloc();
                    149:                xp->cmd = xc_move;
                    150:        }
                    151:        xp->arg0 = row;
                    152:        xp->arg1 = col;
                    153: }
                    154:
                    155: xxscroll(dir, top, bot)
                    156: {
                    157:        register struct xx *xp = xx_tail;
                    158:
                    159:        if (xp != 0 && xp->cmd == xc_scroll &&
                    160:            xp->arg1 == top && xp->arg2 == bot &&
                    161:            (xp->arg0 < 0 && dir < 0 || xp->arg0 > 0 && dir > 0)) {
                    162:                xp->arg0 += dir;
                    163:                return;
                    164:        }
                    165:        xp = xxalloc();
                    166:        xp->cmd = xc_scroll;
                    167:        xp->arg0 = dir;
                    168:        xp->arg1 = top;
                    169:        xp->arg2 = bot;
                    170: }
                    171:
                    172: xxinschar(row, col, c, m)
                    173: {
                    174:        register struct xx *xp;
                    175:
                    176:        xp = xxalloc();
                    177:        xp->cmd = xc_inschar;
                    178:        xp->arg0 = row;
                    179:        xp->arg1 = col;
                    180:        xp->arg2 = c;
                    181:        xp->arg3 = m;
                    182: }
                    183:
                    184: xxinsspace(row, col)
                    185: {
                    186:        register struct xx *xp = xx_tail;
                    187:
                    188:        if (xp != 0 && xp->cmd == xc_insspace && xp->arg0 == row &&
                    189:            col >= xp->arg1 && col <= xp->arg1 + xp->arg2) {
                    190:                xp->arg2++;
                    191:                return;
                    192:        }
                    193:        xp = xxalloc();
                    194:        xp->cmd = xc_insspace;
                    195:        xp->arg0 = row;
                    196:        xp->arg1 = col;
                    197:        xp->arg2 = 1;
                    198: }
                    199:
                    200: xxdelchar(row, col)
                    201: {
                    202:        register struct xx *xp = xx_tail;
                    203:
                    204:        if (xp != 0 && xp->cmd == xc_delchar &&
                    205:            xp->arg0 == row && xp->arg1 == col) {
                    206:                xp->arg2++;
                    207:                return;
                    208:        }
                    209:        xp = xxalloc();
                    210:        xp->cmd = xc_delchar;
                    211:        xp->arg0 = row;
                    212:        xp->arg1 = col;
                    213:        xp->arg2 = 1;
                    214: }
                    215:
                    216: xxclear()
                    217: {
                    218:        register struct xx *xp;
                    219:
                    220:        xxreset1();
                    221:        xp = xxalloc();
                    222:        xp->cmd = xc_clear;
                    223: }
                    224:
                    225: xxclreos(row, col)
                    226: {
                    227:        register struct xx *xp = xxalloc();
                    228:
                    229:        xp->cmd = xc_clreos;
                    230:        xp->arg0 = row;
                    231:        xp->arg1 = col;
                    232: }
                    233:
                    234: xxclreol(row, col)
                    235: {
                    236:        register struct xx *xp = xxalloc();
                    237:
                    238:        xp->cmd = xc_clreol;
                    239:        xp->arg0 = row;
                    240:        xp->arg1 = col;
                    241: }
                    242:
                    243: xxwrite(row, col, p, n, m)
                    244:        char *p;
                    245: {
                    246:        register struct xx *xp;
                    247:
                    248:        if (xxbufp + n + 1 > xxbufe)
                    249:                xxflush(0);
                    250:        xp = xxalloc();
                    251:        xp->cmd = xc_write;
                    252:        xp->arg0 = row;
                    253:        xp->arg1 = col;
                    254:        xp->arg2 = n;
                    255:        xp->arg3 = m;
                    256:        xp->buf = xxbufp;
                    257:        bcopy(p, xxbufp, n);
                    258:        xxbufp += n;
                    259:        *xxbufp++ = char_sep;
                    260: }