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

Annotation of src/usr.bin/window/wwsize.c, Revision 1.2

1.2     ! deraadt     1: /*     $NetBSD: wwsize.c,v 1.4 1995/12/21 10:46:28 mycroft Exp $       */
1.1       deraadt     2:
                      3: /*
                      4:  * Copyright (c) 1983, 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[] = "@(#)wwsize.c   8.1 (Berkeley) 6/6/93";
                     42: #else
1.2     ! deraadt    43: static char rcsid[] = "$NetBSD: wwsize.c,v 1.4 1995/12/21 10:46:28 mycroft Exp $";
1.1       deraadt    44: #endif
                     45: #endif /* not lint */
                     46:
                     47: #include "ww.h"
                     48:
                     49: /*
                     50:  * Resize a window.  Should be unattached.
                     51:  */
                     52: wwsize(w, nrow, ncol)
                     53: register struct ww *w;
                     54: {
                     55:        register i, j;
                     56:        int nline;
                     57:        union ww_char **buf = 0;
                     58:        char **win = 0;
                     59:        short *nvis = 0;
                     60:        char **fmap = 0;
                     61:        char m;
                     62:
                     63:        /*
                     64:         * First allocate new buffers.
                     65:         */
                     66:        win = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
                     67:        if (win == 0)
                     68:                goto bad;
                     69:        if (w->ww_fmap != 0) {
                     70:                fmap = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
                     71:                if (fmap == 0)
                     72:                        goto bad;
                     73:        }
                     74:        if (nrow > w->ww_b.nr || ncol > w->ww_b.nc) {
                     75:                nline = MAX(w->ww_b.nr, nrow);
                     76:                buf = (union ww_char **) wwalloc(w->ww_b.t, w->ww_b.l,
                     77:                        nline, ncol, sizeof (union ww_char));
                     78:                if (buf == 0)
                     79:                        goto bad;
                     80:        }
                     81:        nvis = (short *)malloc((unsigned) nrow * sizeof (short));
                     82:        if (nvis == 0) {
                     83:                wwerrno = WWE_NOMEM;
                     84:                goto bad;
                     85:        }
                     86:        nvis -= w->ww_w.t;
                     87:        /*
                     88:         * Copy text buffer.
                     89:         */
                     90:        if (buf != 0) {
                     91:                int b, r;
                     92:
                     93:                b = w->ww_b.t + nline;
                     94:                r = w->ww_b.l + ncol;
                     95:                if (ncol < w->ww_b.nc)
                     96:                        for (i = w->ww_b.t; i < w->ww_b.b; i++)
                     97:                                for (j = w->ww_b.l; j < r; j++)
                     98:                                        buf[i][j] = w->ww_buf[i][j];
                     99:                else
                    100:                        for (i = w->ww_b.t; i < w->ww_b.b; i++) {
                    101:                                for (j = w->ww_b.l; j < w->ww_b.r; j++)
                    102:                                        buf[i][j] = w->ww_buf[i][j];
                    103:                                for (; j < r; j++)
                    104:                                        buf[i][j].c_w = ' ';
                    105:                        }
                    106:                for (; i < b; i++)
                    107:                        for (j = w->ww_b.l; j < r; j++)
                    108:                                buf[i][j].c_w = ' ';
                    109:        }
                    110:        /*
                    111:         * Now free the old stuff.
                    112:         */
                    113:        wwfree((char **)w->ww_win, w->ww_w.t);
                    114:        w->ww_win = win;
                    115:        if (buf != 0) {
                    116:                wwfree((char **)w->ww_buf, w->ww_b.t);
                    117:                w->ww_buf = buf;
                    118:        }
                    119:        if (w->ww_fmap != 0) {
                    120:                wwfree((char **)w->ww_fmap, w->ww_w.t);
                    121:                w->ww_fmap = fmap;
                    122:        }
                    123:        free((char *)(w->ww_nvis + w->ww_w.t));
                    124:        w->ww_nvis = nvis;
                    125:        /*
                    126:         * Set new sizes.
                    127:         */
                    128:                /* window */
                    129:        w->ww_w.b = w->ww_w.t + nrow;
                    130:        w->ww_w.r = w->ww_w.l + ncol;
                    131:        w->ww_w.nr = nrow;
                    132:        w->ww_w.nc = ncol;
                    133:                /* text buffer */
                    134:        if (buf != 0) {
                    135:                w->ww_b.b = w->ww_b.t + nline;
                    136:                w->ww_b.r = w->ww_b.l + ncol;
                    137:                w->ww_b.nr = nline;
                    138:                w->ww_b.nc = ncol;
                    139:        }
                    140:                /* scroll */
                    141:        if ((i = w->ww_b.b - w->ww_w.b) < 0 ||
                    142:            (i = w->ww_cur.r - w->ww_w.b + 1) > 0) {
                    143:                w->ww_buf += i;
                    144:                w->ww_b.t -= i;
                    145:                w->ww_b.b -= i;
                    146:                w->ww_cur.r -= i;
                    147:        }
                    148:                /* interior */
                    149:        w->ww_i.b = MIN(w->ww_w.b, wwnrow);
                    150:        w->ww_i.r = MIN(w->ww_w.r, wwncol);
                    151:        w->ww_i.nr = w->ww_i.b - w->ww_i.t;
                    152:        w->ww_i.nc = w->ww_i.r - w->ww_i.l;
                    153:        /*
                    154:         * Initialize new buffers.
                    155:         */
                    156:                /* window */
                    157:        m = 0;
                    158:        if (w->ww_oflags & WWO_GLASS)
                    159:                m |= WWM_GLS;
                    160:        if (w->ww_oflags & WWO_REVERSE)
                    161:                m |= WWM_REV;
                    162:        for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    163:                for (j = w->ww_w.l; j < w->ww_w.r; j++)
                    164:                        w->ww_win[i][j] = m;
                    165:                /* frame map */
                    166:        if (fmap != 0)
                    167:                for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    168:                        for (j = w->ww_w.l; j < w->ww_w.r; j++)
                    169:                                w->ww_fmap[i][j] = 0;
                    170:                /* visibility */
                    171:        j = m ? 0 : w->ww_w.nc;
                    172:        for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    173:                w->ww_nvis[i] = j;
                    174:        /*
                    175:         * Put cursor back.
                    176:         */
                    177:        if (w->ww_hascursor) {
                    178:                w->ww_hascursor = 0;
                    179:                wwcursor(w, 1);
                    180:        }
                    181:        /*
                    182:         * Fool with pty.
                    183:         */
1.2     ! deraadt   184:        if (w->ww_type == WWT_PTY && w->ww_pty >= 0)
1.1       deraadt   185:                (void) wwsetttysize(w->ww_pty, nrow, ncol);
                    186:        return 0;
                    187: bad:
                    188:        if (win != 0)
                    189:                wwfree(win, w->ww_w.t);
                    190:        if (fmap != 0)
                    191:                wwfree(fmap, w->ww_w.t);
                    192:        if (buf != 0)
                    193:                wwfree((char **)buf, w->ww_b.t);
                    194:        if (nvis != 0)
                    195:                free((char *)(nvis + w->ww_w.t));
                    196:        return -1;
                    197: }