xref: /freebsd/contrib/ncurses/ncurses/tinfo/lib_ti.c (revision 73f0a83d68863a383fd8953972cd36eb6420ec7d)
10e3d5408SPeter Wemm /****************************************************************************
2*73f0a83dSXin LI  * Copyright (c) 1998-2010,2013 Free Software Foundation, Inc.              *
30e3d5408SPeter Wemm  *                                                                          *
40e3d5408SPeter Wemm  * Permission is hereby granted, free of charge, to any person obtaining a  *
50e3d5408SPeter Wemm  * copy of this software and associated documentation files (the            *
60e3d5408SPeter Wemm  * "Software"), to deal in the Software without restriction, including      *
70e3d5408SPeter Wemm  * without limitation the rights to use, copy, modify, merge, publish,      *
80e3d5408SPeter Wemm  * distribute, distribute with modifications, sublicense, and/or sell       *
90e3d5408SPeter Wemm  * copies of the Software, and to permit persons to whom the Software is    *
100e3d5408SPeter Wemm  * furnished to do so, subject to the following conditions:                 *
110e3d5408SPeter Wemm  *                                                                          *
120e3d5408SPeter Wemm  * The above copyright notice and this permission notice shall be included  *
130e3d5408SPeter Wemm  * in all copies or substantial portions of the Software.                   *
140e3d5408SPeter Wemm  *                                                                          *
150e3d5408SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
160e3d5408SPeter Wemm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
170e3d5408SPeter Wemm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
180e3d5408SPeter Wemm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
190e3d5408SPeter Wemm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
200e3d5408SPeter Wemm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
210e3d5408SPeter Wemm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
220e3d5408SPeter Wemm  *                                                                          *
230e3d5408SPeter Wemm  * Except as contained in this notice, the name(s) of the above copyright   *
240e3d5408SPeter Wemm  * holders shall not be used in advertising or otherwise to promote the     *
250e3d5408SPeter Wemm  * sale, use or other dealings in this Software without prior written       *
260e3d5408SPeter Wemm  * authorization.                                                           *
270e3d5408SPeter Wemm  ****************************************************************************/
280e3d5408SPeter Wemm 
290e3d5408SPeter Wemm /****************************************************************************
300e3d5408SPeter Wemm  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
310e3d5408SPeter Wemm  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
3206bfebdeSXin LI  *     and: Thomas E. Dickey                        1996-on                 *
330e3d5408SPeter Wemm  ****************************************************************************/
340e3d5408SPeter Wemm 
350e3d5408SPeter Wemm #include <curses.priv.h>
360e3d5408SPeter Wemm 
370e3d5408SPeter Wemm #include <tic.h>
380e3d5408SPeter Wemm 
39*73f0a83dSXin LI MODULE_ID("$Id: lib_ti.c,v 1.30 2013/06/08 16:55:05 tom Exp $")
400e3d5408SPeter Wemm 
4106bfebdeSXin LI #if 0
4206bfebdeSXin LI static bool
4306bfebdeSXin LI same_name(const char *a, const char *b)
4406bfebdeSXin LI {
4506bfebdeSXin LI     fprintf(stderr, "compare(%s,%s)\n", a, b);
4606bfebdeSXin LI     return !strcmp(a, b);
4706bfebdeSXin LI }
4806bfebdeSXin LI #else
4906bfebdeSXin LI #define same_name(a,b) !strcmp(a,b)
5006bfebdeSXin LI #endif
5106bfebdeSXin LI 
5206bfebdeSXin LI NCURSES_EXPORT(int)
5306bfebdeSXin LI NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
5406bfebdeSXin LI {
5506bfebdeSXin LI     int result = ABSENT_BOOLEAN;
56*73f0a83dSXin LI     int j = -1;
5706bfebdeSXin LI 
5806bfebdeSXin LI     T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
5906bfebdeSXin LI 
6006bfebdeSXin LI     if (HasTInfoTerminal(SP_PARM)) {
6106bfebdeSXin LI 	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
6206bfebdeSXin LI 	struct name_table_entry const *entry_ptr;
6306bfebdeSXin LI 
6406bfebdeSXin LI 	entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
6506bfebdeSXin LI 	if (entry_ptr != 0) {
6606bfebdeSXin LI 	    j = entry_ptr->nte_index;
6706bfebdeSXin LI 	}
6806bfebdeSXin LI #if NCURSES_XNAMES
6906bfebdeSXin LI 	else {
70*73f0a83dSXin LI 	    int i;
7106bfebdeSXin LI 	    for_each_ext_boolean(i, tp) {
7206bfebdeSXin LI 		const char *capname = ExtBoolname(tp, i, boolnames);
7306bfebdeSXin LI 		if (same_name(str, capname)) {
7406bfebdeSXin LI 		    j = i;
7506bfebdeSXin LI 		    break;
7606bfebdeSXin LI 		}
7706bfebdeSXin LI 	    }
7806bfebdeSXin LI 	}
7906bfebdeSXin LI #endif
8006bfebdeSXin LI 	if (j >= 0) {
8106bfebdeSXin LI 	    /* note: setupterm forces invalid booleans to false */
8206bfebdeSXin LI 	    result = tp->Booleans[j];
8306bfebdeSXin LI 	}
8406bfebdeSXin LI     }
8506bfebdeSXin LI 
8606bfebdeSXin LI     returnCode(result);
8706bfebdeSXin LI }
8806bfebdeSXin LI 
8906bfebdeSXin LI #if NCURSES_SP_FUNCS
907a69bbfbSPeter Wemm NCURSES_EXPORT(int)
9115589c42SPeter Wemm tigetflag(NCURSES_CONST char *str)
920e3d5408SPeter Wemm {
9306bfebdeSXin LI     return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
9406bfebdeSXin LI }
9506bfebdeSXin LI #endif
960e3d5408SPeter Wemm 
9706bfebdeSXin LI NCURSES_EXPORT(int)
9806bfebdeSXin LI NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
9906bfebdeSXin LI {
100*73f0a83dSXin LI     int j = -1;
10106bfebdeSXin LI     int result = CANCELLED_NUMERIC;	/* Solaris returns a -1 on error */
1020e3d5408SPeter Wemm 
10306bfebdeSXin LI     T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str));
10406bfebdeSXin LI 
10506bfebdeSXin LI     if (HasTInfoTerminal(SP_PARM)) {
10606bfebdeSXin LI 	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
10706bfebdeSXin LI 	struct name_table_entry const *entry_ptr;
10806bfebdeSXin LI 
10906bfebdeSXin LI 	entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
11006bfebdeSXin LI 	if (entry_ptr != 0) {
11106bfebdeSXin LI 	    j = entry_ptr->nte_index;
11206bfebdeSXin LI 	}
11306bfebdeSXin LI #if NCURSES_XNAMES
11406bfebdeSXin LI 	else {
115*73f0a83dSXin LI 	    int i;
11606bfebdeSXin LI 	    for_each_ext_number(i, tp) {
11706bfebdeSXin LI 		const char *capname = ExtNumname(tp, i, numnames);
11806bfebdeSXin LI 		if (same_name(str, capname)) {
11906bfebdeSXin LI 		    j = i;
12006bfebdeSXin LI 		    break;
1210e3d5408SPeter Wemm 		}
1220e3d5408SPeter Wemm 	    }
1230e3d5408SPeter Wemm 	}
12406bfebdeSXin LI #endif
12506bfebdeSXin LI 	if (j >= 0) {
12606bfebdeSXin LI 	    if (VALID_NUMERIC(tp->Numbers[j]))
12706bfebdeSXin LI 		result = tp->Numbers[j];
12806bfebdeSXin LI 	    else
12906bfebdeSXin LI 		result = ABSENT_NUMERIC;
13006bfebdeSXin LI 	}
1310e3d5408SPeter Wemm     }
1320e3d5408SPeter Wemm 
13306bfebdeSXin LI     returnCode(result);
13406bfebdeSXin LI }
13506bfebdeSXin LI 
13606bfebdeSXin LI #if NCURSES_SP_FUNCS
1377a69bbfbSPeter Wemm NCURSES_EXPORT(int)
13815589c42SPeter Wemm tigetnum(NCURSES_CONST char *str)
1390e3d5408SPeter Wemm {
14006bfebdeSXin LI     return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
14106bfebdeSXin LI }
14206bfebdeSXin LI #endif
1430e3d5408SPeter Wemm 
14406bfebdeSXin LI NCURSES_EXPORT(char *)
14506bfebdeSXin LI NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
14606bfebdeSXin LI {
14706bfebdeSXin LI     char *result = CANCELLED_STRING;
148*73f0a83dSXin LI     int j = -1;
1490e3d5408SPeter Wemm 
15006bfebdeSXin LI     T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
15106bfebdeSXin LI 
15206bfebdeSXin LI     if (HasTInfoTerminal(SP_PARM)) {
15306bfebdeSXin LI 	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
15406bfebdeSXin LI 	struct name_table_entry const *entry_ptr;
15506bfebdeSXin LI 
15606bfebdeSXin LI 	entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
15706bfebdeSXin LI 	if (entry_ptr != 0) {
15806bfebdeSXin LI 	    j = entry_ptr->nte_index;
15906bfebdeSXin LI 	}
16006bfebdeSXin LI #if NCURSES_XNAMES
16106bfebdeSXin LI 	else {
162*73f0a83dSXin LI 	    int i;
16306bfebdeSXin LI 	    for_each_ext_string(i, tp) {
16406bfebdeSXin LI 		const char *capname = ExtStrname(tp, i, strnames);
16506bfebdeSXin LI 		if (same_name(str, capname)) {
16606bfebdeSXin LI 		    j = i;
16706bfebdeSXin LI 		    break;
1680e3d5408SPeter Wemm 		}
1690e3d5408SPeter Wemm 	    }
1700e3d5408SPeter Wemm 	}
17106bfebdeSXin LI #endif
17206bfebdeSXin LI 	if (j >= 0) {
17306bfebdeSXin LI 	    /* note: setupterm forces cancelled strings to null */
17406bfebdeSXin LI 	    result = tp->Strings[j];
17506bfebdeSXin LI 	}
1760e3d5408SPeter Wemm     }
1770e3d5408SPeter Wemm 
17806bfebdeSXin LI     returnPtr(result);
17906bfebdeSXin LI }
18006bfebdeSXin LI 
18106bfebdeSXin LI #if NCURSES_SP_FUNCS
1827a69bbfbSPeter Wemm NCURSES_EXPORT(char *)
18315589c42SPeter Wemm tigetstr(NCURSES_CONST char *str)
1840e3d5408SPeter Wemm {
18506bfebdeSXin LI     return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
1860e3d5408SPeter Wemm }
18706bfebdeSXin LI #endif
188