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