xref: /original-bsd/lib/libcurses/delwin.c (revision 860e07fc)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)delwin.c	5.6 (Berkeley) 08/23/92";
10 #endif	/* not lint */
11 
12 #include <curses.h>
13 #include <stdlib.h>
14 
15 /*
16  * delwin --
17  *	Delete a window and release it back to the system.
18  */
19 int
20 delwin(win)
21 	register WINDOW *win;
22 {
23 
24 	register WINDOW *wp, *np;
25 	register int i;
26 
27 	if (win->_orig == NULL) {
28 		/*
29 		 * If we are the original window, delete the space for all
30 		 * the subwindows, and the array of space as well.
31 		 */
32 		for (i = 0; i < win->_maxy && win->_y[i]; i++)
33 			free(win->_y[i]);
34 		free(win->_firstch);
35 		free(win->_lastch);
36 		wp = win->_nextp;
37 		while (wp != win) {
38 			np = wp->_nextp;
39 			delwin(wp);
40 			wp = np;
41 		}
42 	} else {
43 		/*
44 		 * If we are a subwindow, take ourselves out of the list.
45 		 * NOTE: if we are a subwindow, the minimum list is orig
46 		 * followed by this subwindow, so there are always at least
47 		 * two windows in the list.
48 		 */
49 		for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp)
50 			continue;
51 		wp->_nextp = win->_nextp;
52 	}
53 	free(win->_y);
54 	free(win);
55 	return (OK);
56 }
57