1174993Srafan/**************************************************************************** 2184989Srafan * Copyright (c) 2006-2007,2008 Free Software Foundation, Inc. * 3174993Srafan * * 4174993Srafan * Permission is hereby granted, free of charge, to any person obtaining a * 5174993Srafan * copy of this software and associated documentation files (the * 6174993Srafan * "Software"), to deal in the Software without restriction, including * 7174993Srafan * without limitation the rights to use, copy, modify, merge, publish, * 8174993Srafan * distribute, distribute with modifications, sublicense, and/or sell * 9174993Srafan * copies of the Software, and to permit persons to whom the Software is * 10174993Srafan * furnished to do so, subject to the following conditions: * 11174993Srafan * * 12174993Srafan * The above copyright notice and this permission notice shall be included * 13174993Srafan * in all copies or substantial portions of the Software. * 14174993Srafan * * 15174993Srafan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16174993Srafan * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17174993Srafan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18174993Srafan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19174993Srafan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20174993Srafan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21174993Srafan * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22174993Srafan * * 23174993Srafan * Except as contained in this notice, the name(s) of the above copyright * 24174993Srafan * holders shall not be used in advertising or otherwise to promote the * 25174993Srafan * sale, use or other dealings in this Software without prior written * 26174993Srafan * authorization. * 27174993Srafan ****************************************************************************/ 28174993Srafan 29174993Srafan/**************************************************************************** 30174993Srafan * Author: Thomas E. Dickey * 31174993Srafan ****************************************************************************/ 32174993Srafan 33174993Srafan#include <curses.priv.h> 34174993Srafan 35174993Srafan#include <ctype.h> 36174993Srafan 37174993Srafan#include <tic.h> 38174993Srafan#include <term_entry.h> 39174993Srafan 40184989SrafanMODULE_ID("$Id: entries.c,v 1.8 2008/09/27 13:11:10 tom Exp $") 41174993Srafan 42174993Srafan/**************************************************************************** 43174993Srafan * 44174993Srafan * Entry queue handling 45174993Srafan * 46174993Srafan ****************************************************************************/ 47174993Srafan/* 48174993Srafan * The entry list is a doubly linked list with NULLs terminating the lists: 49174993Srafan * 50174993Srafan * --------- --------- --------- 51174993Srafan * | | | | | | offset 52174993Srafan * |-------| |-------| |-------| 53174993Srafan * | ----+-->| ----+-->| NULL | next 54174993Srafan * |-------| |-------| |-------| 55174993Srafan * | NULL |<--+---- |<--+---- | last 56174993Srafan * --------- --------- --------- 57174993Srafan * ^ ^ 58174993Srafan * | | 59174993Srafan * | | 60174993Srafan * _nc_head _nc_tail 61174993Srafan */ 62174993Srafan 63174993SrafanNCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0; 64174993SrafanNCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0; 65174993Srafan 66174993SrafanNCURSES_EXPORT(void) 67174993Srafan_nc_free_entry(ENTRY * headp, TERMTYPE *tterm) 68174993Srafan/* free the allocated storage consumed by the given list entry */ 69174993Srafan{ 70174993Srafan ENTRY *ep; 71174993Srafan 72174993Srafan if ((ep = _nc_delink_entry(headp, tterm)) != 0) { 73174993Srafan free(ep); 74174993Srafan } 75174993Srafan} 76174993Srafan 77174993SrafanNCURSES_EXPORT(void) 78174993Srafan_nc_free_entries(ENTRY * headp) 79174993Srafan/* free the allocated storage consumed by list entries */ 80174993Srafan{ 81174993Srafan (void) headp; /* unused - _nc_head is altered here! */ 82174993Srafan 83174993Srafan while (_nc_head != 0) { 84174993Srafan _nc_free_termtype(&(_nc_head->tterm)); 85174993Srafan } 86174993Srafan} 87174993Srafan 88174993SrafanNCURSES_EXPORT(ENTRY *) 89174993Srafan_nc_delink_entry(ENTRY * headp, TERMTYPE *tterm) 90174993Srafan/* delink the allocated storage for the given list entry */ 91174993Srafan{ 92174993Srafan ENTRY *ep, *last; 93174993Srafan 94174993Srafan for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) { 95174993Srafan if (&(ep->tterm) == tterm) { 96174993Srafan if (last != 0) { 97174993Srafan last->next = ep->next; 98174993Srafan } 99174993Srafan if (ep == _nc_head) { 100174993Srafan _nc_head = ep->next; 101174993Srafan } 102174993Srafan if (ep == _nc_tail) { 103174993Srafan _nc_tail = last; 104174993Srafan } 105174993Srafan break; 106174993Srafan } 107174993Srafan } 108174993Srafan return ep; 109174993Srafan} 110174993Srafan 111174993SrafanNCURSES_EXPORT(void) 112174993Srafan_nc_leaks_tinfo(void) 113174993Srafan{ 114184989Srafan#if NO_LEAKS 115174993Srafan char *s; 116184989Srafan#endif 117174993Srafan 118174993Srafan T((T_CALLED("_nc_free_tinfo()"))); 119174993Srafan#if NO_LEAKS 120174993Srafan _nc_free_tparm(); 121174993Srafan _nc_tgetent_leaks(); 122174993Srafan _nc_free_entries(_nc_head); 123174993Srafan _nc_get_type(0); 124174993Srafan _nc_first_name(0); 125174993Srafan _nc_keyname_leaks(); 126174993Srafan#if BROKEN_LINKER || USE_REENTRANT 127174993Srafan _nc_names_leaks(); 128174993Srafan _nc_codes_leaks(); 129184989Srafan FreeIfNeeded(_nc_prescreen.real_acs_map); 130174993Srafan#endif 131174993Srafan 132174993Srafan if ((s = _nc_home_terminfo()) != 0) 133174993Srafan free(s); 134184989Srafan#endif /* NO_LEAKS */ 135174993Srafan returnVoid; 136174993Srafan} 137174993Srafan 138174993Srafan#if NO_LEAKS 139174993SrafanNCURSES_EXPORT(void) 140174993Srafan_nc_free_tinfo(int code) 141174993Srafan{ 142174993Srafan _nc_leaks_tinfo(); 143174993Srafan exit(code); 144174993Srafan} 145174993Srafan#endif 146