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
42 MODULE_ID("$Id: lib_termcap.c,v 1.17 1998/02/11 12:13:54 tom Exp $")
45 some of the code in here was contributed by:
46 Magnus Bengtsson, d6mbeng@dtek.chalmers.se
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 ***************************************************************************/
69 int tgetent(char *bufp GCC_UNUSED, const char *name)
76 T(("calling tgetent"));
77 setupterm(name, STDOUT_FILENO, &errcode);
83 if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
84 backspace_if_not_bs = cursor_left;
86 /* we're required to export these */
89 if (cursor_up != NULL)
91 if (backspace_if_not_bs != NULL)
92 BC = backspace_if_not_bs;
95 * Back-convert to the funny speed encoding used by the old BSD
96 * curses library. Method suggested by Andrey Chernov
97 * <ache@astral.msk.su>
99 if ((speed = cfgetospeed(&cur_term->Nttyb)) < 1)
100 ospeed = 1; /* assume lowest non-hangup speed */
104 static const speed_t speeds[] = {
140 #define MAXSPEED SIZEOF(speeds)
142 for (sp = speeds; sp < speeds + MAXSPEED; sp++) {
143 if (sp[0] <= speed) {
147 ospeed = MAXSPEED - (sp - speeds);
150 ospeed = cur_term->Nttyb.sg_ospeed;
155 #include <capdefaults.c>
162 /***************************************************************************
166 * Look up boolean termcap capability str and return its value (TRUE=1 if
167 * present, FALSE=0 if not).
169 ***************************************************************************/
171 int tgetflag(const char *id)
175 T(("tgetflag: %s", id));
177 for (i = 0; i < BOOLCOUNT; i++)
178 if (!strcmp(id, boolcodes[i]))
179 return cur_term->type.Booleans[i];
184 /***************************************************************************
188 * Look up numeric termcap capability str and return its value, or -1 if
191 ***************************************************************************/
193 int tgetnum(const char *id)
197 T(("tgetnum: %s", id));
199 for (i = 0; i < NUMCOUNT; i++)
200 if (!strcmp(id, numcodes[i]))
201 return cur_term->type.Numbers[i];
206 /***************************************************************************
210 * Look up string termcap capability str and return a pointer to its value,
211 * or NULL if not given.
213 ***************************************************************************/
215 char *tgetstr(const char *id, char **area GCC_UNUSED)
219 T(("tgetstr: %s", id));
221 for (i = 0; i < STRCOUNT; i++) {
222 T(("trying %s", strcodes[i]));
223 if (!strcmp(id, strcodes[i])) {
224 T(("found match : %s", cur_term->type.Strings[i]));
225 return cur_term->type.Strings[i];
234 * tgoto(string, x, y)
236 * Retained solely for upward compatibility. Note the intentional
237 * reversing of the last two arguments.
241 char *tgoto(const char *string, int x, int y)
243 return(tparm(string, y, x));