]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_ti.c
355310ec778cecae99259ae9b96a4aa02ba4559d
[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  ****************************************************************************/
33
34 #include <curses.priv.h>
35
36 #include <term_entry.h>
37 #include <tic.h>
38
39 MODULE_ID("$Id: lib_ti.c,v 1.24 2009/04/18 17:37:50 tom Exp $")
40
41 NCURSES_EXPORT(int)
42 NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
43 {
44     unsigned i;
45
46     T((T_CALLED("tigetflag(%p, %s)"), SP_PARM, str));
47
48     if (HasTInfoTerminal(SP_PARM)) {
49         TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
50         for_each_boolean(i, tp) {
51             const char *capname = ExtBoolname(tp, i, boolnames);
52             if (!strcmp(str, capname)) {
53                 /* setupterm forces invalid booleans to false */
54                 returnCode(tp->Booleans[i]);
55             }
56         }
57     }
58
59     returnCode(ABSENT_BOOLEAN);
60 }
61
62 #if NCURSES_SP_FUNCS
63 NCURSES_EXPORT(int)
64 tigetflag(NCURSES_CONST char *str)
65 {
66     return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
67 }
68 #endif
69
70 NCURSES_EXPORT(int)
71 NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
72 {
73     unsigned i;
74
75     T((T_CALLED("tigetnum(%p, %s)"), SP_PARM, str));
76
77     if (HasTInfoTerminal(SP_PARM)) {
78         TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
79         for_each_number(i, tp) {
80             const char *capname = ExtNumname(tp, i, numnames);
81             if (!strcmp(str, capname)) {
82                 if (!VALID_NUMERIC(tp->Numbers[i]))
83                     returnCode(ABSENT_NUMERIC);
84                 returnCode(tp->Numbers[i]);
85             }
86         }
87     }
88
89     returnCode(CANCELLED_NUMERIC);      /* Solaris returns a -1 instead */
90 }
91
92 #if NCURSES_SP_FUNCS
93 NCURSES_EXPORT(int)
94 tigetnum(NCURSES_CONST char *str)
95 {
96     return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
97 }
98 #endif
99
100 NCURSES_EXPORT(char *)
101 NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
102 {
103     unsigned i;
104
105     T((T_CALLED("tigetstr(%p, %s)"), SP_PARM, str));
106
107     if (HasTInfoTerminal(SP_PARM)) {
108         TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
109         for_each_string(i, tp) {
110             const char *capname = ExtStrname(tp, i, strnames);
111             if (!strcmp(str, capname)) {
112                 /* setupterm forces cancelled strings to null */
113                 returnPtr(tp->Strings[i]);
114             }
115         }
116     }
117
118     returnPtr(CANCELLED_STRING);
119 }
120
121 #if NCURSES_SP_FUNCS
122 NCURSES_EXPORT(char *)
123 tigetstr(NCURSES_CONST char *str)
124 {
125     return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
126 }
127 #endif