]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_termcap.c
ncurses 4.1
[ncurses.git] / ncurses / lib_termcap.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
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.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 #include <curses.priv.h>
23
24 #include <termcap.h>
25 #include <tic.h>
26
27 #define __INTERNAL_CAPS_VISIBLE
28 #include <term.h>
29
30 MODULE_ID("$Id: lib_termcap.c,v 1.13 1996/12/21 14:24:06 tom Exp $")
31
32 /*
33    some of the code in here was contributed by:
34    Magnus Bengtsson, d6mbeng@dtek.chalmers.se
35 */
36
37 char PC;
38 char *UP;
39 char *BC;
40 short ospeed;
41
42 /***************************************************************************
43  *
44  * tgetent(bufp, term)
45  *
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
48  * below are called.
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.
54  *
55  ***************************************************************************/
56
57 int tgetent(char *bufp GCC_UNUSED, const char *name)
58 {
59 int errcode;
60 #if defined(TERMIOS)
61 speed_t speed;
62 #endif
63
64         T(("calling tgetent"));
65         setupterm((char *)name, STDOUT_FILENO, &errcode);
66
67         if (errcode != 1)
68                 return(errcode);
69
70         if (cursor_left)
71             if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
72                 backspace_if_not_bs = cursor_left;
73
74         /* we're required to export these */
75         if (pad_char != NULL)
76                 PC = pad_char[0];
77         if (cursor_up != NULL)
78                 UP = cursor_up;
79         if (backspace_if_not_bs != NULL)
80                 BC = backspace_if_not_bs;
81 #if defined(TERMIOS)
82         /*
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>
86          */
87         if ((speed = cfgetospeed(&cur_term->Nttyb)) < 1)
88             ospeed = 1;         /* assume lowest non-hangup speed */
89         else
90         {
91                 const speed_t *sp;
92                 static const speed_t speeds[] = {
93 #ifdef B115200
94                         B115200,
95 #endif
96 #ifdef B57600
97                         B57600,
98 #endif
99 #ifdef B38400
100                         B38400,
101 #else
102 #ifdef EXTB
103                         EXTB,
104 #endif
105 #endif /* B38400 */
106 #ifdef B19200
107                         B19200,
108 #else
109 #ifdef EXTA
110                         EXTA,
111 #endif
112 #endif /* B19200 */
113                         B9600,
114                         B4800,
115                         B2400,
116                         B1800,
117                         B1200,
118                         B600,
119                         B300,
120                         B200,
121                         B150,
122                         B134,
123                         B110,
124                         B75,
125                         B50,
126                         B0,
127                 };
128 #define MAXSPEED        sizeof(speeds)/sizeof(speeds[0])
129
130                 for (sp = speeds; sp < speeds + MAXSPEED; sp++) {
131                         if (sp[0] <= speed) {
132                                 break;
133                         }
134                 }
135                 ospeed = MAXSPEED - (sp - speeds);
136         }
137 #else
138         ospeed = cur_term->Nttyb.sg_ospeed;
139 #endif
140
141 /* LINT_PREPRO
142 #if 0*/
143 #include <capdefaults.c>
144 /* LINT_PREPRO
145 #endif*/
146
147         return errcode;
148 }
149
150 /***************************************************************************
151  *
152  * tgetflag(str)
153  *
154  * Look up boolean termcap capability str and return its value (TRUE=1 if
155  * present, FALSE=0 if not).
156  *
157  ***************************************************************************/
158
159 int tgetflag(const char *id)
160 {
161 int i;
162
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];
167         return ERR;
168 }
169
170 /***************************************************************************
171  *
172  * tgetnum(str)
173  *
174  * Look up numeric termcap capability str and return its value, or -1 if
175  * not given.
176  *
177  ***************************************************************************/
178
179 int tgetnum(const char *id)
180 {
181 int i;
182
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];
187         return ERR;
188 }
189
190 /***************************************************************************
191  *
192  * tgetstr(str, area)
193  *
194  * Look up string termcap capability str and return a pointer to its value,
195  * or NULL if not given.
196  *
197  ***************************************************************************/
198
199 char *tgetstr(const char *id, char **area GCC_UNUSED)
200 {
201 int i;
202
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];
209                 }
210         }
211         return NULL;
212 }
213
214 /*
215  *      char *
216  *      tgoto(string, x, y)
217  *
218  *      Retained solely for upward compatibility.  Note the intentional
219  *      reversing of the last two arguments.
220  *
221  */
222
223 char *tgoto(const char *string, int x, int y)
224 {
225         return(tparm((char *)string, y, x));
226 }