Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / contrib / ncurses / 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 /* $FreeBSD: src/contrib/ncurses/ncurses/tinfo/lib_termcap.c,v 1.5.2.2 2000/10/12 18:40:51 peter Exp $ */
35 /* $DragonFly: src/contrib/ncurses/ncurses/tinfo/Attic/lib_termcap.c,v 1.2 2003/06/17 04:24:03 dillon Exp $ */
36
37 #include <curses.priv.h>
38
39 #include <termcap.h>
40 #include <tic.h>
41
42 #define __INTERNAL_CAPS_VISIBLE
43 #include <term_entry.h>
44
45 MODULE_ID("$Id: lib_termcap.c,v 1.37 2000/09/16 20:30:16 tom Exp $")
46
47 /*
48    some of the code in here was contributed by:
49    Magnus Bengtsson, d6mbeng@dtek.chalmers.se
50 */
51
52 char *UP = 0;
53 char *BC = 0;
54
55 #ifdef FREEBSD_NATIVE
56 #undef  GCC_UNUSED
57 #define GCC_UNUSED
58 extern char _nc_termcap[];      /* buffer to copy out */
59 #endif
60
61 /***************************************************************************
62  *
63  * tgetent(bufp, term)
64  *
65  * In termcap, this function reads in the entry for terminal `term' into the
66  * buffer pointed to by bufp. It must be called before any of the functions
67  * below are called.
68  * In this terminfo emulation, tgetent() simply calls setupterm() (which
69  * does a bit more than tgetent() in termcap does), and returns its return
70  * value (1 if successful, 0 if no terminal with the given name could be
71  * found, or -1 if no terminal descriptions have been installed on the
72  * system).  The bufp argument is ignored.
73  *
74  ***************************************************************************/
75
76 int
77 tgetent(char *bufp GCC_UNUSED, const char *name)
78 {
79     int errcode;
80
81     T((T_CALLED("tgetent()")));
82
83     setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode);
84
85     if (errcode == 1) {
86
87         if (cursor_left)
88             if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
89                 backspace_if_not_bs = cursor_left;
90
91         /* we're required to export these */
92         if (pad_char != NULL)
93             PC = pad_char[0];
94         if (cursor_up != NULL)
95             UP = cursor_up;
96         if (backspace_if_not_bs != NULL)
97             BC = backspace_if_not_bs;
98
99         (void) baudrate();      /* sets ospeed as a side-effect */
100
101 /* LINT_PREPRO
102 #if 0*/
103 #include <capdefaults.c>
104 /* LINT_PREPRO
105 #endif*/
106
107     }
108
109 #ifdef FREEBSD_NATIVE
110     /*
111      * This is a REALLY UGLY hack. Basically, if we originate with
112      * a termcap source, try and copy it out.
113      */
114     if (bufp && _nc_termcap[0])
115         strncpy(bufp, _nc_termcap, 1024);
116 #endif
117
118     returnCode(errcode);
119 }
120
121 /***************************************************************************
122  *
123  * tgetflag(str)
124  *
125  * Look up boolean termcap capability str and return its value (TRUE=1 if
126  * present, FALSE=0 if not).
127  *
128  ***************************************************************************/
129
130 int
131 tgetflag(NCURSES_CONST char *id)
132 {
133     int i;
134
135     T((T_CALLED("tgetflag(%s)"), id));
136     if (cur_term != 0) {
137         TERMTYPE *tp = &(cur_term->type);
138         for_each_boolean(i, tp) {
139             const char *capname = ExtBoolname(tp, i, boolcodes);
140             if (!strncmp(id, capname, 2)) {
141                 /* setupterm forces invalid booleans to false */
142                 returnCode(tp->Booleans[i]);
143             }
144         }
145     }
146     returnCode(0);              /* Solaris does this */
147 }
148
149 /***************************************************************************
150  *
151  * tgetnum(str)
152  *
153  * Look up numeric termcap capability str and return its value, or -1 if
154  * not given.
155  *
156  ***************************************************************************/
157
158 int
159 tgetnum(NCURSES_CONST char *id)
160 {
161     int i;
162
163     T((T_CALLED("tgetnum(%s)"), id));
164     if (cur_term != 0) {
165         TERMTYPE *tp = &(cur_term->type);
166         for_each_number(i, tp) {
167             const char *capname = ExtNumname(tp, i, numcodes);
168             if (!strncmp(id, capname, 2)) {
169                 if (!VALID_NUMERIC(tp->Numbers[i]))
170                     returnCode(ABSENT_NUMERIC);
171                 returnCode(tp->Numbers[i]);
172             }
173         }
174     }
175     returnCode(ABSENT_NUMERIC);
176 }
177
178 /***************************************************************************
179  *
180  * tgetstr(str, area)
181  *
182  * Look up string termcap capability str and return a pointer to its value,
183  * or NULL if not given.
184  *
185  ***************************************************************************/
186
187 char *
188 tgetstr(NCURSES_CONST char *id, char **area)
189 {
190     int i;
191
192     T((T_CALLED("tgetstr(%s,%p)"), id, area));
193     if (cur_term != 0) {
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                 TR(TRACE_DATABASE,("found match : %s", _nc_visbuf(tp->Strings[i])));
199                 /* setupterm forces canceled strings to null */
200                 if (area != 0
201                     && *area != 0
202                     && VALID_STRING(tp->Strings[i])) {
203                     (void) strcpy(*area, tp->Strings[i]);
204                     *area += strlen(*area) + 1;
205                 }
206                 returnPtr(tp->Strings[i]);
207             }
208         }
209     }
210     returnPtr(NULL);
211 }