border.c revision 1.19 1 /* $NetBSD: border.c,v 1.19 2021/09/06 07:03:49 rin Exp $ */
2
3 /*
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julian Coleman.
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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 __RCSID("$NetBSD: border.c,v 1.19 2021/09/06 07:03:49 rin Exp $");
35 #endif /* not lint */
36
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "curses.h"
41 #include "curses_private.h"
42
43 #ifndef _CURSES_USE_MACROS
44
45 /*
46 * border --
47 * Draw a border around stdscr using the specified
48 * delimiting characters.
49 */
50 int
51 border(chtype left, chtype right, chtype top, chtype bottom, chtype topleft,
52 chtype topright, chtype botleft, chtype botright)
53 {
54 return wborder(stdscr, left, right, top, bottom, topleft, topright,
55 botleft, botright);
56 }
57
58 #endif
59
60 /*
61 * wborder --
62 * Draw a border around the given window using the specified delimiting
63 * characters.
64 */
65 int
66 wborder(WINDOW *win, chtype left, chtype right, chtype top, chtype bottom,
67 chtype topleft, chtype topright, chtype botleft, chtype botright)
68 {
69 #ifndef HAVE_WCHAR
70 int endy, endx, i;
71 __LDATA *fp, *lp;
72
73 if (!(left & __CHARTEXT))
74 left |= ACS_VLINE;
75 if (!(right & __CHARTEXT))
76 right |= ACS_VLINE;
77 if (!(top & __CHARTEXT))
78 top |= ACS_HLINE;
79 if (!(bottom & __CHARTEXT))
80 bottom |= ACS_HLINE;
81 if (!(topleft & __CHARTEXT))
82 topleft |= ACS_ULCORNER;
83 if (!(topright & __CHARTEXT))
84 topright |= ACS_URCORNER;
85 if (!(botleft & __CHARTEXT))
86 botleft |= ACS_LLCORNER;
87 if (!(botright & __CHARTEXT))
88 botright |= ACS_LRCORNER;
89
90 __CTRACE(__CTRACE_INPUT, "wborder: left = %c, 0x%x\n",
91 left & __CHARTEXT, left & __ATTRIBUTES);
92 __CTRACE(__CTRACE_INPUT, "wborder: right = %c, 0x%x\n",
93 right & __CHARTEXT, right & __ATTRIBUTES);
94 __CTRACE(__CTRACE_INPUT, "wborder: top = %c, 0x%x\n",
95 top & __CHARTEXT, top & __ATTRIBUTES);
96 __CTRACE(__CTRACE_INPUT, "wborder: bottom = %c, 0x%x\n",
97 bottom & __CHARTEXT, bottom & __ATTRIBUTES);
98 __CTRACE(__CTRACE_INPUT, "wborder: topleft = %c, 0x%x\n",
99 topleft & __CHARTEXT, topleft & __ATTRIBUTES);
100 __CTRACE(__CTRACE_INPUT, "wborder: topright = %c, 0x%x\n",
101 topright & __CHARTEXT, topright & __ATTRIBUTES);
102 __CTRACE(__CTRACE_INPUT, "wborder: botleft = %c, 0x%x\n",
103 botleft & __CHARTEXT, botleft & __ATTRIBUTES);
104 __CTRACE(__CTRACE_INPUT, "wborder: botright = %c, 0x%x\n",
105 botright & __CHARTEXT, botright & __ATTRIBUTES);
106
107 /* Merge window and background attributes */
108 left |= (left & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
109 left |= (left & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
110 right |= (right & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
111 right |= (right & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
112 top |= (top & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
113 top |= (top & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
114 bottom |= (bottom & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
115 bottom |= (bottom & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
116 topleft |= (topleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
117 topleft |= (topleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
118 topright |= (topright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
119 topright |= (topright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
120 botleft |= (botleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
121 botleft |= (botleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
122 botright |= (botright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
123 botright |= (botright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
124
125 endx = win->maxx - 1;
126 endy = win->maxy - 1;
127 fp = win->alines[0]->line;
128 lp = win->alines[endy]->line;
129
130 /* Sides */
131 for (i = 1; i < endy; i++) {
132 win->alines[i]->line[0].ch = (wchar_t) left & __CHARTEXT;
133 win->alines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES;
134 win->alines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT;
135 win->alines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES;
136 }
137 for (i = 1; i < endx; i++) {
138 fp[i].ch = (wchar_t) top & __CHARTEXT;
139 fp[i].attr = (attr_t) top & __ATTRIBUTES;
140 lp[i].ch = (wchar_t) bottom & __CHARTEXT;
141 lp[i].attr = (attr_t) bottom & __ATTRIBUTES;
142 }
143
144 /* Corners */
145 if (!(win->maxy == LINES && win->maxx == COLS &&
146 (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
147 fp[0].ch = (wchar_t) topleft & __CHARTEXT;
148 fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
149 fp[endx].ch = (wchar_t) topright & __CHARTEXT;
150 fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
151 lp[0].ch = (wchar_t) botleft & __CHARTEXT;
152 lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
153 lp[endx].ch = (wchar_t) botright & __CHARTEXT;
154 lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
155 }
156 __touchwin(win);
157 return OK;
158 #else /* HAVE_WCHAR */
159 cchar_t ls, rs, ts, bs, tl, tr, bl, br;
160 cchar_t *lsp, *rsp, *tsp, *bsp, *tlp, *trp, *blp, *brp;
161
162 #define S(in, out, def) \
163 if (in & __CHARTEXT) { \
164 __cursesi_chtype_to_cchar(in, &out); \
165 } else { \
166 memcpy(&out, def, sizeof(cchar_t)); \
167 out.attributes |= in & __ATTRIBUTES; \
168 } \
169 out##p = &out;
170
171 S(left, ls, WACS_VLINE);
172 S(right, rs, WACS_VLINE);
173 S(top, ts, WACS_HLINE);
174 S(bottom, bs, WACS_HLINE);
175 S(topleft, tl, WACS_ULCORNER);
176 S(topright, tr, WACS_URCORNER);
177 S(botleft, bl, WACS_LLCORNER);
178 S(botright, br, WACS_LRCORNER);
179 #undef S
180 return wborder_set(win, lsp, rsp, tsp, bsp, tlp, trp, blp, brp);
181 #endif /* HAVE_WCHAR */
182 }
183
184 int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
185 const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
186 const cchar_t *bl, const cchar_t *br)
187 {
188 #ifndef HAVE_WCHAR
189 return ERR;
190 #else
191 return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
192 #endif /* HAVE_WCHAR */
193 }
194
195 int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
196 const cchar_t *ts, const cchar_t *bs,
197 const cchar_t *tl, const cchar_t *tr,
198 const cchar_t *bl, const cchar_t *br)
199 {
200 #ifndef HAVE_WCHAR
201 return ERR;
202 #else
203 int endy, endx, i, j, k, cw, pcw, tlcw, blcw, trcw, brcw;
204 cchar_t left, right, bottom, top, topleft, topright, botleft, botright;
205 nschar_t *np, *tnp;
206
207 if (ls && wcwidth(ls->vals[0]))
208 memcpy(&left, ls, sizeof(cchar_t));
209 else
210 memcpy(&left, WACS_VLINE, sizeof(cchar_t));
211 if (rs && wcwidth( rs->vals[0]))
212 memcpy(&right, rs, sizeof(cchar_t));
213 else
214 memcpy(&right, WACS_VLINE, sizeof(cchar_t));
215 if (ts && wcwidth( ts->vals[0]))
216 memcpy(&top, ts, sizeof(cchar_t));
217 else
218 memcpy( &top, WACS_HLINE, sizeof(cchar_t));
219 if (bs && wcwidth( bs->vals[0]))
220 memcpy(&bottom, bs, sizeof(cchar_t));
221 else
222 memcpy(&bottom, WACS_HLINE, sizeof(cchar_t));
223 if (tl && wcwidth(tl->vals[0]))
224 memcpy( &topleft, tl, sizeof(cchar_t));
225 else
226 memcpy(&topleft, WACS_ULCORNER, sizeof(cchar_t));
227 if (tr && wcwidth( tr->vals[0]))
228 memcpy(&topright, tr, sizeof(cchar_t));
229 else
230 memcpy(&topright, WACS_URCORNER, sizeof( cchar_t ));
231 if (bl && wcwidth( bl->vals[0]))
232 memcpy(&botleft, bl, sizeof(cchar_t));
233 else
234 memcpy(&botleft, WACS_LLCORNER, sizeof(cchar_t));
235 if (br && wcwidth( br->vals[0]))
236 memcpy(&botright, br, sizeof(cchar_t));
237 else
238 memcpy(&botright, WACS_LRCORNER, sizeof(cchar_t));
239
240 __CTRACE(__CTRACE_INPUT, "wborder_set: left = %c, 0x%x\n",
241 left.vals[0], left.attributes );
242 __CTRACE(__CTRACE_INPUT, "wborder_set: right = %c, 0x%x\n",
243 right.vals[0], right.attributes );
244 __CTRACE(__CTRACE_INPUT, "wborder_set: top = %c, 0x%x\n",
245 top.vals[0], top.attributes );
246 __CTRACE(__CTRACE_INPUT, "wborder_set: bottom = %c, 0x%x\n",
247 bottom.vals[0], bottom.attributes );
248 __CTRACE(__CTRACE_INPUT, "wborder_set: topleft = %c, 0x%x\n",
249 topleft.vals[0], topleft.attributes );
250 __CTRACE(__CTRACE_INPUT, "wborder_set: topright = %c, 0x%x\n",
251 topright.vals[0], topright.attributes );
252 __CTRACE(__CTRACE_INPUT, "wborder_set: botleft = %c, 0x%x\n",
253 botleft.vals[0], botleft.attributes );
254 __CTRACE(__CTRACE_INPUT, "wborder_set: botright = %c, 0x%x\n",
255 botright.vals[0], botright.attributes );
256
257 /* Merge window attributes */
258 left.attributes |= (left.attributes & __COLOR) ?
259 (win->wattr & ~__COLOR) : win->wattr;
260 left.attributes |= (left.attributes & __COLOR) ?
261 (win->battr & ~__COLOR) : win->battr;
262 right.attributes |= (right.attributes & __COLOR) ?
263 (win->wattr & ~__COLOR) : win->wattr;
264 right.attributes |= (right.attributes & __COLOR) ?
265 (win->battr & ~__COLOR) : win->battr;
266 top.attributes |= (top.attributes & __COLOR) ?
267 (win->wattr & ~__COLOR) : win->wattr;
268 top.attributes |= (top.attributes & __COLOR) ?
269 (win->battr & ~__COLOR) : win->battr;
270 bottom.attributes |= (bottom.attributes & __COLOR) ?
271 (win->wattr & ~__COLOR) : win->wattr;
272 bottom.attributes |= (bottom.attributes & __COLOR) ?
273 (win->battr & ~__COLOR) : win->battr;
274 topleft.attributes |= (topleft.attributes & __COLOR) ?
275 (win->wattr & ~__COLOR) : win->wattr;
276 topleft.attributes |= (topleft.attributes & __COLOR) ?
277 (win->battr & ~__COLOR) : win->battr;
278 topright.attributes |= (topright.attributes & __COLOR) ?
279 (win->wattr & ~__COLOR) : win->wattr;
280 topright.attributes |= (topright.attributes & __COLOR) ?
281 (win->battr & ~__COLOR) : win->battr;
282 botleft.attributes |= (botleft.attributes & __COLOR) ?
283 (win->wattr & ~__COLOR) : win->wattr;
284 botleft.attributes |= (botleft.attributes & __COLOR) ?
285 (win->battr & ~__COLOR) : win->battr;
286 botright.attributes |= (botright.attributes & __COLOR) ?
287 (win->wattr & ~__COLOR) : win->wattr;
288 botright.attributes |= (botright.attributes & __COLOR) ?
289 (win->battr & ~__COLOR) : win->battr;
290
291 endx = win->maxx - 1;
292 endy = win->maxy - 1;
293
294 /* Sides */
295 for (i = 1; i < endy; i++) {
296 /* left border */
297 cw = wcwidth(left.vals[0]);
298 if (cw < 0)
299 cw = 1;
300 for ( j = 0; j < cw; j++ ) {
301 win->alines[i]->line[j].ch = left.vals[0];
302 win->alines[i]->line[j].attr = left.attributes;
303 np = win->alines[i]->line[j].nsp;
304 if (np) {
305 while (np) {
306 tnp = np->next;
307 free(np);
308 np = tnp;
309 }
310 win->alines[i]->line[j].nsp = NULL;
311 }
312 if (j)
313 SET_WCOL(win->alines[i]->line[j], -j);
314 else {
315 SET_WCOL(win->alines[i]->line[j], cw);
316 if (left.elements > 1) {
317 for (k = 1; k < left.elements; k++) {
318 np = malloc(sizeof(nschar_t));
319 if (!np)
320 return ERR;
321 np->ch = left.vals[ k ];
322 np->next = win->alines[i]->line[j].nsp;
323 win->alines[i]->line[j].nsp
324 = np;
325 }
326 }
327 }
328 }
329 for (j = cw; WCOL(win->alines[i]->line[j]) < 0; j++) {
330 __CTRACE(__CTRACE_INPUT,
331 "wborder_set: clean out partial char[%d]", j);
332 win->alines[i]->line[j].ch = ( wchar_t )btowc(win->bch);
333 if (_cursesi_copy_nsp(win->bnsp,
334 &win->alines[i]->line[j]) == ERR)
335 return ERR;
336 SET_WCOL(win->alines[i]->line[j], 1);
337 }
338 /* right border */
339 cw = wcwidth(right.vals[0]);
340 if (cw < 0)
341 cw = 1;
342 pcw = WCOL( win->alines[i]->line[endx - cw]);
343 for ( j = endx - cw + 1; j <= endx; j++ ) {
344 win->alines[i]->line[j].ch = right.vals[0];
345 win->alines[i]->line[j].attr = right.attributes;
346 np = win->alines[i]->line[j].nsp;
347 if (np) {
348 while (np) {
349 tnp = np->next;
350 free(np);
351 np = tnp;
352 }
353 win->alines[i]->line[j].nsp = NULL;
354 }
355 if (j == endx - cw + 1) {
356 SET_WCOL(win->alines[i]->line[j], cw);
357 if (right.elements > 1) {
358 for (k = 1; k < right.elements; k++) {
359 np = malloc(sizeof(nschar_t));
360 if (!np)
361 return ERR;
362 np->ch = right.vals[ k ];
363 np->next = win->alines[i]->line[j].nsp;
364 win->alines[i]->line[j].nsp
365 = np;
366 }
367 }
368 } else
369 SET_WCOL(win->alines[i]->line[j],
370 endx - cw + 1 - j);
371 }
372 if (pcw != 1) {
373 __CTRACE(__CTRACE_INPUT,
374 "wborder_set: clean out partial chars[%d:%d]",
375 endx - cw + pcw, endx - cw );
376 k = pcw < 0 ? endx -cw + pcw : endx - cw;
377 for (j = endx - cw; j >= k; j--) {
378 win->alines[i]->line[j].ch
379 = (wchar_t)btowc(win->bch);
380 if (_cursesi_copy_nsp(win->bnsp,
381 &win->alines[i]->line[j]) == ERR)
382 return ERR;
383 win->alines[i]->line[j].attr = win->battr;
384 SET_WCOL(win->alines[i]->line[j], 1);
385 }
386 }
387 }
388 tlcw = wcwidth(topleft.vals[0]);
389 if (tlcw < 0)
390 tlcw = 1;
391 blcw = wcwidth(botleft.vals[0]);
392 if (blcw < 0)
393 blcw = 1;
394 trcw = wcwidth(topright.vals[0]);
395 if (trcw < 0)
396 trcw = 1;
397 brcw = wcwidth(botright.vals[0]);
398 if (brcw < 0)
399 brcw = 1;
400 /* upper border */
401 cw = wcwidth(top.vals[0]);
402 if (cw < 0)
403 cw = 1;
404 for (i = tlcw; i <= min( endx - cw, endx - trcw); i += cw) {
405 for (j = 0; j < cw; j++) {
406 win->alines[0]->line[i + j].ch = top.vals[0];
407 win->alines[0]->line[i + j].attr = top.attributes;
408 np = win->alines[0]->line[i + j].nsp;
409 if (np) {
410 while (np) {
411 tnp = np->next;
412 free(np);
413 np = tnp;
414 }
415 win->alines[0]->line[i + j].nsp = NULL;
416 }
417 if (j)
418 SET_WCOL(win->alines[ 0 ]->line[ i + j ], -j);
419 else {
420 SET_WCOL(win->alines[ 0 ]->line[ i + j ], cw);
421 if ( top.elements > 1 ) {
422 for (k = 1; k < top.elements; k++) {
423 np = malloc(sizeof(nschar_t));
424 if (!np)
425 return ERR;
426 np->ch = top.vals[k];
427 np->next = win->alines[0]->line[i + j].nsp;
428 win->alines[0]->line[i + j].nsp
429 = np;
430 }
431 }
432 }
433 }
434 }
435 while (i <= endx - trcw) {
436 win->alines[0]->line[i].ch =
437 (wchar_t)btowc((int) win->bch);
438 if (_cursesi_copy_nsp(win->bnsp,
439 &win->alines[0]->line[i]) == ERR)
440 return ERR;
441 win->alines[0]->line[i].attr = win->battr;
442 SET_WCOL(win->alines[0]->line[i], 1);
443 i++;
444 }
445 /* lower border */
446 for (i = blcw; i <= min( endx - cw, endx - brcw); i += cw) {
447 for (j = 0; j < cw; j++) {
448 win->alines[endy]->line[i + j].ch = bottom.vals[0];
449 win->alines[endy]->line[i + j].attr = bottom.attributes;
450 np = win->alines[endy]->line[i + j].nsp;
451 if (np) {
452 while (np) {
453 tnp = np->next;
454 free(np);
455 np = tnp;
456 }
457 win->alines[endy]->line[i + j].nsp = NULL;
458 }
459 if (j)
460 SET_WCOL(win->alines[endy]->line[i + j], -j);
461 else {
462 SET_WCOL(win->alines[endy]->line[i + j], cw);
463 if (bottom.elements > 1) {
464 for (k = 1; k < bottom.elements; k++) {
465 np = malloc(sizeof(nschar_t));
466 if (!np)
467 return ERR;
468 np->ch = bottom.vals[ k ];
469 np->next = win->alines[endy]->line[i + j].nsp;
470 win->alines[endy]->line[i + j].nsp = np;
471 }
472 }
473 }
474 }
475 }
476 while (i <= endx - brcw) {
477 win->alines[endy]->line[i].ch = (wchar_t)btowc((int) win->bch );
478 if (_cursesi_copy_nsp(win->bnsp,
479 &win->alines[endy]->line[i]) == ERR)
480 return ERR;
481 win->alines[endy]->line[i].attr = win->battr;
482 SET_WCOL(win->alines[endy]->line[ i ], 1);
483 i++;
484 }
485
486 /* Corners */
487 if (!(win->maxy == LINES && win->maxx == COLS &&
488 (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
489 for (i = 0; i < tlcw; i++) {
490 win->alines[0]->line[i].ch = topleft.vals[0];
491 win->alines[0]->line[i].attr = topleft.attributes;
492 np = win->alines[0]->line[i].nsp;
493 if (np) {
494 while (np) {
495 tnp = np->next;
496 free(np);
497 np = tnp;
498 }
499 win->alines[0]->line[i].nsp = NULL;
500 }
501 if (i)
502 SET_WCOL(win->alines[0]->line[i], -i);
503 else {
504 SET_WCOL(win->alines[0]->line[i], tlcw);
505 if (topleft.elements > 1) {
506 for (k = 1; k < topleft.elements; k++)
507 {
508 np = malloc(sizeof(nschar_t));
509 if (!np)
510 return ERR;
511 np->ch = topleft.vals[k];
512 np->next = win->alines[0]->line[i].nsp;
513 win->alines[0]->line[i].nsp = np;
514 }
515 }
516 }
517 }
518 for (i = endx - trcw + 1; i <= endx; i++) {
519 win->alines[0]->line[i].ch = topright.vals[0];
520 win->alines[0]->line[i].attr = topright.attributes;
521 np = win->alines[0]->line[i].nsp;
522 if (np) {
523 while (np) {
524 tnp = np->next;
525 free(np);
526 np = tnp;
527 }
528 win->alines[0]->line[i].nsp = NULL;
529 }
530 if (i == endx - trcw + 1) {
531 SET_WCOL(win->alines[0]->line[i], trcw);
532 if (topright.elements > 1) {
533 for (k = 1; k < topright.elements;k ++)
534 {
535 np = malloc(sizeof(nschar_t));
536 if (!np)
537 return ERR;
538 np->ch = topright.vals[k];
539 np->next = win->alines[0]->line[i].nsp;
540 win->alines[ 0 ]->line[i].nsp = np;
541 }
542 }
543 } else
544 SET_WCOL(win->alines[0]->line[i],
545 endx - trcw + 1 - i);
546 }
547 for (i = 0; i < blcw; i++) {
548 win->alines[endy]->line[i].ch = botleft.vals[0];
549 win->alines[endy]->line[i].attr = botleft.attributes;
550 np = win->alines[ endy ]->line[i].nsp;
551 if (np) {
552 while (np) {
553 tnp = np->next;
554 free(np);
555 np = tnp;
556 }
557 win->alines[endy]->line[i].nsp = NULL;
558 }
559 if (i)
560 SET_WCOL(win->alines[endy]->line[i], -i);
561 else {
562 SET_WCOL(win->alines[endy]->line[i], blcw);
563 if (botleft.elements > 1) {
564 for (k = 1; k < botleft.elements; k++) {
565 np = malloc(sizeof(nschar_t));
566 if (!np)
567 return ERR;
568 np->ch = botleft.vals[ k ];
569 np->next = win->alines[endy]->line[i].nsp;
570 win->alines[endy]->line[i].nsp = np;
571 }
572 }
573 }
574 }
575 for (i = endx - brcw + 1; i <= endx; i++) {
576 win->alines[endy]->line[i].ch = botright.vals[0];
577 win->alines[endy]->line[i].attr = botright.attributes;
578 np = win->alines[endy]->line[i].nsp;
579 if (np) {
580 while (np) {
581 tnp = np->next;
582 free(np);
583 np = tnp;
584 }
585 win->alines[endy]->line[i].nsp = NULL;
586 }
587 if (i == endx - brcw + 1) {
588 SET_WCOL(win->alines[endy]->line[i], brcw);
589 if (botright.elements > 1) {
590 for (k = 1; k < botright.elements; k++){
591 np = malloc(sizeof(nschar_t));
592 if (!np)
593 return ERR;
594 np->ch = botright.vals[k];
595 np->next = win->alines[endy]->line[i].nsp;
596 win->alines[endy]->line[i].nsp = np;
597 }
598 }
599 } else
600 SET_WCOL(win->alines[endy]->line[i],
601 endx - brcw + 1 - i);
602 }
603 }
604 __touchwin(win);
605 return OK;
606 #endif /* HAVE_WCHAR */
607 }
608