Annotation of 43BSDTahoe/ucb/window/wwsize.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: static char sccsid[] = "@(#)wwsize.c   3.6 (Berkeley) 6/29/88";
                     20: #endif /* not lint */
                     21: 
                     22: #include "ww.h"
                     23: 
                     24: /*
                     25:  * Resize a window.  Should be unattached.
                     26:  */
                     27: wwsize(w, nrow, ncol)
                     28: register struct ww *w;
                     29: {
                     30:        register i, j;
                     31:        int nline;
                     32:        union ww_char **buf = 0;
                     33:        char **win = 0;
                     34:        short *nvis = 0;
                     35:        char **fmap = 0;
                     36:        char m;
                     37: 
                     38:        /*
                     39:         * First allocate new buffers.
                     40:         */
                     41:        win = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
                     42:        if (win == 0)
                     43:                goto bad;
                     44:        if (w->ww_fmap != 0) {
                     45:                fmap = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
                     46:                if (fmap == 0)
                     47:                        goto bad;
                     48:        }
                     49:        if (nrow > w->ww_b.nr || ncol > w->ww_b.nc) {
                     50:                nline = MAX(w->ww_b.nr, nrow);
                     51:                buf = (union ww_char **) wwalloc(w->ww_b.t, w->ww_b.l,
                     52:                        nline, ncol, sizeof (union ww_char));
                     53:                if (buf == 0)
                     54:                        goto bad;
                     55:        }
                     56:        nvis = (short *)malloc((unsigned) nrow * sizeof (short));
                     57:        if (nvis == 0) {
                     58:                wwerrno = WWE_NOMEM;
                     59:                goto bad;
                     60:        }
                     61:        nvis -= w->ww_w.t;
                     62:        /*
                     63:         * Copy text buffer.
                     64:         */
                     65:        if (buf != 0) {
                     66:                int b, r;
                     67: 
                     68:                b = w->ww_b.t + nline;
                     69:                r = w->ww_b.l + ncol;
                     70:                if (ncol < w->ww_b.nc)
                     71:                        for (i = w->ww_b.t; i < w->ww_b.b; i++)
                     72:                                for (j = w->ww_b.l; j < r; j++)
                     73:                                        buf[i][j] = w->ww_buf[i][j];
                     74:                else
                     75:                        for (i = w->ww_b.t; i < w->ww_b.b; i++) {
                     76:                                for (j = w->ww_b.l; j < w->ww_b.r; j++)
                     77:                                        buf[i][j] = w->ww_buf[i][j];
                     78:                                for (; j < r; j++)
                     79:                                        buf[i][j].c_w = ' ';
                     80:                        }
                     81:                for (; i < b; i++)
                     82:                        for (j = w->ww_b.l; j < r; j++)
                     83:                                buf[i][j].c_w = ' ';
                     84:        }
                     85:        /*
                     86:         * Now free the old stuff.
                     87:         */
                     88:        wwfree((char **)w->ww_win, w->ww_w.t);
                     89:        w->ww_win = win;
                     90:        if (buf != 0) {
                     91:                wwfree((char **)w->ww_buf, w->ww_b.t);
                     92:                w->ww_buf = buf;
                     93:        }
                     94:        if (w->ww_fmap != 0) {
                     95:                wwfree((char **)w->ww_fmap, w->ww_w.t);
                     96:                w->ww_fmap = fmap;
                     97:        }
                     98:        free((char *)(w->ww_nvis + w->ww_w.t));
                     99:        w->ww_nvis = nvis;
                    100:        /*
                    101:         * Set new sizes.
                    102:         */
                    103:                /* window */
                    104:        w->ww_w.b = w->ww_w.t + nrow;
                    105:        w->ww_w.r = w->ww_w.l + ncol;
                    106:        w->ww_w.nr = nrow;
                    107:        w->ww_w.nc = ncol;
                    108:                /* text buffer */
                    109:        if (buf != 0) {
                    110:                w->ww_b.b = w->ww_b.t + nline;
                    111:                w->ww_b.r = w->ww_b.l + ncol;
                    112:                w->ww_b.nr = nline;
                    113:                w->ww_b.nc = ncol;
                    114:        }
                    115:                /* scroll */
                    116:        if ((i = w->ww_b.b - w->ww_w.b) < 0 ||
                    117:            (i = w->ww_cur.r - w->ww_w.b + 1) > 0) {
                    118:                w->ww_buf += i;
                    119:                w->ww_b.t -= i;
                    120:                w->ww_b.b -= i;
                    121:                w->ww_cur.r -= i;
                    122:        }
                    123:                /* interior */
                    124:        w->ww_i.b = MIN(w->ww_w.b, wwnrow);
                    125:        w->ww_i.r = MIN(w->ww_w.r, wwncol);
                    126:        w->ww_i.nr = w->ww_i.b - w->ww_i.t;
                    127:        w->ww_i.nc = w->ww_i.r - w->ww_i.l;
                    128:        /*
                    129:         * Initialize new buffers.
                    130:         */
                    131:                /* window */
                    132:        m = 0;
                    133:        if (w->ww_oflags & WWO_GLASS)
                    134:                m |= WWM_GLS;
                    135:        if (w->ww_oflags & WWO_REVERSE)
                    136:                m |= WWM_REV;
                    137:        for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    138:                for (j = w->ww_w.l; j < w->ww_w.r; j++)
                    139:                        w->ww_win[i][j] = m;
                    140:                /* frame map */
                    141:        if (fmap != 0)
                    142:                for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    143:                        for (j = w->ww_w.l; j < w->ww_w.r; j++)
                    144:                                w->ww_fmap[i][j] = 0;
                    145:                /* visibility */
                    146:        j = m ? 0 : w->ww_w.nc;
                    147:        for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    148:                w->ww_nvis[i] = j;
                    149:        /*
                    150:         * Put cursor back.
                    151:         */
                    152:        if (w->ww_hascursor) {
                    153:                w->ww_hascursor = 0;
                    154:                wwcursor(w, 1);
                    155:        }
                    156:        /*
                    157:         * Fool with pty.
                    158:         */
                    159:        if (w->ww_ispty && w->ww_pty >= 0) {
                    160:                struct winsize winsize;
                    161: 
                    162:                winsize.ws_row = nrow;
                    163:                winsize.ws_col = ncol;
                    164:                winsize.ws_xpixel = winsize.ws_ypixel = 0;
                    165:                (void) ioctl(w->ww_pty, TIOCSWINSZ, (char *)&winsize);
                    166:        }
                    167:        return 0;
                    168: bad:
                    169:        if (win != 0)
                    170:                wwfree(win, w->ww_w.t);
                    171:        if (fmap != 0)
                    172:                wwfree(fmap, w->ww_w.t);
                    173:        if (buf != 0)
                    174:                wwfree((char **)buf, w->ww_b.t);
                    175:        if (nvis != 0)
                    176:                free((char *)(nvis + w->ww_w.t));
                    177:        return -1;
                    178: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.