blob: ef20dfb1da08539dcead9a7748d2b134ed32b38b [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020,2023 Thomas E. Dickey *
3 * Copyright 1999-2010,2016 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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 Kachhape6a01f52011-07-20 11:45:59 +053031#include <tic.h> /* struct tinfo_fkeys */
32
micky3879b9f5e72025-07-08 18:04:53 -040033MODULE_ID("$Id: init_keytry.c,v 1.20 2023/09/16 12:55:01 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053034
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 Kondikae271bc2015-11-15 02:50:53 +010047#define CUR SP_TERMTYPE
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053048
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
60const struct tinfo_fkeys *
61_nc_tinfo_fkeysf(void)
62{
63 return _nc_tinfo_fkeys;
64}
65#endif
66
67NCURSES_EXPORT(void)
68_nc_init_keytry(SCREEN *sp)
69{
micky3879b9f5e72025-07-08 18:04:53 -040070 T(("_nc_init_keytry(%p)", (void *) sp));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053071
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) {
micky3879b9f5e72025-07-08 18:04:53 -040078 unsigned n;
79
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053080 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 Kondikae271bc2015-11-15 02:50:53 +010096 const char *name = ExtStrname(tp, (int) n, strnames);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097 char *value = tp->Strings[n];
98 if (name != 0
99 && *name == 'k'
micky3879b9f5e72025-07-08 18:04:53 -0400100 && VALID_STRING(value)
Steve Kondikae271bc2015-11-15 02:50:53 +0100101 && NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx
102 value) == 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530103 (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}