blob: 5cb77b850dd77f33c1816a53a8c35b143b24dff2 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2018,2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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: *
12 * *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
15 * *
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. *
23 * *
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 *
27 * authorization. *
28 ****************************************************************************/
29
30/****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
Steve Kondikae271bc2015-11-15 02:50:53 +010033 * and: Thomas E. Dickey 1996-on *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053034 ****************************************************************************/
35
36#include <curses.priv.h>
37
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053038#include <tic.h>
39
micky3879b9f5e72025-07-08 18:04:53 -040040MODULE_ID("$Id: lib_ti.c,v 1.34 2020/02/02 23:34:34 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053041
Steve Kondikae271bc2015-11-15 02:50:53 +010042#if 0
43static bool
44same_name(const char *a, const char *b)
45{
46 fprintf(stderr, "compare(%s,%s)\n", a, b);
47 return !strcmp(a, b);
48}
49#else
50#define same_name(a,b) !strcmp(a,b)
51#endif
52
53NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -040054NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx const char *str)
Steve Kondikae271bc2015-11-15 02:50:53 +010055{
56 int result = ABSENT_BOOLEAN;
Steve Kondikae271bc2015-11-15 02:50:53 +010057
58 T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
59
60 if (HasTInfoTerminal(SP_PARM)) {
micky3879b9f5e72025-07-08 18:04:53 -040061 TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
Steve Kondikae271bc2015-11-15 02:50:53 +010062 struct name_table_entry const *entry_ptr;
micky3879b9f5e72025-07-08 18:04:53 -040063 int j = -1;
Steve Kondikae271bc2015-11-15 02:50:53 +010064
65 entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
66 if (entry_ptr != 0) {
67 j = entry_ptr->nte_index;
68 }
69#if NCURSES_XNAMES
70 else {
71 int i;
72 for_each_ext_boolean(i, tp) {
73 const char *capname = ExtBoolname(tp, i, boolnames);
74 if (same_name(str, capname)) {
75 j = i;
76 break;
77 }
78 }
79 }
80#endif
81 if (j >= 0) {
82 /* note: setupterm forces invalid booleans to false */
83 result = tp->Booleans[j];
84 }
85 }
86
87 returnCode(result);
88}
89
90#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053091NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -040092tigetflag(const char *str)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053093{
Steve Kondikae271bc2015-11-15 02:50:53 +010094 return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
95}
96#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097
Steve Kondikae271bc2015-11-15 02:50:53 +010098NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -040099NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx const char *str)
Steve Kondikae271bc2015-11-15 02:50:53 +0100100{
Steve Kondikae271bc2015-11-15 02:50:53 +0100101 int result = CANCELLED_NUMERIC; /* Solaris returns a -1 on error */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530102
Steve Kondikae271bc2015-11-15 02:50:53 +0100103 T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str));
104
105 if (HasTInfoTerminal(SP_PARM)) {
micky3879b9f5e72025-07-08 18:04:53 -0400106 TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
Steve Kondikae271bc2015-11-15 02:50:53 +0100107 struct name_table_entry const *entry_ptr;
micky3879b9f5e72025-07-08 18:04:53 -0400108 int j = -1;
Steve Kondikae271bc2015-11-15 02:50:53 +0100109
110 entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
111 if (entry_ptr != 0) {
112 j = entry_ptr->nte_index;
113 }
114#if NCURSES_XNAMES
115 else {
116 int i;
117 for_each_ext_number(i, tp) {
118 const char *capname = ExtNumname(tp, i, numnames);
119 if (same_name(str, capname)) {
120 j = i;
121 break;
122 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530123 }
124 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100125#endif
126 if (j >= 0) {
127 if (VALID_NUMERIC(tp->Numbers[j]))
128 result = tp->Numbers[j];
129 else
130 result = ABSENT_NUMERIC;
131 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530132 }
133
Steve Kondikae271bc2015-11-15 02:50:53 +0100134 returnCode(result);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530135}
136
Steve Kondikae271bc2015-11-15 02:50:53 +0100137#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530138NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -0400139tigetnum(const char *str)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530140{
Steve Kondikae271bc2015-11-15 02:50:53 +0100141 return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
142}
143#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530144
Steve Kondikae271bc2015-11-15 02:50:53 +0100145NCURSES_EXPORT(char *)
micky3879b9f5e72025-07-08 18:04:53 -0400146NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx const char *str)
Steve Kondikae271bc2015-11-15 02:50:53 +0100147{
148 char *result = CANCELLED_STRING;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530149
Steve Kondikae271bc2015-11-15 02:50:53 +0100150 T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
151
152 if (HasTInfoTerminal(SP_PARM)) {
micky3879b9f5e72025-07-08 18:04:53 -0400153 TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
Steve Kondikae271bc2015-11-15 02:50:53 +0100154 struct name_table_entry const *entry_ptr;
micky3879b9f5e72025-07-08 18:04:53 -0400155 int j = -1;
Steve Kondikae271bc2015-11-15 02:50:53 +0100156
157 entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
158 if (entry_ptr != 0) {
159 j = entry_ptr->nte_index;
160 }
161#if NCURSES_XNAMES
162 else {
163 int i;
164 for_each_ext_string(i, tp) {
165 const char *capname = ExtStrname(tp, i, strnames);
166 if (same_name(str, capname)) {
167 j = i;
168 break;
169 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530170 }
171 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100172#endif
173 if (j >= 0) {
174 /* note: setupterm forces cancelled strings to null */
175 result = tp->Strings[j];
176 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530177 }
178
Steve Kondikae271bc2015-11-15 02:50:53 +0100179 returnPtr(result);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530180}
181
Steve Kondikae271bc2015-11-15 02:50:53 +0100182#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530183NCURSES_EXPORT(char *)
micky3879b9f5e72025-07-08 18:04:53 -0400184tigetstr(const char *str)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530185{
Steve Kondikae271bc2015-11-15 02:50:53 +0100186 return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530187}
Steve Kondikae271bc2015-11-15 02:50:53 +0100188#endif