1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/* $OpenBSD: wwsize.c,v 1.5 1997/02/25 00:05:08 downsj Exp $ */
/* $NetBSD: wwsize.c,v 1.5 1996/02/08 20:45:11 mycroft Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Edward Wang at The University of California, Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)wwsize.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$OpenBSD: wwsize.c,v 1.5 1997/02/25 00:05:08 downsj Exp $";
#endif
#endif /* not lint */
#include "ww.h"
/*
* Resize a window. Should be unattached.
*/
wwsize(w, nrow, ncol)
register struct ww *w;
{
register i, j;
int nline;
union ww_char **buf = 0;
char **win = 0;
short *nvis = 0;
char **fmap = 0;
char m;
/*
* First allocate new buffers.
*/
win = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
if (win == 0)
goto bad;
if (w->ww_fmap != 0) {
fmap = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char));
if (fmap == 0)
goto bad;
}
if (nrow > w->ww_b.nr || ncol > w->ww_b.nc) {
nline = MAX(w->ww_b.nr, nrow);
buf = (union ww_char **) wwalloc(w->ww_b.t, w->ww_b.l,
nline, ncol, sizeof (union ww_char));
if (buf == 0)
goto bad;
}
nvis = (short *)malloc((unsigned) nrow * sizeof (short));
if (nvis == 0) {
wwerrno = WWE_NOMEM;
goto bad;
}
nvis -= w->ww_w.t;
/*
* Copy text buffer.
*/
if (buf != 0) {
int b, r;
b = w->ww_b.t + nline;
r = w->ww_b.l + ncol;
if (ncol < w->ww_b.nc)
for (i = w->ww_b.t; i < w->ww_b.b; i++)
for (j = w->ww_b.l; j < r; j++)
buf[i][j] = w->ww_buf[i][j];
else
for (i = w->ww_b.t; i < w->ww_b.b; i++) {
for (j = w->ww_b.l; j < w->ww_b.r; j++)
buf[i][j] = w->ww_buf[i][j];
for (; j < r; j++)
buf[i][j].c_w = ' ';
}
for (; i < b; i++)
for (j = w->ww_b.l; j < r; j++)
buf[i][j].c_w = ' ';
}
/*
* Now free the old stuff.
*/
wwfree((char **)w->ww_win, w->ww_w.t);
w->ww_win = win;
if (buf != 0) {
wwfree((char **)w->ww_buf, w->ww_b.t);
w->ww_buf = buf;
}
if (w->ww_fmap != 0) {
wwfree((char **)w->ww_fmap, w->ww_w.t);
w->ww_fmap = fmap;
}
free((char *)(w->ww_nvis + w->ww_w.t));
w->ww_nvis = nvis;
/*
* Set new sizes.
*/
/* window */
w->ww_w.b = w->ww_w.t + nrow;
w->ww_w.r = w->ww_w.l + ncol;
w->ww_w.nr = nrow;
w->ww_w.nc = ncol;
/* text buffer */
if (buf != 0) {
w->ww_b.b = w->ww_b.t + nline;
w->ww_b.r = w->ww_b.l + ncol;
w->ww_b.nr = nline;
w->ww_b.nc = ncol;
}
/* scroll */
if ((i = w->ww_b.b - w->ww_w.b) < 0 ||
(i = w->ww_cur.r - w->ww_w.b + 1) > 0) {
w->ww_buf += i;
w->ww_b.t -= i;
w->ww_b.b -= i;
w->ww_cur.r -= i;
}
/* interior */
w->ww_i.b = MIN(w->ww_w.b, wwnrow);
w->ww_i.r = MIN(w->ww_w.r, wwncol);
w->ww_i.nr = w->ww_i.b - w->ww_i.t;
w->ww_i.nc = w->ww_i.r - w->ww_i.l;
/*
* Initialize new buffers.
*/
/* window */
m = 0;
if (w->ww_oflags & WWO_GLASS)
m |= WWM_GLS;
if (w->ww_oflags & WWO_REVERSE)
m |= WWM_REV;
for (i = w->ww_w.t; i < w->ww_w.b; i++)
for (j = w->ww_w.l; j < w->ww_w.r; j++)
w->ww_win[i][j] = m;
/* frame map */
if (fmap != 0)
for (i = w->ww_w.t; i < w->ww_w.b; i++)
for (j = w->ww_w.l; j < w->ww_w.r; j++)
w->ww_fmap[i][j] = 0;
/* visibility */
j = m ? 0 : w->ww_w.nc;
for (i = w->ww_w.t; i < w->ww_w.b; i++)
w->ww_nvis[i] = j;
/*
* Put cursor back.
*/
if (ISSET(w->ww_wflags, WWW_HASCURSOR)) {
CLR(w->ww_wflags, WWW_HASCURSOR);
wwcursor(w, 1);
}
/*
* Fool with pty.
*/
if (w->ww_type == WWT_PTY && w->ww_pty >= 0)
(void) wwsetttysize(w->ww_pty, nrow, ncol);
return 0;
bad:
if (win != 0)
wwfree(win, w->ww_w.t);
if (fmap != 0)
wwfree(fmap, w->ww_w.t);
if (buf != 0)
wwfree((char **)buf, w->ww_b.t);
if (nvis != 0)
free((char *)(nvis + w->ww_w.t));
return -1;
}
|