1 /****************************************************************************
2 * Copyright 2018,2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 ****************************************************************************/
36 #include <curses.priv.h>
40 MODULE_ID("$Id: lib_ti.c,v 1.34 2020/02/02 23:34:34 tom Exp $")
44 same_name(const char *a, const char *b)
46 fprintf(stderr, "compare(%s,%s)\n", a, b);
50 #define same_name(a,b) !strcmp(a,b)
54 NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx const char *str)
56 int result = ABSENT_BOOLEAN;
58 T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
60 if (HasTInfoTerminal(SP_PARM)) {
61 TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
62 struct name_table_entry const *entry_ptr;
65 entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
67 j = entry_ptr->nte_index;
72 for_each_ext_boolean(i, tp) {
73 const char *capname = ExtBoolname(tp, i, boolnames);
74 if (same_name(str, capname)) {
82 /* note: setupterm forces invalid booleans to false */
83 result = tp->Booleans[j];
92 tigetflag(const char *str)
94 return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
99 NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx const char *str)
101 int result = CANCELLED_NUMERIC; /* Solaris returns a -1 on error */
103 T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str));
105 if (HasTInfoTerminal(SP_PARM)) {
106 TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
107 struct name_table_entry const *entry_ptr;
110 entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
111 if (entry_ptr != 0) {
112 j = entry_ptr->nte_index;
117 for_each_ext_number(i, tp) {
118 const char *capname = ExtNumname(tp, i, numnames);
119 if (same_name(str, capname)) {
127 if (VALID_NUMERIC(tp->Numbers[j]))
128 result = tp->Numbers[j];
130 result = ABSENT_NUMERIC;
139 tigetnum(const char *str)
141 return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
145 NCURSES_EXPORT(char *)
146 NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx const char *str)
148 char *result = CANCELLED_STRING;
150 T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
152 if (HasTInfoTerminal(SP_PARM)) {
153 TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
154 struct name_table_entry const *entry_ptr;
157 entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
158 if (entry_ptr != 0) {
159 j = entry_ptr->nte_index;
164 for_each_ext_string(i, tp) {
165 const char *capname = ExtStrname(tp, i, strnames);
166 if (same_name(str, capname)) {
174 /* note: setupterm forces cancelled strings to null */
175 result = tp->Strings[j];
183 NCURSES_EXPORT(char *)
184 tigetstr(const char *str)
186 return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);