xref: /original-bsd/lib/libcurses/delwin.c (revision 92d3de31)
1 # include	"curses.ext"
2 
3 /*
4  *	This routine deletes a window and releases it back to the system.
5  *
6  * 04/06/83 (Berkeley) @(#)delwin.c	1.5
7  */
8 delwin(win)
9 reg WINDOW	*win; {
10 
11 	reg int		i;
12 	reg WINDOW	*wp, *np;
13 
14 	if (win->_orig == NULL) {
15 		/*
16 		 * If we are the original window, delete the space for
17 		 * all the subwindows, and the array of space as well.
18 		 */
19 		for (i = 0; i < win->_maxy && win->_y[i]; i++)
20 			cfree(win->_y[i]);
21 		wp = win->_nextp;
22 		while (wp != win) {
23 			np = wp->_nextp;
24 			delwin(wp);
25 			wp = np;
26 		}
27 	}
28 	else {
29 		/*
30 		 * If we are a subwindow, take ourself out of the
31 		 * list.  NOTE: if we are a subwindow, the minimum list
32 		 * is orig followed by this subwindow, so there are
33 		 * always at least two windows in the list.
34 		 */
35 		for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp)
36 			continue;
37 		wp->_nextp = win->_nextp;
38 	}
39 	cfree(win->_y);
40 	cfree(win->_firstch);
41 	cfree(win->_lastch);
42 	cfree(win);
43 }
44