blob: cf2a8337b870ce931f67d670ed6259086fccd522 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
2 * Copyright (c) 2006-2007,2008 Free Software Foundation, Inc. *
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 *
31 ****************************************************************************/
32
33#include <curses.priv.h>
34
35#include <ctype.h>
36
37#include <tic.h>
38#include <term_entry.h>
39
40MODULE_ID("$Id: entries.c,v 1.8 2008/09/27 13:11:10 tom Exp $")
41
42/****************************************************************************
43 *
44 * Entry queue handling
45 *
46 ****************************************************************************/
47/*
48 * The entry list is a doubly linked list with NULLs terminating the lists:
49 *
50 * --------- --------- ---------
51 * | | | | | | offset
52 * |-------| |-------| |-------|
53 * | ----+-->| ----+-->| NULL | next
54 * |-------| |-------| |-------|
55 * | NULL |<--+---- |<--+---- | last
56 * --------- --------- ---------
57 * ^ ^
58 * | |
59 * | |
60 * _nc_head _nc_tail
61 */
62
63NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0;
64NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0;
65
66NCURSES_EXPORT(void)
67_nc_free_entry(ENTRY * headp, TERMTYPE *tterm)
68/* free the allocated storage consumed by the given list entry */
69{
70 ENTRY *ep;
71
72 if ((ep = _nc_delink_entry(headp, tterm)) != 0) {
73 free(ep);
74 }
75}
76
77NCURSES_EXPORT(void)
78_nc_free_entries(ENTRY * headp)
79/* free the allocated storage consumed by list entries */
80{
81 (void) headp; /* unused - _nc_head is altered here! */
82
83 while (_nc_head != 0) {
84 _nc_free_termtype(&(_nc_head->tterm));
85 }
86}
87
88NCURSES_EXPORT(ENTRY *)
89_nc_delink_entry(ENTRY * headp, TERMTYPE *tterm)
90/* delink the allocated storage for the given list entry */
91{
92 ENTRY *ep, *last;
93
94 for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) {
95 if (&(ep->tterm) == tterm) {
96 if (last != 0) {
97 last->next = ep->next;
98 }
99 if (ep == _nc_head) {
100 _nc_head = ep->next;
101 }
102 if (ep == _nc_tail) {
103 _nc_tail = last;
104 }
105 break;
106 }
107 }
108 return ep;
109}
110
111NCURSES_EXPORT(void)
112_nc_leaks_tinfo(void)
113{
114#if NO_LEAKS
115 char *s;
116#endif
117
118 T((T_CALLED("_nc_free_tinfo()")));
119#if NO_LEAKS
120 _nc_free_tparm();
121 _nc_tgetent_leaks();
122 _nc_free_entries(_nc_head);
123 _nc_get_type(0);
124 _nc_first_name(0);
125 _nc_keyname_leaks();
126#if BROKEN_LINKER || USE_REENTRANT
127 _nc_names_leaks();
128 _nc_codes_leaks();
129 FreeIfNeeded(_nc_prescreen.real_acs_map);
130#endif
131
132 if ((s = _nc_home_terminfo()) != 0)
133 free(s);
134#endif /* NO_LEAKS */
135 returnVoid;
136}
137
138#if NO_LEAKS
139NCURSES_EXPORT(void)
140_nc_free_tinfo(int code)
141{
142 _nc_leaks_tinfo();
143 exit(code);
144}
145#endif