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 2020,2023 Thomas E. Dickey * |
| 3 | * Copyright 1999-2010,2016 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 | #include <curses.priv.h> |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 31 | #include <tic.h> /* struct tinfo_fkeys */ |
| 32 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 33 | MODULE_ID("$Id: init_keytry.c,v 1.20 2023/09/16 12:55:01 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | ** _nc_init_keytry() |
| 37 | ** |
| 38 | ** Construct the try for the current terminal's keypad keys. |
| 39 | ** |
| 40 | */ |
| 41 | |
| 42 | /* |
| 43 | * Internal entrypoints use SCREEN* parameter to obtain capabilities rather |
| 44 | * than cur_term. |
| 45 | */ |
| 46 | #undef CUR |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 47 | #define CUR SP_TERMTYPE |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 48 | |
| 49 | #if BROKEN_LINKER |
| 50 | #undef _nc_tinfo_fkeys |
| 51 | #endif |
| 52 | |
| 53 | /* LINT_PREPRO |
| 54 | #if 0*/ |
| 55 | #include <init_keytry.h> |
| 56 | /* LINT_PREPRO |
| 57 | #endif*/ |
| 58 | |
| 59 | #if BROKEN_LINKER |
| 60 | const struct tinfo_fkeys * |
| 61 | _nc_tinfo_fkeysf(void) |
| 62 | { |
| 63 | return _nc_tinfo_fkeys; |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | NCURSES_EXPORT(void) |
| 68 | _nc_init_keytry(SCREEN *sp) |
| 69 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 70 | T(("_nc_init_keytry(%p)", (void *) sp)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 71 | |
| 72 | /* The sp->_keytry value is initialized in newterm(), where the sp |
| 73 | * structure is created, because we can not tell where keypad() or |
| 74 | * mouse_activate() (which will call keyok()) are first called. |
| 75 | */ |
| 76 | |
| 77 | if (sp != 0) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 78 | unsigned n; |
| 79 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 80 | for (n = 0; _nc_tinfo_fkeys[n].code; n++) { |
| 81 | if (_nc_tinfo_fkeys[n].offset < STRCOUNT) { |
| 82 | (void) _nc_add_to_try(&(sp->_keytry), |
| 83 | CUR Strings[_nc_tinfo_fkeys[n].offset], |
| 84 | _nc_tinfo_fkeys[n].code); |
| 85 | } |
| 86 | } |
| 87 | #if NCURSES_XNAMES |
| 88 | /* |
| 89 | * Add any of the extended strings to the tries if their name begins |
| 90 | * with 'k', i.e., they follow the convention of other terminfo key |
| 91 | * names. |
| 92 | */ |
| 93 | { |
| 94 | TERMTYPE *tp = &(sp->_term->type); |
| 95 | for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 96 | const char *name = ExtStrname(tp, (int) n, strnames); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 97 | char *value = tp->Strings[n]; |
| 98 | if (name != 0 |
| 99 | && *name == 'k' |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 100 | && VALID_STRING(value) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 101 | && NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx |
| 102 | value) == 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | (void) _nc_add_to_try(&(sp->_keytry), |
| 104 | value, |
| 105 | n - STRCOUNT + KEY_MAX); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | #endif |
| 110 | #ifdef TRACE |
| 111 | _nc_trace_tries(sp->_keytry); |
| 112 | #endif |
| 113 | } |
| 114 | } |