lib_termcap.c revision 50850
1/**************************************************************************** 2 * Copyright (c) 1998 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 42MODULE_ID("$Id: lib_termcap.c,v 1.28 1999/02/27 22:12:58 tom Exp $") 43 44/* 45 some of the code in here was contributed by: 46 Magnus Bengtsson, d6mbeng@dtek.chalmers.se 47*/ 48 49char *UP; 50char *BC; 51 52#ifdef FREEBSD_NATIVE 53#undef GCC_UNUSED 54#define GCC_UNUSED 55extern char _nc_termcap[]; /* buffer to copy out */ 56#endif 57 58/*************************************************************************** 59 * 60 * tgetent(bufp, term) 61 * 62 * In termcap, this function reads in the entry for terminal `term' into the 63 * buffer pointed to by bufp. It must be called before any of the functions 64 * below are called. 65 * In this terminfo emulation, tgetent() simply calls setupterm() (which 66 * does a bit more than tgetent() in termcap does), and returns its return 67 * value (1 if successful, 0 if no terminal with the given name could be 68 * found, or -1 if no terminal descriptions have been installed on the 69 * system). The bufp argument is ignored. 70 * 71 ***************************************************************************/ 72 73int tgetent(char *bufp GCC_UNUSED, const char *name) 74{ 75int errcode; 76 77 T((T_CALLED("tgetent()"))); 78 79 setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode); 80 81 if (errcode == 1) { 82 83 if (cursor_left) 84 if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0) 85 backspace_if_not_bs = cursor_left; 86 87 /* we're required to export these */ 88 if (pad_char != NULL) 89 PC = pad_char[0]; 90 if (cursor_up != NULL) 91 UP = cursor_up; 92 if (backspace_if_not_bs != NULL) 93 BC = backspace_if_not_bs; 94 95 (void) baudrate(); /* sets ospeed as a side-effect */ 96 97/* LINT_PREPRO 98#if 0*/ 99#include <capdefaults.c> 100/* LINT_PREPRO 101#endif*/ 102 103 } 104#ifdef FREEBSD_NATIVE 105 /* 106 * This is a REALLY UGLY hack. Basically, if we originate with 107 * a termcap source, try and copy it out. 108 */ 109 if (bufp && _nc_termcap[0]) 110 strncpy(bufp, _nc_termcap, 1024); 111#endif 112 113 returnCode(errcode); 114} 115 116/*************************************************************************** 117 * 118 * tgetflag(str) 119 * 120 * Look up boolean termcap capability str and return its value (TRUE=1 if 121 * present, FALSE=0 if not). 122 * 123 ***************************************************************************/ 124 125int tgetflag(NCURSES_CONST char *id) 126{ 127int i; 128 129 T((T_CALLED("tgetflag(%s)"), id)); 130 if (cur_term != 0) { 131 TERMTYPE *tp = &(cur_term->type); 132 for_each_boolean(i, tp) { 133 const char *capname = ExtBoolname(tp, i, boolcodes); 134 if (!strncmp(id, capname, 2)) { 135 /* setupterm forces invalid booleans to false */ 136 returnCode(tp->Booleans[i]); 137 } 138 } 139 } 140 returnCode(0); /* Solaris does this */ 141} 142 143/*************************************************************************** 144 * 145 * tgetnum(str) 146 * 147 * Look up numeric termcap capability str and return its value, or -1 if 148 * not given. 149 * 150 ***************************************************************************/ 151 152int tgetnum(NCURSES_CONST char *id) 153{ 154int i; 155 156 T((T_CALLED("tgetnum(%s)"), id)); 157 if (cur_term != 0) { 158 TERMTYPE *tp = &(cur_term->type); 159 for_each_number(i, tp) { 160 const char *capname = ExtNumname(tp, i, numcodes); 161 if (!strncmp(id, capname, 2)) { 162 if (!VALID_NUMERIC(tp->Numbers[i])) 163 return -1; 164 returnCode(tp->Numbers[i]); 165 } 166 } 167 } 168 returnCode(ERR); 169} 170 171/*************************************************************************** 172 * 173 * tgetstr(str, area) 174 * 175 * Look up string termcap capability str and return a pointer to its value, 176 * or NULL if not given. 177 * 178 ***************************************************************************/ 179 180char *tgetstr(NCURSES_CONST char *id, char **area GCC_UNUSED) 181{ 182int i; 183 184 T((T_CALLED("tgetstr(%s,%p)"), id, area)); 185 if (cur_term != 0) { 186 TERMTYPE *tp = &(cur_term->type); 187 for_each_string(i, tp) { 188 const char *capname = ExtStrname(tp, i, strcodes); 189 T(("trying %s", capname)); 190 if (!strncmp(id, capname, 2)) { 191 T(("found match : %s", _nc_visbuf(tp->Strings[i]))); 192 /* setupterm forces cancelled strings to null */ 193#ifdef FREEBSD_NATIVE 194 if (*area && tp->Strings[i]) { 195 strcpy(*area, tp->Strings[i]); 196 *area += strlen(tp->Strings[i]) + 1; 197 } 198#endif 199 returnPtr(tp->Strings[i]); 200 } 201 } 202 } 203 returnPtr(NULL); 204} 205 206/* 207 * char * 208 * tgoto(string, x, y) 209 * 210 * Retained solely for upward compatibility. Note the intentional 211 * reversing of the last two arguments. 212 * 213 */ 214 215char *tgoto(const char *string, int x, int y) 216{ 217 T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y)); 218 returnPtr(tparm((NCURSES_CONST char *)string, y, x)); 219} 220