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