xref: /original-bsd/lib/libcurses/delwin.c (revision a810125e)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)delwin.c	5.8 (Berkeley) 10/26/92";
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 	register int i;
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