xref: /openbsd/lib/libcurses/base/keybound.c (revision c7ef0cfc)
1*c7ef0cfcSnicm /* $OpenBSD: keybound.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
2c21ba70dSmillert 
3c21ba70dSmillert /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2020 Thomas E. Dickey                                          *
5*c7ef0cfcSnicm  * Copyright 1999-2009,2011 Free Software Foundation, Inc.                  *
6c21ba70dSmillert  *                                                                          *
7c21ba70dSmillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
8c21ba70dSmillert  * copy of this software and associated documentation files (the            *
9c21ba70dSmillert  * "Software"), to deal in the Software without restriction, including      *
10c21ba70dSmillert  * without limitation the rights to use, copy, modify, merge, publish,      *
11c21ba70dSmillert  * distribute, distribute with modifications, sublicense, and/or sell       *
12c21ba70dSmillert  * copies of the Software, and to permit persons to whom the Software is    *
13c21ba70dSmillert  * furnished to do so, subject to the following conditions:                 *
14c21ba70dSmillert  *                                                                          *
15c21ba70dSmillert  * The above copyright notice and this permission notice shall be included  *
16c21ba70dSmillert  * in all copies or substantial portions of the Software.                   *
17c21ba70dSmillert  *                                                                          *
18c21ba70dSmillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19c21ba70dSmillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20c21ba70dSmillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21c21ba70dSmillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22c21ba70dSmillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23c21ba70dSmillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24c21ba70dSmillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
25c21ba70dSmillert  *                                                                          *
26c21ba70dSmillert  * Except as contained in this notice, the name(s) of the above copyright   *
27c21ba70dSmillert  * holders shall not be used in advertising or otherwise to promote the     *
28c21ba70dSmillert  * sale, use or other dealings in this Software without prior written       *
29c21ba70dSmillert  * authorization.                                                           *
30c21ba70dSmillert  ****************************************************************************/
31c21ba70dSmillert 
32c21ba70dSmillert /****************************************************************************
3381d8c4e1Snicm  *  Author: Thomas E. Dickey                        1999-on                 *
34*c7ef0cfcSnicm  *     and: Juergen Pfeifer                         2009                    *
35c21ba70dSmillert  ****************************************************************************/
36c21ba70dSmillert 
37c21ba70dSmillert #include <curses.priv.h>
38c21ba70dSmillert 
39*c7ef0cfcSnicm MODULE_ID("$Id: keybound.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
40c21ba70dSmillert 
41c21ba70dSmillert /*
42c21ba70dSmillert  * Returns the count'th string definition which is associated with the
43c21ba70dSmillert  * given keycode.  The result is malloc'd, must be freed by the caller.
44c21ba70dSmillert  */
NCURSES_EXPORT(char *)4584af20ceSmillert NCURSES_EXPORT(char *)
46*c7ef0cfcSnicm NCURSES_SP_NAME(keybound) (NCURSES_SP_DCLx int code, int count)
47c21ba70dSmillert {
4881d8c4e1Snicm     char *result = 0;
4981d8c4e1Snicm 
50*c7ef0cfcSnicm     T((T_CALLED("keybound(%p, %d,%d)"), (void *) SP_PARM, code, count));
51*c7ef0cfcSnicm     if (SP_PARM != 0 && code >= 0) {
52*c7ef0cfcSnicm 	result = _nc_expand_try(SP_PARM->_keytry,
53*c7ef0cfcSnicm 				(unsigned) code,
54*c7ef0cfcSnicm 				&count,
55*c7ef0cfcSnicm 				(size_t) 0);
56b09fd9d5Sespie     }
5781d8c4e1Snicm     returnPtr(result);
58c21ba70dSmillert }
59*c7ef0cfcSnicm 
60*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
61*c7ef0cfcSnicm NCURSES_EXPORT(char *)
keybound(int code,int count)62*c7ef0cfcSnicm keybound(int code, int count)
63*c7ef0cfcSnicm {
64*c7ef0cfcSnicm     return NCURSES_SP_NAME(keybound) (CURRENT_SCREEN, code, count);
65*c7ef0cfcSnicm }
66*c7ef0cfcSnicm #endif
67