]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_ti.c
ncurses 5.7 - patch 20090711
[ncurses.git] / ncurses / tinfo / lib_ti.c
1 /****************************************************************************
2  * Copyright (c) 1998-2003,2009 Free Software Foundation, Inc.              *
3  *                                                                          *
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>                         *
32  *     and: Thomas E. Dickey                        1996-on                 *
33  ****************************************************************************/
34
35 #include <curses.priv.h>
36
37 #include <term_entry.h>
38 #include <tic.h>
39
40 MODULE_ID("$Id: lib_ti.c,v 1.26 2009/07/11 18:14:21 tom Exp $")
41
42 #if 0
43 static bool
44 same_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
53 NCURSES_EXPORT(int)
54 NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
55 {
56     int result = ABSENT_BOOLEAN;
57     int i, j;
58
59     T((T_CALLED("tigetflag(%p, %s)"), SP_PARM, str));
60
61     if (HasTInfoTerminal(SP_PARM)) {
62         TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
63         struct name_table_entry const *entry_ptr;
64
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             j = -1;
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
91 NCURSES_EXPORT(int)
92 tigetflag(NCURSES_CONST char *str)
93 {
94     return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
95 }
96 #endif
97
98 NCURSES_EXPORT(int)
99 NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
100 {
101     int i, j;
102     int result = CANCELLED_NUMERIC;     /* Solaris returns a -1 on error */
103
104     T((T_CALLED("tigetnum(%p, %s)"), SP_PARM, str));
105
106     if (HasTInfoTerminal(SP_PARM)) {
107         TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
108         struct name_table_entry const *entry_ptr;
109
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             j = -1;
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                 }
123             }
124         }
125 #endif
126         if (j >= 0 && VALID_NUMERIC(tp->Numbers[j]))
127             result = tp->Numbers[j];
128         else
129             result = ABSENT_NUMERIC;
130     }
131
132     returnCode(result);
133 }
134
135 #if NCURSES_SP_FUNCS
136 NCURSES_EXPORT(int)
137 tigetnum(NCURSES_CONST char *str)
138 {
139     return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
140 }
141 #endif
142
143 NCURSES_EXPORT(char *)
144 NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
145 {
146     char *result = CANCELLED_STRING;
147     int i, j;
148
149     T((T_CALLED("tigetstr(%p, %s)"), SP_PARM, str));
150
151     if (HasTInfoTerminal(SP_PARM)) {
152         TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
153         struct name_table_entry const *entry_ptr;
154
155         entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
156         if (entry_ptr != 0) {
157             j = entry_ptr->nte_index;
158         }
159 #if NCURSES_XNAMES
160         else {
161             j = -1;
162             for_each_ext_string(i, tp) {
163                 const char *capname = ExtStrname(tp, i, strnames);
164                 if (same_name(str, capname)) {
165                     j = i;
166                     break;
167                 }
168             }
169         }
170 #endif
171         if (j >= 0) {
172             /* note: setupterm forces cancelled strings to null */
173             result = tp->Strings[j];
174         }
175     }
176
177     returnPtr(result);
178 }
179
180 #if NCURSES_SP_FUNCS
181 NCURSES_EXPORT(char *)
182 tigetstr(NCURSES_CONST char *str)
183 {
184     return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
185 }
186 #endif