Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2018,2020 Thomas E. Dickey * |
| 3 | * Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a * |
| 6 | * copy of this software and associated documentation files (the * |
| 7 | * "Software"), to deal in the Software without restriction, including * |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, * |
| 9 | * distribute, distribute with modifications, sublicense, and/or sell * |
| 10 | * copies of the Software, and to permit persons to whom the Software is * |
| 11 | * furnished to do so, subject to the following conditions: * |
| 12 | * * |
| 13 | * The above copyright notice and this permission notice shall be included * |
| 14 | * in all copies or substantial portions of the Software. * |
| 15 | * * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 19 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 22 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 23 | * * |
| 24 | * Except as contained in this notice, the name(s) of the above copyright * |
| 25 | * holders shall not be used in advertising or otherwise to promote the * |
| 26 | * sale, use or other dealings in this Software without prior written * |
| 27 | * authorization. * |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | /**************************************************************************** |
| 31 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 32 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 33 | * and: Thomas E. Dickey 1996-on * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 34 | ****************************************************************************/ |
| 35 | |
| 36 | #include <curses.priv.h> |
| 37 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 38 | #include <tic.h> |
| 39 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 40 | MODULE_ID("$Id: lib_ti.c,v 1.34 2020/02/02 23:34:34 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 41 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 42 | #if 0 |
| 43 | static bool |
| 44 | same_name(const char *a, const char *b) |
| 45 | { |
| 46 | fprintf(stderr, "compare(%s,%s)\n", a, b); |
| 47 | return !strcmp(a, b); |
| 48 | } |
| 49 | #else |
| 50 | #define same_name(a,b) !strcmp(a,b) |
| 51 | #endif |
| 52 | |
| 53 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 54 | NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx const char *str) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 55 | { |
| 56 | int result = ABSENT_BOOLEAN; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 57 | |
| 58 | T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str)); |
| 59 | |
| 60 | if (HasTInfoTerminal(SP_PARM)) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 61 | TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 62 | struct name_table_entry const *entry_ptr; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 63 | int j = -1; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 64 | |
| 65 | entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE); |
| 66 | if (entry_ptr != 0) { |
| 67 | j = entry_ptr->nte_index; |
| 68 | } |
| 69 | #if NCURSES_XNAMES |
| 70 | else { |
| 71 | int i; |
| 72 | for_each_ext_boolean(i, tp) { |
| 73 | const char *capname = ExtBoolname(tp, i, boolnames); |
| 74 | if (same_name(str, capname)) { |
| 75 | j = i; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | #endif |
| 81 | if (j >= 0) { |
| 82 | /* note: setupterm forces invalid booleans to false */ |
| 83 | result = tp->Booleans[j]; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | returnCode(result); |
| 88 | } |
| 89 | |
| 90 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 91 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 92 | tigetflag(const char *str) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 93 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 94 | return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str); |
| 95 | } |
| 96 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 97 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 98 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 99 | NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx const char *str) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 100 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 101 | int result = CANCELLED_NUMERIC; /* Solaris returns a -1 on error */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 102 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 103 | T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str)); |
| 104 | |
| 105 | if (HasTInfoTerminal(SP_PARM)) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 106 | TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 107 | struct name_table_entry const *entry_ptr; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 108 | int j = -1; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 109 | |
| 110 | entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE); |
| 111 | if (entry_ptr != 0) { |
| 112 | j = entry_ptr->nte_index; |
| 113 | } |
| 114 | #if NCURSES_XNAMES |
| 115 | else { |
| 116 | int i; |
| 117 | for_each_ext_number(i, tp) { |
| 118 | const char *capname = ExtNumname(tp, i, numnames); |
| 119 | if (same_name(str, capname)) { |
| 120 | j = i; |
| 121 | break; |
| 122 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 123 | } |
| 124 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 125 | #endif |
| 126 | if (j >= 0) { |
| 127 | if (VALID_NUMERIC(tp->Numbers[j])) |
| 128 | result = tp->Numbers[j]; |
| 129 | else |
| 130 | result = ABSENT_NUMERIC; |
| 131 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 132 | } |
| 133 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 134 | returnCode(result); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 135 | } |
| 136 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 137 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 138 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 139 | tigetnum(const char *str) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 140 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 141 | return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str); |
| 142 | } |
| 143 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 144 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 145 | NCURSES_EXPORT(char *) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 146 | NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx const char *str) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 147 | { |
| 148 | char *result = CANCELLED_STRING; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 149 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 150 | T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str)); |
| 151 | |
| 152 | if (HasTInfoTerminal(SP_PARM)) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 153 | TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 154 | struct name_table_entry const *entry_ptr; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 155 | int j = -1; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 156 | |
| 157 | entry_ptr = _nc_find_type_entry(str, STRING, FALSE); |
| 158 | if (entry_ptr != 0) { |
| 159 | j = entry_ptr->nte_index; |
| 160 | } |
| 161 | #if NCURSES_XNAMES |
| 162 | else { |
| 163 | int i; |
| 164 | for_each_ext_string(i, tp) { |
| 165 | const char *capname = ExtStrname(tp, i, strnames); |
| 166 | if (same_name(str, capname)) { |
| 167 | j = i; |
| 168 | break; |
| 169 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 170 | } |
| 171 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 172 | #endif |
| 173 | if (j >= 0) { |
| 174 | /* note: setupterm forces cancelled strings to null */ |
| 175 | result = tp->Strings[j]; |
| 176 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 177 | } |
| 178 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 179 | returnPtr(result); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 180 | } |
| 181 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 182 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 183 | NCURSES_EXPORT(char *) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 184 | tigetstr(const char *str) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 185 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 186 | return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 187 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 188 | #endif |