Back to index

tetex-bin  3.0
lib_freeall.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Thomas E. Dickey <dickey@clark.net> 1996,1997                   *
00031  ****************************************************************************/
00032 
00033 #include <curses.priv.h>
00034 #include <term_entry.h>
00035 #include <tic.h>
00036 
00037 #if HAVE_NC_FREEALL
00038 
00039 #if HAVE_LIBDBMALLOC
00040 extern int malloc_errfd;    /* FIXME */
00041 #endif
00042 
00043 MODULE_ID("$Id: lib_freeall.c,v 1.29 2004/05/16 15:49:05 tom Exp $")
00044 
00045 /*
00046  * Free all ncurses data.  This is used for testing only (there's no practical
00047  * use for it as an extension).
00048  */
00049 NCURSES_EXPORT(void)
00050 _nc_freeall(void)
00051 {
00052     WINDOWLIST *p, *q;
00053     char *s;
00054 
00055     T((T_CALLED("_nc_freeall()")));
00056 #if NO_LEAKS
00057     _nc_free_tparm();
00058     FreeAndNull(_nc_oldnums);
00059 #endif
00060     if (SP != 0) {
00061        while (_nc_windows != 0) {
00062            /* Delete only windows that're not a parent */
00063            for (p = _nc_windows; p != 0; p = p->next) {
00064               bool found = FALSE;
00065 
00066               for (q = _nc_windows; q != 0; q = q->next) {
00067                   if ((p != q)
00068                      && (q->win._flags & _SUBWIN)
00069                      && (&(p->win) == q->win._parent)) {
00070                      found = TRUE;
00071                      break;
00072                   }
00073               }
00074 
00075               if (!found) {
00076                   delwin(&(p->win));
00077                   break;
00078               }
00079            }
00080        }
00081        delscreen(SP);
00082     }
00083 
00084     del_curterm(cur_term);
00085     _nc_free_entries(_nc_head);
00086     _nc_get_type(0);
00087     _nc_first_name(0);
00088 #if USE_WIDEC_SUPPORT
00089     FreeIfNeeded(_nc_wacs);
00090 #endif
00091 
00092     if ((s = _nc_home_terminfo()) != 0)
00093        free(s);
00094 
00095     (void) _nc_printf_string(0, 0);
00096 #ifdef TRACE
00097     (void) _nc_trace_buf(-1, 0);
00098 #endif
00099 
00100 #if HAVE_LIBDBMALLOC
00101     malloc_dump(malloc_errfd);
00102 #elif HAVE_LIBDMALLOC
00103 #elif HAVE_PURIFY
00104     purify_all_inuse();
00105 #endif
00106     returnVoid;
00107 }
00108 
00109 NCURSES_EXPORT(void)
00110 _nc_free_and_exit(int code)
00111 {
00112     char *last_setbuf = (SP != 0) ? SP->_setbuf : 0;
00113 
00114     _nc_freeall();
00115 #ifdef TRACE
00116     trace(0);               /* close trace file, freeing its setbuf */
00117     free(_nc_varargs("?", 0));
00118 #endif
00119     fclose(stdout);
00120     FreeIfNeeded(last_setbuf);
00121     exit(code);
00122 }
00123 
00124 #else
00125 NCURSES_EXPORT(void)
00126 _nc_freeall(void)
00127 {
00128 }
00129 #endif