10e3d5408SPeter Wemm /**************************************************************************** 2*06bfebdeSXin LI * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * 30e3d5408SPeter Wemm * * 40e3d5408SPeter Wemm * Permission is hereby granted, free of charge, to any person obtaining a * 50e3d5408SPeter Wemm * copy of this software and associated documentation files (the * 60e3d5408SPeter Wemm * "Software"), to deal in the Software without restriction, including * 70e3d5408SPeter Wemm * without limitation the rights to use, copy, modify, merge, publish, * 80e3d5408SPeter Wemm * distribute, distribute with modifications, sublicense, and/or sell * 90e3d5408SPeter Wemm * copies of the Software, and to permit persons to whom the Software is * 100e3d5408SPeter Wemm * furnished to do so, subject to the following conditions: * 110e3d5408SPeter Wemm * * 120e3d5408SPeter Wemm * The above copyright notice and this permission notice shall be included * 130e3d5408SPeter Wemm * in all copies or substantial portions of the Software. * 140e3d5408SPeter Wemm * * 150e3d5408SPeter Wemm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 160e3d5408SPeter Wemm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 170e3d5408SPeter Wemm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 180e3d5408SPeter Wemm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 190e3d5408SPeter Wemm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 200e3d5408SPeter Wemm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 210e3d5408SPeter Wemm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 220e3d5408SPeter Wemm * * 230e3d5408SPeter Wemm * Except as contained in this notice, the name(s) of the above copyright * 240e3d5408SPeter Wemm * holders shall not be used in advertising or otherwise to promote the * 250e3d5408SPeter Wemm * sale, use or other dealings in this Software without prior written * 260e3d5408SPeter Wemm * authorization. * 270e3d5408SPeter Wemm ****************************************************************************/ 280e3d5408SPeter Wemm 290e3d5408SPeter Wemm /**************************************************************************** 300e3d5408SPeter Wemm * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 310e3d5408SPeter Wemm * and: Eric S. Raymond <esr@snark.thyrsus.com> * 32*06bfebdeSXin LI * and: Thomas E. Dickey 1996-on * 330e3d5408SPeter Wemm ****************************************************************************/ 340e3d5408SPeter Wemm 350e3d5408SPeter Wemm #include <curses.priv.h> 360e3d5408SPeter Wemm 370e3d5408SPeter Wemm #include <tic.h> 380e3d5408SPeter Wemm 39*06bfebdeSXin LI MODULE_ID("$Id: lib_ti.c,v 1.29 2010/01/23 17:57:43 tom Exp $") 400e3d5408SPeter Wemm 41*06bfebdeSXin LI #if 0 42*06bfebdeSXin LI static bool 43*06bfebdeSXin LI same_name(const char *a, const char *b) 44*06bfebdeSXin LI { 45*06bfebdeSXin LI fprintf(stderr, "compare(%s,%s)\n", a, b); 46*06bfebdeSXin LI return !strcmp(a, b); 47*06bfebdeSXin LI } 48*06bfebdeSXin LI #else 49*06bfebdeSXin LI #define same_name(a,b) !strcmp(a,b) 50*06bfebdeSXin LI #endif 51*06bfebdeSXin LI 52*06bfebdeSXin LI NCURSES_EXPORT(int) 53*06bfebdeSXin LI NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str) 54*06bfebdeSXin LI { 55*06bfebdeSXin LI int result = ABSENT_BOOLEAN; 56*06bfebdeSXin LI int i, j; 57*06bfebdeSXin LI 58*06bfebdeSXin LI T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str)); 59*06bfebdeSXin LI 60*06bfebdeSXin LI if (HasTInfoTerminal(SP_PARM)) { 61*06bfebdeSXin LI TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); 62*06bfebdeSXin LI struct name_table_entry const *entry_ptr; 63*06bfebdeSXin LI 64*06bfebdeSXin LI entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE); 65*06bfebdeSXin LI if (entry_ptr != 0) { 66*06bfebdeSXin LI j = entry_ptr->nte_index; 67*06bfebdeSXin LI } 68*06bfebdeSXin LI #if NCURSES_XNAMES 69*06bfebdeSXin LI else { 70*06bfebdeSXin LI j = -1; 71*06bfebdeSXin LI for_each_ext_boolean(i, tp) { 72*06bfebdeSXin LI const char *capname = ExtBoolname(tp, i, boolnames); 73*06bfebdeSXin LI if (same_name(str, capname)) { 74*06bfebdeSXin LI j = i; 75*06bfebdeSXin LI break; 76*06bfebdeSXin LI } 77*06bfebdeSXin LI } 78*06bfebdeSXin LI } 79*06bfebdeSXin LI #endif 80*06bfebdeSXin LI if (j >= 0) { 81*06bfebdeSXin LI /* note: setupterm forces invalid booleans to false */ 82*06bfebdeSXin LI result = tp->Booleans[j]; 83*06bfebdeSXin LI } 84*06bfebdeSXin LI } 85*06bfebdeSXin LI 86*06bfebdeSXin LI returnCode(result); 87*06bfebdeSXin LI } 88*06bfebdeSXin LI 89*06bfebdeSXin LI #if NCURSES_SP_FUNCS 907a69bbfbSPeter Wemm NCURSES_EXPORT(int) 9115589c42SPeter Wemm tigetflag(NCURSES_CONST char *str) 920e3d5408SPeter Wemm { 93*06bfebdeSXin LI return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str); 94*06bfebdeSXin LI } 95*06bfebdeSXin LI #endif 960e3d5408SPeter Wemm 97*06bfebdeSXin LI NCURSES_EXPORT(int) 98*06bfebdeSXin LI NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str) 99*06bfebdeSXin LI { 100*06bfebdeSXin LI int i, j; 101*06bfebdeSXin LI int result = CANCELLED_NUMERIC; /* Solaris returns a -1 on error */ 1020e3d5408SPeter Wemm 103*06bfebdeSXin LI T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str)); 104*06bfebdeSXin LI 105*06bfebdeSXin LI if (HasTInfoTerminal(SP_PARM)) { 106*06bfebdeSXin LI TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); 107*06bfebdeSXin LI struct name_table_entry const *entry_ptr; 108*06bfebdeSXin LI 109*06bfebdeSXin LI entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE); 110*06bfebdeSXin LI if (entry_ptr != 0) { 111*06bfebdeSXin LI j = entry_ptr->nte_index; 112*06bfebdeSXin LI } 113*06bfebdeSXin LI #if NCURSES_XNAMES 114*06bfebdeSXin LI else { 115*06bfebdeSXin LI j = -1; 116*06bfebdeSXin LI for_each_ext_number(i, tp) { 117*06bfebdeSXin LI const char *capname = ExtNumname(tp, i, numnames); 118*06bfebdeSXin LI if (same_name(str, capname)) { 119*06bfebdeSXin LI j = i; 120*06bfebdeSXin LI break; 1210e3d5408SPeter Wemm } 1220e3d5408SPeter Wemm } 1230e3d5408SPeter Wemm } 124*06bfebdeSXin LI #endif 125*06bfebdeSXin LI if (j >= 0) { 126*06bfebdeSXin LI if (VALID_NUMERIC(tp->Numbers[j])) 127*06bfebdeSXin LI result = tp->Numbers[j]; 128*06bfebdeSXin LI else 129*06bfebdeSXin LI result = ABSENT_NUMERIC; 130*06bfebdeSXin LI } 1310e3d5408SPeter Wemm } 1320e3d5408SPeter Wemm 133*06bfebdeSXin LI returnCode(result); 134*06bfebdeSXin LI } 135*06bfebdeSXin LI 136*06bfebdeSXin LI #if NCURSES_SP_FUNCS 1377a69bbfbSPeter Wemm NCURSES_EXPORT(int) 13815589c42SPeter Wemm tigetnum(NCURSES_CONST char *str) 1390e3d5408SPeter Wemm { 140*06bfebdeSXin LI return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str); 141*06bfebdeSXin LI } 142*06bfebdeSXin LI #endif 1430e3d5408SPeter Wemm 144*06bfebdeSXin LI NCURSES_EXPORT(char *) 145*06bfebdeSXin LI NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str) 146*06bfebdeSXin LI { 147*06bfebdeSXin LI char *result = CANCELLED_STRING; 148*06bfebdeSXin LI int i, j; 1490e3d5408SPeter Wemm 150*06bfebdeSXin LI T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str)); 151*06bfebdeSXin LI 152*06bfebdeSXin LI if (HasTInfoTerminal(SP_PARM)) { 153*06bfebdeSXin LI TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); 154*06bfebdeSXin LI struct name_table_entry const *entry_ptr; 155*06bfebdeSXin LI 156*06bfebdeSXin LI entry_ptr = _nc_find_type_entry(str, STRING, FALSE); 157*06bfebdeSXin LI if (entry_ptr != 0) { 158*06bfebdeSXin LI j = entry_ptr->nte_index; 159*06bfebdeSXin LI } 160*06bfebdeSXin LI #if NCURSES_XNAMES 161*06bfebdeSXin LI else { 162*06bfebdeSXin LI j = -1; 163*06bfebdeSXin LI for_each_ext_string(i, tp) { 164*06bfebdeSXin LI const char *capname = ExtStrname(tp, i, strnames); 165*06bfebdeSXin LI if (same_name(str, capname)) { 166*06bfebdeSXin LI j = i; 167*06bfebdeSXin LI break; 1680e3d5408SPeter Wemm } 1690e3d5408SPeter Wemm } 1700e3d5408SPeter Wemm } 171*06bfebdeSXin LI #endif 172*06bfebdeSXin LI if (j >= 0) { 173*06bfebdeSXin LI /* note: setupterm forces cancelled strings to null */ 174*06bfebdeSXin LI result = tp->Strings[j]; 175*06bfebdeSXin LI } 1760e3d5408SPeter Wemm } 1770e3d5408SPeter Wemm 178*06bfebdeSXin LI returnPtr(result); 179*06bfebdeSXin LI } 180*06bfebdeSXin LI 181*06bfebdeSXin LI #if NCURSES_SP_FUNCS 1827a69bbfbSPeter Wemm NCURSES_EXPORT(char *) 18315589c42SPeter Wemm tigetstr(NCURSES_CONST char *str) 1840e3d5408SPeter Wemm { 185*06bfebdeSXin LI return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str); 1860e3d5408SPeter Wemm } 187*06bfebdeSXin LI #endif 188