]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/entries.c
ncurses 5.7 - patch 20091114
[ncurses.git] / ncurses / tinfo / entries.c
1 /****************************************************************************
2  * Copyright (c) 2006-2008,2009 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  *     and: Juergen Pfeifer                                                 *
32  ****************************************************************************/
33
34 #include <curses.priv.h>
35
36 #include <ctype.h>
37
38 #include <tic.h>
39 #include <term_entry.h>
40
41 MODULE_ID("$Id: entries.c,v 1.16 2009/09/27 14:45:02 tom Exp $")
42
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
64 NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0;
65 NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0;
66
67 NCURSES_EXPORT(void)
68 _nc_free_entry(ENTRY * headp, TERMTYPE *tterm)
69 /* free the allocated storage consumed by the given list entry */
70 {
71     ENTRY *ep;
72
73     if ((ep = _nc_delink_entry(headp, tterm)) != 0) {
74         free(ep);
75     }
76 }
77
78 NCURSES_EXPORT(void)
79 _nc_free_entries(ENTRY * headp)
80 /* free the allocated storage consumed by list entries */
81 {
82     (void) headp;               /* unused - _nc_head is altered here! */
83
84     while (_nc_head != 0) {
85         _nc_free_termtype(&(_nc_head->tterm));
86     }
87 }
88
89 NCURSES_EXPORT(ENTRY *)
90 _nc_delink_entry(ENTRY * headp, TERMTYPE *tterm)
91 /* delink the allocated storage for the given list entry */
92 {
93     ENTRY *ep, *last;
94
95     for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) {
96         if (&(ep->tterm) == tterm) {
97             if (last != 0) {
98                 last->next = ep->next;
99             }
100             if (ep == _nc_head) {
101                 _nc_head = ep->next;
102             }
103             if (ep == _nc_tail) {
104                 _nc_tail = last;
105             }
106             break;
107         }
108     }
109     return ep;
110 }
111
112 NCURSES_EXPORT(void)
113 _nc_leaks_tinfo(void)
114 {
115 #if NO_LEAKS
116     char *s;
117 #endif
118
119     T((T_CALLED("_nc_free_tinfo()")));
120 #if NO_LEAKS
121     _nc_free_tparm();
122     _nc_tgetent_leaks();
123
124     if (TerminalOf(CURRENT_SCREEN) != 0) {
125         del_curterm(TerminalOf(CURRENT_SCREEN));
126     }
127
128     _nc_comp_captab_leaks();
129     _nc_free_entries(_nc_head);
130     _nc_get_type(0);
131     _nc_first_name(0);
132     _nc_keyname_leaks();
133 #if BROKEN_LINKER || USE_REENTRANT
134     _nc_names_leaks();
135     _nc_codes_leaks();
136     FreeIfNeeded(_nc_prescreen.real_acs_map);
137 #endif
138
139     if ((s = _nc_home_terminfo()) != 0)
140         free(s);
141
142 #ifdef TRACE
143     trace(0);
144     _nc_trace_buf(-1, 0);
145 #endif
146
147 #endif /* NO_LEAKS */
148     returnVoid;
149 }
150
151 #if NO_LEAKS
152 NCURSES_EXPORT(void)
153 _nc_free_tinfo(int code)
154 {
155     _nc_leaks_tinfo();
156     exit(code);
157 }
158 #endif