]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/free_ttype.c
ncurses 6.3 - patch 20220806
[ncurses.git] / ncurses / tinfo / free_ttype.c
1 /****************************************************************************
2  * Copyright 2020,2022 Thomas E. Dickey                                     *
3  * Copyright 1999-2011,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *  Author: Thomas E. Dickey                    1999-on                     *
32  ****************************************************************************/
33
34 /*
35  * free_ttype.c -- allocation functions for TERMTYPE
36  *
37  *      _nc_free_termtype()
38  *      use_extended_names()
39  *
40  */
41
42 #include <curses.priv.h>
43
44 #include <tic.h>
45
46 MODULE_ID("$Id: free_ttype.c,v 1.21 2022/05/28 18:02:33 tom Exp $")
47
48 static void
49 really_free_termtype(TERMTYPE2 *ptr, bool freeStrings)
50 {
51     T(("really_free_termtype(%s) %d", ptr->term_names, freeStrings));
52
53     if (freeStrings) {
54         FreeIfNeeded(ptr->str_table);
55     }
56     FreeIfNeeded(ptr->Booleans);
57     FreeIfNeeded(ptr->Numbers);
58     FreeIfNeeded(ptr->Strings);
59 #if NCURSES_XNAMES
60     if (freeStrings) {
61         FreeIfNeeded(ptr->ext_str_table);
62     }
63     FreeIfNeeded(ptr->ext_Names);
64 #endif
65     memset(ptr, 0, sizeof(TERMTYPE));
66     _nc_free_entry(_nc_head, ptr);
67 }
68
69 /*
70  * This entrypoint was used by tack 1.07; deprecated with ncurses 6.2
71  */
72 NCURSES_EXPORT(void)
73 _nc_free_termtype(TERMTYPE *ptr)
74 {
75     really_free_termtype((TERMTYPE2 *) ptr, !NCURSES_EXT_NUMBERS);
76 }
77
78 /*
79  * These similar entrypoints are not used outside of ncurses.
80  */
81 NCURSES_EXPORT(void)
82 _nc_free_termtype1(TERMTYPE *ptr)
83 {
84     really_free_termtype((TERMTYPE2 *) ptr, TRUE);
85 }
86
87 #if NCURSES_EXT_NUMBERS
88 NCURSES_EXPORT(void)
89 _nc_free_termtype2(TERMTYPE2 *ptr)
90 {
91     really_free_termtype(ptr, TRUE);
92 }
93 #endif
94
95 #if NCURSES_XNAMES
96 NCURSES_EXPORT_VAR(bool) _nc_user_definable = TRUE;
97
98 NCURSES_EXPORT(int)
99 use_extended_names(bool flag)
100 {
101     int oldflag = _nc_user_definable;
102
103     START_TRACE();
104     T((T_CALLED("use_extended_names(%d)"), flag));
105     _nc_user_definable = flag;
106     returnBool(oldflag);
107 }
108 #endif