1 /*
2 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
8
9 /*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
13 */
14
15 /*LINTLIBRARY*/
16
17 #ifndef lint
18 static char
19 sccsid[] = "@(#)delwin.c 1.6 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
20 #endif /* not lint */
21
22 #include "curses.ext"
23 #include <malloc.h>
24
25 /*
26 * This routine deletes a window and releases it back to the system.
27 */
28
29 int
delwin(WINDOW * win)30 delwin(WINDOW *win)
31 {
32 int i;
33 WINDOW *wp, *np;
34
35 if (win->_orig == NULL) {
36 /*
37 * If we are the original window, delete the space for
38 * all the subwindows, and the array of space as well.
39 */
40 for (i = 0; i < win->_maxy && win->_y[i]; i++)
41 free(win->_y[i]);
42 free(win->_firstch);
43 free(win->_lastch);
44 wp = win->_nextp;
45 while (wp != win) {
46 np = wp->_nextp;
47 (void) delwin(wp);
48 wp = np;
49 }
50 } else {
51 /*
52 * If we are a subwindow, take ourselves out of the
53 * list. NOTE: if we are a subwindow, the minimum list
54 * is orig followed by this subwindow, so there are
55 * always at least two windows in the list.
56 */
57 for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp)
58 continue;
59 wp->_nextp = win->_nextp;
60 }
61 free(win->_y);
62 free(win);
63
64 return (OK);
65 }
66