1 /****************************************************************************
2 * Copyright (c) 1998 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 ****************************************************************************/
34 #include <curses.priv.h>
39 #define __INTERNAL_CAPS_VISIBLE
40 #include <term_entry.h>
42 MODULE_ID("$Id: lib_termcap.c,v 1.29 1999/09/05 01:06:43 tom Exp $")
45 some of the code in here was contributed by:
46 Magnus Bengtsson, d6mbeng@dtek.chalmers.se
52 /***************************************************************************
56 * In termcap, this function reads in the entry for terminal `term' into the
57 * buffer pointed to by bufp. It must be called before any of the functions
59 * In this terminfo emulation, tgetent() simply calls setupterm() (which
60 * does a bit more than tgetent() in termcap does), and returns its return
61 * value (1 if successful, 0 if no terminal with the given name could be
62 * found, or -1 if no terminal descriptions have been installed on the
63 * system). The bufp argument is ignored.
65 ***************************************************************************/
67 int tgetent(char *bufp GCC_UNUSED, const char *name)
71 T((T_CALLED("tgetent()")));
73 setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode);
78 if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
79 backspace_if_not_bs = cursor_left;
81 /* we're required to export these */
84 if (cursor_up != NULL)
86 if (backspace_if_not_bs != NULL)
87 BC = backspace_if_not_bs;
89 (void) baudrate(); /* sets ospeed as a side-effect */
93 #include <capdefaults.c>
101 /***************************************************************************
105 * Look up boolean termcap capability str and return its value (TRUE=1 if
106 * present, FALSE=0 if not).
108 ***************************************************************************/
110 int tgetflag(NCURSES_CONST char *id)
114 T((T_CALLED("tgetflag(%s)"), id));
116 TERMTYPE *tp = &(cur_term->type);
117 for_each_boolean(i, tp) {
118 const char *capname = ExtBoolname(tp, i, boolcodes);
119 if (!strncmp(id, capname, 2)) {
120 /* setupterm forces invalid booleans to false */
121 returnCode(tp->Booleans[i]);
125 returnCode(0); /* Solaris does this */
128 /***************************************************************************
132 * Look up numeric termcap capability str and return its value, or -1 if
135 ***************************************************************************/
137 int tgetnum(NCURSES_CONST char *id)
141 T((T_CALLED("tgetnum(%s)"), id));
143 TERMTYPE *tp = &(cur_term->type);
144 for_each_number(i, tp) {
145 const char *capname = ExtNumname(tp, i, numcodes);
146 if (!strncmp(id, capname, 2)) {
147 if (!VALID_NUMERIC(tp->Numbers[i]))
149 returnCode(tp->Numbers[i]);
156 /***************************************************************************
160 * Look up string termcap capability str and return a pointer to its value,
161 * or NULL if not given.
163 ***************************************************************************/
165 char *tgetstr(NCURSES_CONST char *id, char **area)
169 T((T_CALLED("tgetstr(%s,%p)"), id, area));
171 TERMTYPE *tp = &(cur_term->type);
172 for_each_string(i, tp) {
173 const char *capname = ExtStrname(tp, i, strcodes);
174 T(("trying %s", capname));
175 if (!strncmp(id, capname, 2)) {
176 T(("found match : %s", _nc_visbuf(tp->Strings[i])));
177 /* setupterm forces cancelled strings to null */
180 && VALID_STRING(tp->Strings[i])) {
181 (void) strcpy(*area, tp->Strings[i]);
182 *area += strlen(*area) + 1;
184 returnPtr(tp->Strings[i]);
193 * tgoto(string, x, y)
195 * Retained solely for upward compatibility. Note the intentional
196 * reversing of the last two arguments.
200 char *tgoto(const char *string, int x, int y)
202 T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
203 returnPtr(tparm((NCURSES_CONST char *)string, y, x));