Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 2 | * Copyright (c) 1998-2012,2015 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 3 | * * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a * |
| 5 | * copy of this software and associated documentation files (the * |
| 6 | * "Software"), to deal in the Software without restriction, including * |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, * |
| 8 | * distribute, distribute with modifications, sublicense, and/or sell * |
| 9 | * copies of the Software, and to permit persons to whom the Software is * |
| 10 | * furnished to do so, subject to the following conditions: * |
| 11 | * * |
| 12 | * The above copyright notice and this permission notice shall be included * |
| 13 | * in all copies or substantial portions of the Software. * |
| 14 | * * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 18 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 21 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 22 | * * |
| 23 | * Except as contained in this notice, the name(s) of the above copyright * |
| 24 | * holders shall not be used in advertising or otherwise to promote the * |
| 25 | * sale, use or other dealings in this Software without prior written * |
| 26 | * authorization. * |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | /**************************************************************************** |
| 30 | * Author: Thomas E. Dickey 1996-on * |
| 31 | ****************************************************************************/ |
| 32 | |
| 33 | #include <curses.priv.h> |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 34 | #include <tic.h> |
| 35 | |
| 36 | #if HAVE_NC_FREEALL |
| 37 | |
| 38 | #if HAVE_LIBDBMALLOC |
| 39 | extern int malloc_errfd; /* FIXME */ |
| 40 | #endif |
| 41 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 42 | MODULE_ID("$Id: lib_freeall.c,v 1.63 2015/05/02 23:46:26 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Free all ncurses data. This is used for testing only (there's no practical |
| 46 | * use for it as an extension). |
| 47 | */ |
| 48 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 49 | NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 50 | { |
| 51 | WINDOWLIST *p, *q; |
| 52 | static va_list empty_va; |
| 53 | |
| 54 | T((T_CALLED("_nc_freeall()"))); |
| 55 | #if NO_LEAKS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 56 | if (SP_PARM != 0) { |
| 57 | if (SP_PARM->_oldnum_list != 0) { |
| 58 | FreeAndNull(SP_PARM->_oldnum_list); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 59 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 60 | if (SP_PARM->_panelHook.destroy != 0) { |
| 61 | SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 65 | if (SP_PARM != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 66 | _nc_lock_global(curses); |
| 67 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 68 | while (WindowList(SP_PARM) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 69 | bool deleted = FALSE; |
| 70 | |
| 71 | /* Delete only windows that're not a parent */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 72 | for (each_window(SP_PARM, p)) { |
| 73 | WINDOW *p_win = &(p->win); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 74 | bool found = FALSE; |
| 75 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 76 | for (each_window(SP_PARM, q)) { |
| 77 | WINDOW *q_win = &(q->win); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 78 | if ((p != q) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 79 | && (q_win->_flags & _SUBWIN) |
| 80 | && (p_win == q_win->_parent)) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 81 | found = TRUE; |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (!found) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 87 | if (delwin(p_win) != ERR) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 88 | deleted = TRUE; |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Don't continue to loop if the list is trashed. |
| 95 | */ |
| 96 | if (!deleted) |
| 97 | break; |
| 98 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 99 | delscreen(SP_PARM); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 100 | _nc_unlock_global(curses); |
| 101 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 102 | |
| 103 | (void) _nc_printf_string(0, empty_va); |
| 104 | #ifdef TRACE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 105 | (void) _nc_trace_buf(-1, (size_t) 0); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 106 | #endif |
| 107 | #if USE_WIDEC_SUPPORT |
| 108 | FreeIfNeeded(_nc_wacs); |
| 109 | #endif |
| 110 | _nc_leaks_tinfo(); |
| 111 | |
| 112 | #if HAVE_LIBDBMALLOC |
| 113 | malloc_dump(malloc_errfd); |
| 114 | #elif HAVE_LIBDMALLOC |
| 115 | #elif HAVE_LIBMPATROL |
| 116 | __mp_summary(); |
| 117 | #elif HAVE_PURIFY |
| 118 | purify_all_inuse(); |
| 119 | #endif |
| 120 | returnVoid; |
| 121 | } |
| 122 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 123 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 124 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 125 | _nc_freeall(void) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 126 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 127 | NCURSES_SP_NAME(_nc_freeall) (CURRENT_SCREEN); |
| 128 | } |
| 129 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 130 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 131 | NCURSES_EXPORT(void) |
| 132 | NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code) |
| 133 | { |
| 134 | NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG); |
| 135 | NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_ARG); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 136 | #ifdef TRACE |
| 137 | trace(0); /* close trace file, freeing its setbuf */ |
| 138 | { |
| 139 | static va_list fake; |
| 140 | free(_nc_varargs("?", fake)); |
| 141 | } |
| 142 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 143 | exit(code); |
| 144 | } |
| 145 | |
| 146 | #else |
| 147 | NCURSES_EXPORT(void) |
| 148 | _nc_freeall(void) |
| 149 | { |
| 150 | } |
| 151 | |
| 152 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 153 | NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code) |
| 154 | { |
| 155 | if (SP_PARM) { |
| 156 | delscreen(SP_PARM); |
| 157 | if (SP_PARM->_term) |
| 158 | NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx SP_PARM->_term); |
| 159 | } |
| 160 | exit(code); |
| 161 | } |
| 162 | #endif |
| 163 | |
| 164 | #if NCURSES_SP_FUNCS |
| 165 | NCURSES_EXPORT(void) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 166 | _nc_free_and_exit(int code) |
| 167 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 168 | NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 169 | } |
| 170 | #endif |