xref: /original-bsd/lib/libcurses/delwin.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1981, 1993
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.1 (Berkeley) 06/04/93";
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 
26 	if (win->orig == NULL) {
27 		/*
28 		 * If we are the original window, delete the space for all
29 		 * the subwindows, the line space and the window space.
30 		 */
31 		free(win->lspace);
32 		free(win->wspace);
33 		free(win->lines);
34 		wp = win->nextp;
35 		while (wp != win) {
36 			np = wp->nextp;
37 			delwin(wp);
38 			wp = np;
39 		}
40 	} else {
41 		/*
42 		 * If we are a subwindow, take ourselves out of the list.
43 		 * NOTE: if we are a subwindow, the minimum list is orig
44 		 * followed by this subwindow, so there are always at least
45 		 * two windows in the list.
46 		 */
47 		for (wp = win->nextp; wp->nextp != win; wp = wp->nextp)
48 			continue;
49 		wp->nextp = win->nextp;
50 	}
51 	free(win);
52 	return (OK);
53 }
54