xref: /original-bsd/lib/libcurses/delwin.c (revision 262b24ac)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)delwin.c	5.3 (Berkeley) 06/30/88";
20 #endif /* not lint */
21 
22 # include	"curses.ext"
23 
24 /*
25  *	This routine deletes a window and releases it back to the system.
26  *
27  */
28 delwin(win)
29 reg WINDOW	*win; {
30 
31 	reg int		i;
32 	reg WINDOW	*wp, *np;
33 
34 	if (win->_orig == NULL) {
35 		/*
36 		 * If we are the original window, delete the space for
37 		 * all the subwindows, and the array of space as well.
38 		 */
39 		for (i = 0; i < win->_maxy && win->_y[i]; i++)
40 			free(win->_y[i]);
41 		free(win->_firstch);
42 		free(win->_lastch);
43 		wp = win->_nextp;
44 		while (wp != win) {
45 			np = wp->_nextp;
46 			delwin(wp);
47 			wp = np;
48 		}
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