lib_termcap.c revision 62453
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 62453 2000-07-03 09:35:22Z 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#ifdef FREEBSD_NATIVE 107 /* 108 * This is a REALLY UGLY hack. Basically, if we originate with 109 * a termcap source, try and copy it out. 110 */ 111 if (bufp && _nc_termcap[0]) 112 strncpy(bufp, _nc_termcap, 1024); 113#endif 114 115 } 116 returnCode(errcode); 117} 118 119/*************************************************************************** 120 * 121 * tgetflag(str) 122 * 123 * Look up boolean termcap capability str and return its value (TRUE=1 if 124 * present, FALSE=0 if not). 125 * 126 ***************************************************************************/ 127 128int 129tgetflag(NCURSES_CONST char *id) 130{ 131 int i; 132 133 T((T_CALLED("tgetflag(%s)"), id)); 134 if (cur_term != 0) { 135 TERMTYPE *tp = &(cur_term->type); 136 for_each_boolean(i, tp) { 137 const char *capname = ExtBoolname(tp, i, boolcodes); 138 if (!strncmp(id, capname, 2)) { 139 /* setupterm forces invalid booleans to false */ 140 returnCode(tp->Booleans[i]); 141 } 142 } 143 } 144 returnCode(0); /* Solaris does this */ 145} 146 147/*************************************************************************** 148 * 149 * tgetnum(str) 150 * 151 * Look up numeric termcap capability str and return its value, or -1 if 152 * not given. 153 * 154 ***************************************************************************/ 155 156int 157tgetnum(NCURSES_CONST char *id) 158{ 159 int i; 160 161 T((T_CALLED("tgetnum(%s)"), id)); 162 if (cur_term != 0) { 163 TERMTYPE *tp = &(cur_term->type); 164 for_each_number(i, tp) { 165 const char *capname = ExtNumname(tp, i, numcodes); 166 if (!strncmp(id, capname, 2)) { 167 if (!VALID_NUMERIC(tp->Numbers[i])) 168 returnCode(ABSENT_NUMERIC); 169 returnCode(tp->Numbers[i]); 170 } 171 } 172 } 173 returnCode(ABSENT_NUMERIC); 174} 175 176/*************************************************************************** 177 * 178 * tgetstr(str, area) 179 * 180 * Look up string termcap capability str and return a pointer to its value, 181 * or NULL if not given. 182 * 183 ***************************************************************************/ 184 185char * 186tgetstr(NCURSES_CONST char *id, char **area) 187{ 188 int i; 189 190 T((T_CALLED("tgetstr(%s,%p)"), id, area)); 191 if (cur_term != 0) { 192 TERMTYPE *tp = &(cur_term->type); 193 for_each_string(i, tp) { 194 const char *capname = ExtStrname(tp, i, strcodes); 195 if (!strncmp(id, capname, 2)) { 196 TR(TRACE_DATABASE,("found match : %s", _nc_visbuf(tp->Strings[i]))); 197 /* setupterm forces canceled strings to null */ 198 if (area != 0 199 && *area != 0 200 && VALID_STRING(tp->Strings[i])) { 201 (void) strcpy(*area, tp->Strings[i]); 202 *area += strlen(*area) + 1; 203 } 204 returnPtr(tp->Strings[i]); 205 } 206 } 207 } 208 returnPtr(NULL); 209} 210 211/* 212 * char * 213 * tgoto(string, x, y) 214 * 215 * Retained solely for upward compatibility. Note the intentional 216 * reversing of the last two arguments. 217 * 218 */ 219 220char * 221tgoto(const char *string, int x, int y) 222{ 223 T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y)); 224 returnPtr(tparm((NCURSES_CONST char *) string, y, x)); 225} 226