xref: /original-bsd/lib/libcurses/delwin.c (revision be1f24e8)
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.7 (Berkeley) 09/14/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 LINE *lp;
26 	register int i;
27 
28 	if (win->orig == NULL) {
29 		/*
30 		 * If we are the original window, delete the space for all
31 		 * the subwindows, and the array of space as well which is
32 		 * pointed to by win->topline->line.
33 		 */
34 
35 		for (lp = win->topline, i = 0; i < win->maxy; i++)
36 			free(lp);
37 		free(win->wspace);
38 		free(win->lines);
39 		wp = win->nextp;
40 		while (wp != win) {
41 			np = wp->nextp;
42 			delwin(wp);
43 			wp = np;
44 		}
45 	} else {
46 		/*
47 		 * If we are a subwindow, take ourselves out of the list.
48 		 * NOTE: if we are a subwindow, the minimum list is orig
49 		 * followed by this subwindow, so there are always at least
50 		 * two windows in the list.
51 		 */
52 		for (wp = win->nextp; wp->nextp != win; wp = wp->nextp)
53 			continue;
54 		wp->nextp = win->nextp;
55 	}
56 	free(win);
57 	return (OK);
58 }
59