2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
22 #include <curses.priv.h>
27 #define __INTERNAL_CAPS_VISIBLE
30 MODULE_ID("$Id: lib_termcap.c,v 1.13 1996/12/21 14:24:06 tom Exp $")
33 some of the code in here was contributed by:
34 Magnus Bengtsson, d6mbeng@dtek.chalmers.se
42 /***************************************************************************
46 * In termcap, this function reads in the entry for terminal `term' into the
47 * buffer pointed to by bufp. It must be called before any of the functions
49 * In this terminfo emulation, tgetent() simply calls setupterm() (which
50 * does a bit more than tgetent() in termcap does), and returns its return
51 * value (1 if successful, 0 if no terminal with the given name could be
52 * found, or -1 if no terminal descriptions have been installed on the
53 * system). The bufp argument is ignored.
55 ***************************************************************************/
57 int tgetent(char *bufp GCC_UNUSED, const char *name)
64 T(("calling tgetent"));
65 setupterm((char *)name, STDOUT_FILENO, &errcode);
71 if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
72 backspace_if_not_bs = cursor_left;
74 /* we're required to export these */
77 if (cursor_up != NULL)
79 if (backspace_if_not_bs != NULL)
80 BC = backspace_if_not_bs;
83 * Back-convert to the funny speed encoding used by the old BSD
84 * curses library. Method suggested by Andrey Chernov
85 * <ache@astral.msk.su>
87 if ((speed = cfgetospeed(&cur_term->Nttyb)) < 1)
88 ospeed = 1; /* assume lowest non-hangup speed */
92 static const speed_t speeds[] = {
128 #define MAXSPEED sizeof(speeds)/sizeof(speeds[0])
130 for (sp = speeds; sp < speeds + MAXSPEED; sp++) {
131 if (sp[0] <= speed) {
135 ospeed = MAXSPEED - (sp - speeds);
138 ospeed = cur_term->Nttyb.sg_ospeed;
143 #include <capdefaults.c>
150 /***************************************************************************
154 * Look up boolean termcap capability str and return its value (TRUE=1 if
155 * present, FALSE=0 if not).
157 ***************************************************************************/
159 int tgetflag(const char *id)
163 T(("tgetflag: %s", id));
164 for (i = 0; i < BOOLCOUNT; i++)
165 if (!strcmp(id, boolcodes[i]))
166 return cur_term->type.Booleans[i];
170 /***************************************************************************
174 * Look up numeric termcap capability str and return its value, or -1 if
177 ***************************************************************************/
179 int tgetnum(const char *id)
183 T(("tgetnum: %s", id));
184 for (i = 0; i < NUMCOUNT; i++)
185 if (!strcmp(id, numcodes[i]))
186 return cur_term->type.Numbers[i];
190 /***************************************************************************
194 * Look up string termcap capability str and return a pointer to its value,
195 * or NULL if not given.
197 ***************************************************************************/
199 char *tgetstr(const char *id, char **area GCC_UNUSED)
203 T(("tgetstr: %s", id));
204 for (i = 0; i < STRCOUNT; i++) {
205 T(("trying %s", strcodes[i]));
206 if (!strcmp(id, strcodes[i])) {
207 T(("found match : %s", cur_term->type.Strings[i]));
208 return cur_term->type.Strings[i];
216 * tgoto(string, x, y)
218 * Retained solely for upward compatibility. Note the intentional
219 * reversing of the last two arguments.
223 char *tgoto(const char *string, int x, int y)
225 return(tparm((char *)string, y, x));