xref: /titanic_52/usr/src/ucblib/libcurses/delwin.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /*LINTLIBRARY*/
18 
19 #ifndef lint
20 static char
21 sccsid[] = "@(#)delwin.c 1.6 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
22 #endif /* not lint */
23 
24 #include	"curses.ext"
25 #include	<malloc.h>
26 
27 /*
28  *	This routine deletes a window and releases it back to the system.
29  */
30 
31 int
32 delwin(WINDOW *win)
33 {
34 	int	i;
35 	WINDOW	*wp, *np;
36 
37 	if (win->_orig == NULL) {
38 		/*
39 		 * If we are the original window, delete the space for
40 		 * all the subwindows, and the array of space as well.
41 		 */
42 		for (i = 0; i < win->_maxy && win->_y[i]; i++)
43 			free(win->_y[i]);
44 		free(win->_firstch);
45 		free(win->_lastch);
46 		wp = win->_nextp;
47 		while (wp != win) {
48 			np = wp->_nextp;
49 			(void) delwin(wp);
50 			wp = np;
51 		}
52 	} else {
53 		/*
54 		 * If we are a subwindow, take ourselves out of the
55 		 * list.  NOTE: if we are a subwindow, the minimum list
56 		 * is orig followed by this subwindow, so there are
57 		 * always at least two windows in the list.
58 		 */
59 		for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp)
60 			continue;
61 		wp->_nextp = win->_nextp;
62 	}
63 	free(win->_y);
64 	free(win);
65 
66 	return (OK);
67 }
68