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