blob: f47fd3fe9eff7d6ef0a4e7b84256374310bf8b54 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2019-2022,2023 Thomas E. Dickey *
3 * Copyright 2006-2012,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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 *
Steve Kondikae271bc2015-11-15 02:50:53 +010032 * and: Juergen Pfeifer *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053033 ****************************************************************************/
34
35#include <curses.priv.h>
36
37#include <ctype.h>
38
39#include <tic.h>
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053040
micky3879b9f5e72025-07-08 18:04:53 -040041MODULE_ID("$Id: entries.c,v 1.35 2023/05/27 20:13:10 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042
43/****************************************************************************
44 *
45 * Entry queue handling
46 *
47 ****************************************************************************/
48/*
49 * The entry list is a doubly linked list with NULLs terminating the lists:
50 *
51 * --------- --------- ---------
52 * | | | | | | offset
53 * |-------| |-------| |-------|
54 * | ----+-->| ----+-->| NULL | next
55 * |-------| |-------| |-------|
56 * | NULL |<--+---- |<--+---- | last
57 * --------- --------- ---------
58 * ^ ^
59 * | |
60 * | |
61 * _nc_head _nc_tail
62 */
63
64NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0;
65NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0;
66
micky3879b9f5e72025-07-08 18:04:53 -040067static ENTRY *
68_nc_delink_entry(ENTRY * headp, const TERMTYPE2 *const tterm)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053069/* delink the allocated storage for the given list entry */
70{
71 ENTRY *ep, *last;
72
73 for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) {
74 if (&(ep->tterm) == tterm) {
75 if (last != 0) {
76 last->next = ep->next;
77 }
Steve Kondikae271bc2015-11-15 02:50:53 +010078 if (ep->next != 0) {
79 ep->next->last = last;
80 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053081 if (ep == _nc_head) {
82 _nc_head = ep->next;
83 }
84 if (ep == _nc_tail) {
85 _nc_tail = last;
86 }
87 break;
88 }
89 }
90 return ep;
91}
92
93NCURSES_EXPORT(void)
micky3879b9f5e72025-07-08 18:04:53 -040094_nc_free_entry(ENTRY * headp, TERMTYPE2 *tterm)
95/* free the allocated storage consumed by the given list entry */
96{
97 ENTRY *ep;
98
99 if ((ep = _nc_delink_entry(headp, tterm)) != 0) {
100 free(ep);
101 }
102}
103
104NCURSES_EXPORT(void)
105_nc_free_entries(ENTRY * headp)
106/* free the allocated storage consumed by list entries */
107{
108 (void) headp; /* unused - _nc_head is altered here! */
109
110 while (_nc_head != 0) {
111 _nc_free_termtype2(&(_nc_head->tterm));
112 }
113}
114
115NCURSES_EXPORT(void)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530116_nc_leaks_tinfo(void)
117{
118#if NO_LEAKS
119 char *s;
120#endif
121
micky3879b9f5e72025-07-08 18:04:53 -0400122 T((T_CALLED("_nc_leaks_tinfo()")));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530123#if NO_LEAKS
micky3879b9f5e72025-07-08 18:04:53 -0400124 _nc_globals.leak_checking = TRUE;
125 _nc_free_tparm(cur_term);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530126 _nc_tgetent_leaks();
Steve Kondikae271bc2015-11-15 02:50:53 +0100127
micky3879b9f5e72025-07-08 18:04:53 -0400128#ifdef USE_PTHREADS
129 /*
130 * Discard any prescreen data which is not used for the current screen.
131 */
132 _nc_lock_global(screen);
133 {
134 PRESCREEN_LIST *p;
135 pthread_t id = GetThreadID();
136 for (p = _nc_prescreen.allocated; p != 0; p = p->next) {
137 if (p->id == id && p->sp != CURRENT_SCREEN) {
138 FreeAndNull(p->sp);
139 }
140 }
141 }
142 _nc_unlock_global(screen);
143#endif
Steve Kondikae271bc2015-11-15 02:50:53 +0100144 if (TerminalOf(CURRENT_SCREEN) != 0) {
145 del_curterm(TerminalOf(CURRENT_SCREEN));
146 }
micky3879b9f5e72025-07-08 18:04:53 -0400147 _nc_forget_prescr();
Steve Kondikae271bc2015-11-15 02:50:53 +0100148
149 _nc_comp_captab_leaks();
micky3879b9f5e72025-07-08 18:04:53 -0400150 _nc_comp_userdefs_leaks();
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530151 _nc_free_entries(_nc_head);
152 _nc_get_type(0);
153 _nc_first_name(0);
Steve Kondikae271bc2015-11-15 02:50:53 +0100154 _nc_db_iterator_leaks();
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530155 _nc_keyname_leaks();
156#if BROKEN_LINKER || USE_REENTRANT
157 _nc_names_leaks();
158 _nc_codes_leaks();
159 FreeIfNeeded(_nc_prescreen.real_acs_map);
160#endif
Steve Kondikae271bc2015-11-15 02:50:53 +0100161 _nc_comp_error_leaks();
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530162
163 if ((s = _nc_home_terminfo()) != 0)
164 free(s);
Steve Kondikae271bc2015-11-15 02:50:53 +0100165
166#ifdef TRACE
micky3879b9f5e72025-07-08 18:04:53 -0400167 T((T_RETURN("")));
168 curses_trace(0);
Steve Kondikae271bc2015-11-15 02:50:53 +0100169 _nc_trace_buf(-1, (size_t) 0);
170#endif
171
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530172#endif /* NO_LEAKS */
173 returnVoid;
174}
175
176#if NO_LEAKS
177NCURSES_EXPORT(void)
178_nc_free_tinfo(int code)
179{
micky3879b9f5e72025-07-08 18:04:53 -0400180 T((T_CALLED("_nc_free_tinfo(%d)"), code));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530181 _nc_leaks_tinfo();
182 exit(code);
183}
184#endif
micky3879b9f5e72025-07-08 18:04:53 -0400185
186NCURSES_EXPORT(void)
187exit_terminfo(int code)
188{
189 T((T_CALLED("exit_terminfo(%d)"), code));
190#if NO_LEAKS
191 _nc_leaks_tinfo();
192#endif
193 exit(code);
194}