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