]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_termcap.c
ncurses 5.1
[ncurses.git] / ncurses / tinfo / lib_termcap.c
1 /****************************************************************************
2  * Copyright (c) 1998,1999,2000 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 <termcap.h>
37 #include <tic.h>
38
39 #define __INTERNAL_CAPS_VISIBLE
40 #include <term_entry.h>
41
42 MODULE_ID("$Id: lib_termcap.c,v 1.36 2000/02/13 01:01:26 tom Exp $")
43
44 /*
45    some of the code in here was contributed by:
46    Magnus Bengtsson, d6mbeng@dtek.chalmers.se
47 */
48
49 char *UP = 0;
50 char *BC = 0;
51
52 /***************************************************************************
53  *
54  * tgetent(bufp, term)
55  *
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
58  * below are called.
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.
64  *
65  ***************************************************************************/
66
67 int
68 tgetent(char *bufp GCC_UNUSED, const char *name)
69 {
70     int errcode;
71
72     T((T_CALLED("tgetent()")));
73
74     setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode);
75
76     if (errcode == 1) {
77
78         if (cursor_left)
79             if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
80                 backspace_if_not_bs = cursor_left;
81
82         /* we're required to export these */
83         if (pad_char != NULL)
84             PC = pad_char[0];
85         if (cursor_up != NULL)
86             UP = cursor_up;
87         if (backspace_if_not_bs != NULL)
88             BC = backspace_if_not_bs;
89
90         (void) baudrate();      /* sets ospeed as a side-effect */
91
92 /* LINT_PREPRO
93 #if 0*/
94 #include <capdefaults.c>
95 /* LINT_PREPRO
96 #endif*/
97
98     }
99     returnCode(errcode);
100 }
101
102 /***************************************************************************
103  *
104  * tgetflag(str)
105  *
106  * Look up boolean termcap capability str and return its value (TRUE=1 if
107  * present, FALSE=0 if not).
108  *
109  ***************************************************************************/
110
111 int
112 tgetflag(NCURSES_CONST char *id)
113 {
114     int i;
115
116     T((T_CALLED("tgetflag(%s)"), id));
117     if (cur_term != 0) {
118         TERMTYPE *tp = &(cur_term->type);
119         for_each_boolean(i, tp) {
120             const char *capname = ExtBoolname(tp, i, boolcodes);
121             if (!strncmp(id, capname, 2)) {
122                 /* setupterm forces invalid booleans to false */
123                 returnCode(tp->Booleans[i]);
124             }
125         }
126     }
127     returnCode(0);              /* Solaris does this */
128 }
129
130 /***************************************************************************
131  *
132  * tgetnum(str)
133  *
134  * Look up numeric termcap capability str and return its value, or -1 if
135  * not given.
136  *
137  ***************************************************************************/
138
139 int
140 tgetnum(NCURSES_CONST char *id)
141 {
142     int i;
143
144     T((T_CALLED("tgetnum(%s)"), id));
145     if (cur_term != 0) {
146         TERMTYPE *tp = &(cur_term->type);
147         for_each_number(i, tp) {
148             const char *capname = ExtNumname(tp, i, numcodes);
149             if (!strncmp(id, capname, 2)) {
150                 if (!VALID_NUMERIC(tp->Numbers[i]))
151                     returnCode(ABSENT_NUMERIC);
152                 returnCode(tp->Numbers[i]);
153             }
154         }
155     }
156     returnCode(ABSENT_NUMERIC);
157 }
158
159 /***************************************************************************
160  *
161  * tgetstr(str, area)
162  *
163  * Look up string termcap capability str and return a pointer to its value,
164  * or NULL if not given.
165  *
166  ***************************************************************************/
167
168 char *
169 tgetstr(NCURSES_CONST char *id, char **area)
170 {
171     int i;
172
173     T((T_CALLED("tgetstr(%s,%p)"), id, area));
174     if (cur_term != 0) {
175         TERMTYPE *tp = &(cur_term->type);
176         for_each_string(i, tp) {
177             const char *capname = ExtStrname(tp, i, strcodes);
178             if (!strncmp(id, capname, 2)) {
179                 TR(TRACE_DATABASE,("found match : %s", _nc_visbuf(tp->Strings[i])));
180                 /* setupterm forces canceled strings to null */
181                 if (area != 0
182                     && *area != 0
183                     && VALID_STRING(tp->Strings[i])) {
184                     (void) strcpy(*area, tp->Strings[i]);
185                     *area += strlen(*area) + 1;
186                 }
187                 returnPtr(tp->Strings[i]);
188             }
189         }
190     }
191     returnPtr(NULL);
192 }
193
194 /*
195  *      char *
196  *      tgoto(string, x, y)
197  *
198  *      Retained solely for upward compatibility.  Note the intentional
199  *      reversing of the last two arguments.
200  *
201  */
202
203 char *
204 tgoto(const char *string, int x, int y)
205 {
206     T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
207     returnPtr(tparm((NCURSES_CONST char *) string, y, x));
208 }