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