missing ncurses sources
[tomato.git] / release / src / router / libncurses / ncurses / tinfo / lib_ti.c
blobe41234210c85de5993eabf088d26896654e599e1
1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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 ****************************************************************************/
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 ****************************************************************************/
35 #include <curses.priv.h>
37 #include <tic.h>
39 MODULE_ID("$Id: lib_ti.c,v 1.29 2010/01/23 17:57:43 tom Exp $")
41 #if 0
42 static bool
43 same_name(const char *a, const char *b)
45 fprintf(stderr, "compare(%s,%s)\n", a, b);
46 return !strcmp(a, b);
48 #else
49 #define same_name(a,b) !strcmp(a,b)
50 #endif
52 NCURSES_EXPORT(int)
53 NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
55 int result = ABSENT_BOOLEAN;
56 int i, j;
58 T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
60 if (HasTInfoTerminal(SP_PARM)) {
61 TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
62 struct name_table_entry const *entry_ptr;
64 entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
65 if (entry_ptr != 0) {
66 j = entry_ptr->nte_index;
68 #if NCURSES_XNAMES
69 else {
70 j = -1;
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;
79 #endif
80 if (j >= 0) {
81 /* note: setupterm forces invalid booleans to false */
82 result = tp->Booleans[j];
86 returnCode(result);
89 #if NCURSES_SP_FUNCS
90 NCURSES_EXPORT(int)
91 tigetflag(NCURSES_CONST char *str)
93 return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
95 #endif
97 NCURSES_EXPORT(int)
98 NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
100 int i, j;
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 TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
107 struct name_table_entry const *entry_ptr;
109 entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
110 if (entry_ptr != 0) {
111 j = entry_ptr->nte_index;
113 #if NCURSES_XNAMES
114 else {
115 j = -1;
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;
124 #endif
125 if (j >= 0) {
126 if (VALID_NUMERIC(tp->Numbers[j]))
127 result = tp->Numbers[j];
128 else
129 result = ABSENT_NUMERIC;
133 returnCode(result);
136 #if NCURSES_SP_FUNCS
137 NCURSES_EXPORT(int)
138 tigetnum(NCURSES_CONST char *str)
140 return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
142 #endif
144 NCURSES_EXPORT(char *)
145 NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
147 char *result = CANCELLED_STRING;
148 int i, j;
150 T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
152 if (HasTInfoTerminal(SP_PARM)) {
153 TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
154 struct name_table_entry const *entry_ptr;
156 entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
157 if (entry_ptr != 0) {
158 j = entry_ptr->nte_index;
160 #if NCURSES_XNAMES
161 else {
162 j = -1;
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;
171 #endif
172 if (j >= 0) {
173 /* note: setupterm forces cancelled strings to null */
174 result = tp->Strings[j];
178 returnPtr(result);
181 #if NCURSES_SP_FUNCS
182 NCURSES_EXPORT(char *)
183 tigetstr(NCURSES_CONST char *str)
185 return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
187 #endif