]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/init_keytry.c
ncurses 5.7 - patch 20090808
[ncurses.git] / ncurses / tinfo / init_keytry.c
1 /****************************************************************************
2  * Copyright (c) 1999-2008,2009 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 #include <curses.priv.h>
30 #include <tic.h>                /* struct tinfo_fkeys */
31
32 #include <term_entry.h>
33
34 MODULE_ID("$Id: init_keytry.c,v 1.14 2009/05/10 00:48:29 tom Exp $")
35
36 /*
37 **      _nc_init_keytry()
38 **
39 **      Construct the try for the current terminal's keypad keys.
40 **
41 */
42
43 /*
44  * Internal entrypoints use SCREEN* parameter to obtain capabilities rather
45  * than cur_term.
46  */
47 #undef CUR
48 #define CUR SP_TERMTYPE 
49
50 #if     BROKEN_LINKER
51 #undef  _nc_tinfo_fkeys
52 #endif
53
54 /* LINT_PREPRO
55 #if 0*/
56 #include <init_keytry.h>
57 /* LINT_PREPRO
58 #endif*/
59
60 #if     BROKEN_LINKER
61 const struct tinfo_fkeys *
62 _nc_tinfo_fkeysf(void)
63 {
64     return _nc_tinfo_fkeys;
65 }
66 #endif
67
68 NCURSES_EXPORT(void)
69 _nc_init_keytry(SCREEN *sp)
70 {
71     size_t n;
72
73     /* The sp->_keytry value is initialized in newterm(), where the sp
74      * structure is created, because we can not tell where keypad() or
75      * mouse_activate() (which will call keyok()) are first called.
76      */
77
78     if (sp != 0) {
79         for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
80             if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
81                 (void) _nc_add_to_try(&(sp->_keytry),
82                                       CUR Strings[_nc_tinfo_fkeys[n].offset],
83                                       _nc_tinfo_fkeys[n].code);
84             }
85         }
86 #if NCURSES_XNAMES
87         /*
88          * Add any of the extended strings to the tries if their name begins
89          * with 'k', i.e., they follow the convention of other terminfo key
90          * names.
91          */
92         {
93             TERMTYPE *tp = &(sp->_term->type);
94             for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
95                 const char *name = ExtStrname(tp, n, strnames);
96                 char *value = tp->Strings[n];
97                 if (name != 0
98                     && *name == 'k'
99                     && value != 0
100                     && NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx
101                                                      value) == 0) {
102                     (void) _nc_add_to_try(&(sp->_keytry),
103                                           value,
104                                           n - STRCOUNT + KEY_MAX);
105                 }
106             }
107         }
108 #endif
109 #ifdef TRACE
110         _nc_trace_tries(sp->_keytry);
111 #endif
112     }
113 }