1 /* $OpenBSD: entries.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 2006-2007,2008 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Thomas E. Dickey * 33 ****************************************************************************/ 34 35 #include <curses.priv.h> 36 37 #include <ctype.h> 38 39 #include <tic.h> 40 #include <term_entry.h> 41 42 MODULE_ID("$Id: entries.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") 43 44 /**************************************************************************** 45 * 46 * Entry queue handling 47 * 48 ****************************************************************************/ 49 /* 50 * The entry list is a doubly linked list with NULLs terminating the lists: 51 * 52 * --------- --------- --------- 53 * | | | | | | offset 54 * |-------| |-------| |-------| 55 * | ----+-->| ----+-->| NULL | next 56 * |-------| |-------| |-------| 57 * | NULL |<--+---- |<--+---- | last 58 * --------- --------- --------- 59 * ^ ^ 60 * | | 61 * | | 62 * _nc_head _nc_tail 63 */ 64 65 NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0; 66 NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0; 67 68 NCURSES_EXPORT(void) 69 _nc_free_entry(ENTRY * headp, TERMTYPE *tterm) 70 /* free the allocated storage consumed by the given list entry */ 71 { 72 ENTRY *ep; 73 74 if ((ep = _nc_delink_entry(headp, tterm)) != 0) { 75 free(ep); 76 } 77 } 78 79 NCURSES_EXPORT(void) 80 _nc_free_entries(ENTRY * headp) 81 /* free the allocated storage consumed by list entries */ 82 { 83 (void) headp; /* unused - _nc_head is altered here! */ 84 85 while (_nc_head != 0) { 86 _nc_free_termtype(&(_nc_head->tterm)); 87 } 88 } 89 90 NCURSES_EXPORT(ENTRY *) 91 _nc_delink_entry(ENTRY * headp, TERMTYPE *tterm) 92 /* delink the allocated storage for the given list entry */ 93 { 94 ENTRY *ep, *last; 95 96 for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) { 97 if (&(ep->tterm) == tterm) { 98 if (last != 0) { 99 last->next = ep->next; 100 } 101 if (ep == _nc_head) { 102 _nc_head = ep->next; 103 } 104 if (ep == _nc_tail) { 105 _nc_tail = last; 106 } 107 break; 108 } 109 } 110 return ep; 111 } 112 113 NCURSES_EXPORT(void) 114 _nc_leaks_tinfo(void) 115 { 116 #if NO_LEAKS 117 char *s; 118 #endif 119 120 T((T_CALLED("_nc_free_tinfo()"))); 121 #if NO_LEAKS 122 _nc_free_tparm(); 123 _nc_tgetent_leaks(); 124 _nc_free_entries(_nc_head); 125 _nc_get_type(0); 126 _nc_first_name(0); 127 _nc_keyname_leaks(); 128 #if BROKEN_LINKER || USE_REENTRANT 129 _nc_names_leaks(); 130 _nc_codes_leaks(); 131 FreeIfNeeded(_nc_prescreen.real_acs_map); 132 #endif 133 134 if ((s = _nc_home_terminfo()) != 0) 135 free(s); 136 #endif /* NO_LEAKS */ 137 returnVoid; 138 } 139 140 #if NO_LEAKS 141 NCURSES_EXPORT(void) 142 _nc_free_tinfo(int code) 143 { 144 _nc_leaks_tinfo(); 145 exit(code); 146 } 147 #endif 148