blob: e9ae74623cf50a2cb3082a4dc7758a93f697754b [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01002 * Copyright (c) 1998-2010,2013 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05303 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
Steve Kondikae271bc2015-11-15 02:50:53 +010032 * and: Thomas E. Dickey 1996-on *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053033 ****************************************************************************/
34
35#include <curses.priv.h>
36
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053037#include <tic.h>
38
Steve Kondikae271bc2015-11-15 02:50:53 +010039MODULE_ID("$Id: lib_ti.c,v 1.30 2013/06/08 16:55:05 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053040
Steve Kondikae271bc2015-11-15 02:50:53 +010041#if 0
42static bool
43same_name(const char *a, const char *b)
44{
45 fprintf(stderr, "compare(%s,%s)\n", a, b);
46 return !strcmp(a, b);
47}
48#else
49#define same_name(a,b) !strcmp(a,b)
50#endif
51
52NCURSES_EXPORT(int)
53NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
54{
55 int result = ABSENT_BOOLEAN;
56 int j = -1;
57
58 T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
59
60 if (HasTInfoTerminal(SP_PARM)) {
61 TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
62 struct name_table_entry const *entry_ptr;
63
64 entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
65 if (entry_ptr != 0) {
66 j = entry_ptr->nte_index;
67 }
68#if NCURSES_XNAMES
69 else {
70 int i;
71 for_each_ext_boolean(i, tp) {
72 const char *capname = ExtBoolname(tp, i, boolnames);
73 if (same_name(str, capname)) {
74 j = i;
75 break;
76 }
77 }
78 }
79#endif
80 if (j >= 0) {
81 /* note: setupterm forces invalid booleans to false */
82 result = tp->Booleans[j];
83 }
84 }
85
86 returnCode(result);
87}
88
89#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090NCURSES_EXPORT(int)
91tigetflag(NCURSES_CONST char *str)
92{
Steve Kondikae271bc2015-11-15 02:50:53 +010093 return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
94}
95#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053096
Steve Kondikae271bc2015-11-15 02:50:53 +010097NCURSES_EXPORT(int)
98NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
99{
100 int j = -1;
101 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)) {
106 TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
107 struct name_table_entry const *entry_ptr;
108
109 entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
110 if (entry_ptr != 0) {
111 j = entry_ptr->nte_index;
112 }
113#if NCURSES_XNAMES
114 else {
115 int i;
116 for_each_ext_number(i, tp) {
117 const char *capname = ExtNumname(tp, i, numnames);
118 if (same_name(str, capname)) {
119 j = i;
120 break;
121 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530122 }
123 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100124#endif
125 if (j >= 0) {
126 if (VALID_NUMERIC(tp->Numbers[j]))
127 result = tp->Numbers[j];
128 else
129 result = ABSENT_NUMERIC;
130 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530131 }
132
Steve Kondikae271bc2015-11-15 02:50:53 +0100133 returnCode(result);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530134}
135
Steve Kondikae271bc2015-11-15 02:50:53 +0100136#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530137NCURSES_EXPORT(int)
138tigetnum(NCURSES_CONST char *str)
139{
Steve Kondikae271bc2015-11-15 02:50:53 +0100140 return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
141}
142#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530143
Steve Kondikae271bc2015-11-15 02:50:53 +0100144NCURSES_EXPORT(char *)
145NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
146{
147 char *result = CANCELLED_STRING;
148 int j = -1;
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)) {
153 TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
154 struct name_table_entry const *entry_ptr;
155
156 entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
157 if (entry_ptr != 0) {
158 j = entry_ptr->nte_index;
159 }
160#if NCURSES_XNAMES
161 else {
162 int i;
163 for_each_ext_string(i, tp) {
164 const char *capname = ExtStrname(tp, i, strnames);
165 if (same_name(str, capname)) {
166 j = i;
167 break;
168 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530169 }
170 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100171#endif
172 if (j >= 0) {
173 /* note: setupterm forces cancelled strings to null */
174 result = tp->Strings[j];
175 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530176 }
177
Steve Kondikae271bc2015-11-15 02:50:53 +0100178 returnPtr(result);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530179}
180
Steve Kondikae271bc2015-11-15 02:50:53 +0100181#if NCURSES_SP_FUNCS
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530182NCURSES_EXPORT(char *)
183tigetstr(NCURSES_CONST char *str)
184{
Steve Kondikae271bc2015-11-15 02:50:53 +0100185 return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530186}
Steve Kondikae271bc2015-11-15 02:50:53 +0100187#endif