1 /****************************************************************************
2 * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
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 *
34 * some of the code in here was contributed by: *
35 * Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93) *
36 ****************************************************************************/
38 #define __INTERNAL_CAPS_VISIBLE
39 #include <curses.priv.h>
45 #include <term_entry.h>
47 MODULE_ID("$Id: lib_termcap.c,v 1.51 2005/07/16 23:12:51 tom Exp $")
49 NCURSES_EXPORT_VAR(char *) UP = 0;
50 NCURSES_EXPORT_VAR(char *) BC = 0;
52 static char *fix_me = 0; /* this holds the filtered sgr0 string */
54 /***************************************************************************
58 * In termcap, this function reads in the entry for terminal `term' into the
59 * buffer pointed to by bufp. It must be called before any of the functions
61 * In this terminfo emulation, tgetent() simply calls setupterm() (which
62 * does a bit more than tgetent() in termcap does), and returns its return
63 * value (1 if successful, 0 if no terminal with the given name could be
64 * found, or -1 if no terminal descriptions have been installed on the
65 * system). The bufp argument is ignored.
67 ***************************************************************************/
70 tgetent(char *bufp GCC_UNUSED, const char *name)
75 T((T_CALLED("tgetent()")));
77 _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE);
82 fix_me = 0; /* don't free it - application may still use */
87 if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
88 backspace_if_not_bs = cursor_left;
90 /* we're required to export these */
93 if (cursor_up != NULL)
95 if (backspace_if_not_bs != NULL)
96 BC = backspace_if_not_bs;
99 if ((fix_me = _nc_trim_sgr0(&(cur_term->type))) != 0) {
100 if (!strcmp(fix_me, exit_attribute_mode)) {
101 if (fix_me != exit_attribute_mode) {
108 (void) baudrate(); /* sets ospeed as a side-effect */
112 #include <capdefaults.c>
120 /***************************************************************************
124 * Look up boolean termcap capability str and return its value (TRUE=1 if
125 * present, FALSE=0 if not).
127 ***************************************************************************/
130 tgetflag(NCURSES_CONST char *id)
134 T((T_CALLED("tgetflag(%s)"), id));
136 TERMTYPE *tp = &(cur_term->type);
137 for_each_boolean(i, tp) {
138 const char *capname = ExtBoolname(tp, i, boolcodes);
139 if (!strncmp(id, capname, 2)) {
140 /* setupterm forces invalid booleans to false */
141 returnCode(tp->Booleans[i]);
145 returnCode(0); /* Solaris does this */
148 /***************************************************************************
152 * Look up numeric termcap capability str and return its value, or -1 if
155 ***************************************************************************/
158 tgetnum(NCURSES_CONST char *id)
162 T((T_CALLED("tgetnum(%s)"), id));
164 TERMTYPE *tp = &(cur_term->type);
165 for_each_number(i, tp) {
166 const char *capname = ExtNumname(tp, i, numcodes);
167 if (!strncmp(id, capname, 2)) {
168 if (!VALID_NUMERIC(tp->Numbers[i]))
169 returnCode(ABSENT_NUMERIC);
170 returnCode(tp->Numbers[i]);
174 returnCode(ABSENT_NUMERIC);
177 /***************************************************************************
181 * Look up string termcap capability str and return a pointer to its value,
182 * or NULL if not given.
184 ***************************************************************************/
186 NCURSES_EXPORT(char *)
187 tgetstr(NCURSES_CONST char *id, char **area)
192 T((T_CALLED("tgetstr(%s,%p)"), id, area));
194 TERMTYPE *tp = &(cur_term->type);
195 for_each_string(i, tp) {
196 const char *capname = ExtStrname(tp, i, strcodes);
197 if (!strncmp(id, capname, 2)) {
198 result = tp->Strings[i];
199 TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(result)));
200 /* setupterm forces canceled strings to null */
201 if (VALID_STRING(result)) {
202 if (result == exit_attribute_mode
205 TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result)));
209 (void) strcpy(*area, result);
210 *area += strlen(*area) + 1;