1: #ifndef lint
   2: static char sccsid[] = "@(#)wwsize.c	3.3 4/24/85";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1983 Regents of the University of California,
   7:  * All rights reserved.  Redistribution permitted subject to
   8:  * the terms of the Berkeley Software License Agreement.
   9:  */
  10: 
  11: #include "ww.h"
  12: 
  13: /*
  14:  * Resize a window.  Should be unattached.
  15:  */
  16: wwsize(w, nrow, ncol)
  17: register struct ww *w;
  18: {
  19:     register i, j;
  20:     int nline;
  21:     union ww_char **buf = 0;
  22:     char **win = 0;
  23:     short *nvis = 0;
  24:     char **fmap = 0;
  25:     char m;
  26: 
  27:     /*
  28: 	 * First allocate new buffers.
  29: 	 */
  30:     win = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
  31:     if (win == 0)
  32:         goto bad;
  33:     if (w->ww_fmap != 0) {
  34:         fmap = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
  35:         if (fmap == 0)
  36:             goto bad;
  37:     }
  38:     if (nrow > w->ww_b.nr || ncol > w->ww_b.nc) {
  39:         nline = MAX(w->ww_b.nr, nrow);
  40:         buf = (union ww_char **) wwalloc(w->ww_b.t, w->ww_b.l,
  41:             nline, ncol, sizeof (union ww_char));
  42:         if (buf == 0)
  43:             goto bad;
  44:     }
  45:     nvis = (short *)malloc((unsigned) nrow * sizeof (short));
  46:     if (nvis == 0) {
  47:         wwerrno = WWE_NOMEM;
  48:         goto bad;
  49:     }
  50:     nvis -= w->ww_w.t;
  51:     /*
  52: 	 * Copy text buffer.
  53: 	 */
  54:     if (buf != 0) {
  55:         int b, r;
  56: 
  57:         b = w->ww_b.t + nline;
  58:         r = w->ww_b.l + ncol;
  59:         if (ncol < w->ww_b.nc)
  60:             for (i = w->ww_b.t; i < w->ww_b.b; i++)
  61:                 for (j = w->ww_b.l; j < r; j++)
  62:                     buf[i][j] = w->ww_buf[i][j];
  63:         else
  64:             for (i = w->ww_b.t; i < w->ww_b.b; i++) {
  65:                 for (j = w->ww_b.l; j < w->ww_b.r; j++)
  66:                     buf[i][j] = w->ww_buf[i][j];
  67:                 for (; j < r; j++)
  68:                     buf[i][j].c_w = ' ';
  69:             }
  70:         for (; i < b; i++)
  71:             for (j = w->ww_b.l; j < r; j++)
  72:                 buf[i][j].c_w = ' ';
  73:     }
  74:     /*
  75: 	 * Now free the old stuff.
  76: 	 */
  77:     wwfree((char **)w->ww_win, w->ww_w.t);
  78:     w->ww_win = win;
  79:     if (buf != 0) {
  80:         wwfree((char **)w->ww_buf, w->ww_b.t);
  81:         w->ww_buf = buf;
  82:     }
  83:     if (w->ww_fmap != 0) {
  84:         wwfree((char **)w->ww_fmap, w->ww_w.t);
  85:         w->ww_fmap = fmap;
  86:     }
  87:     free((char *)(w->ww_nvis + w->ww_w.t));
  88:     w->ww_nvis = nvis;
  89:     /*
  90: 	 * Set new sizes.
  91: 	 */
  92:         /* window */
  93:     w->ww_w.b = w->ww_w.t + nrow;
  94:     w->ww_w.r = w->ww_w.l + ncol;
  95:     w->ww_w.nr = nrow;
  96:     w->ww_w.nc = ncol;
  97:         /* text buffer */
  98:     if (buf != 0) {
  99:         w->ww_b.b = w->ww_b.t + nline;
 100:         w->ww_b.r = w->ww_b.l + ncol;
 101:         w->ww_b.nr = nline;
 102:         w->ww_b.nc = ncol;
 103:     }
 104:         /* scroll */
 105:     if ((i = w->ww_b.b - w->ww_w.b) < 0 ||
 106:         (i = w->ww_cur.r - w->ww_w.b + 1) > 0) {
 107:         w->ww_buf += i;
 108:         w->ww_b.t -= i;
 109:         w->ww_b.b -= i;
 110:         w->ww_cur.r -= i;
 111:     }
 112:         /* interior */
 113:     w->ww_i.b = MIN(w->ww_w.b, wwnrow);
 114:     w->ww_i.r = MIN(w->ww_w.r, wwncol);
 115:     w->ww_i.nr = w->ww_i.b - w->ww_i.t;
 116:     w->ww_i.nc = w->ww_i.r - w->ww_i.l;
 117:     /*
 118: 	 * Initialize new buffers.
 119: 	 */
 120:         /* window */
 121:     m = 0;
 122:     if (w->ww_oflags & WWO_GLASS)
 123:         m |= WWM_GLS;
 124:     if (w->ww_oflags & WWO_REVERSE)
 125:         m |= WWM_REV;
 126:     for (i = w->ww_w.t; i < w->ww_w.b; i++)
 127:         for (j = w->ww_w.l; j < w->ww_w.r; j++)
 128:             w->ww_win[i][j] = m;
 129:         /* frame map */
 130:     if (fmap != 0)
 131:         for (i = w->ww_w.t; i < w->ww_w.b; i++)
 132:             for (j = w->ww_w.l; j < w->ww_w.r; j++)
 133:                 w->ww_fmap[i][j] = 0;
 134:         /* visibility */
 135:     j = m ? 0 : w->ww_w.nc;
 136:     for (i = w->ww_w.t; i < w->ww_w.b; i++)
 137:         w->ww_nvis[i] = j;
 138:     /*
 139: 	 * Put cursor back.
 140: 	 */
 141:     if (w->ww_hascursor) {
 142:         w->ww_hascursor = 0;
 143:         wwcursor(w, 1);
 144:     }
 145:     /*
 146: 	 * Fool with pty.
 147: 	 */
 148:     if (w->ww_ispty && w->ww_pty >= 0) {
 149:         struct winsize winsize;
 150: 
 151:         winsize.ws_row = nrow;
 152:         winsize.ws_col = ncol;
 153:         winsize.ws_xpixel = winsize.ws_ypixel = 0;
 154:         (void) ioctl(w->ww_pty, TIOCSWINSZ, (char *)&winsize);
 155:     }
 156:     return 0;
 157: bad:
 158:     if (win != 0)
 159:         wwfree(win, w->ww_w.t);
 160:     if (fmap != 0)
 161:         wwfree(fmap, w->ww_w.t);
 162:     if (buf != 0)
 163:         wwfree((char **)buf, w->ww_b.t);
 164:     if (nvis != 0)
 165:         free((char *)(nvis + w->ww_w.t));
 166:     return -1;
 167: }

Defined functions

wwsize defined in line 16; used 1 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1988-06-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2238
Valid CSS Valid XHTML 1.0 Strict