1174993Srafan/**************************************************************************** 2174993Srafan * Copyright (c) 2007 Free Software Foundation, Inc. * 3174993Srafan * * 4174993Srafan * Permission is hereby granted, free of charge, to any person obtaining a * 5174993Srafan * copy of this software and associated documentation files (the * 6174993Srafan * "Software"), to deal in the Software without restriction, including * 7174993Srafan * without limitation the rights to use, copy, modify, merge, publish, * 8174993Srafan * distribute, distribute with modifications, sublicense, and/or sell * 9174993Srafan * copies of the Software, and to permit persons to whom the Software is * 10174993Srafan * furnished to do so, subject to the following conditions: * 11174993Srafan * * 12174993Srafan * The above copyright notice and this permission notice shall be included * 13174993Srafan * in all copies or substantial portions of the Software. * 14174993Srafan * * 15174993Srafan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16174993Srafan * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17174993Srafan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18174993Srafan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19174993Srafan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20174993Srafan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21174993Srafan * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22174993Srafan * * 23174993Srafan * Except as contained in this notice, the name(s) of the above copyright * 24174993Srafan * holders shall not be used in advertising or otherwise to promote the * 25174993Srafan * sale, use or other dealings in this Software without prior written * 26174993Srafan * authorization. * 27174993Srafan ****************************************************************************/ 28174993Srafan 29174993Srafan/* 30174993Srafan** lib_key_name.c 31174993Srafan** 32174993Srafan** The routine key_name(). 33174993Srafan** 34174993Srafan*/ 35174993Srafan 36174993Srafan#include <curses.priv.h> 37174993Srafan 38184989SrafanMODULE_ID("$Id: lib_key_name.c,v 1.3 2008/10/11 20:15:14 tom Exp $") 39174993Srafan 40174993SrafanNCURSES_EXPORT(NCURSES_CONST char *) 41174993Srafankey_name(wchar_t c) 42174993Srafan{ 43174993Srafan cchar_t my_cchar; 44174993Srafan wchar_t *my_wchars; 45174993Srafan size_t len; 46174993Srafan 47174993Srafan /* FIXME: move to _nc_globals */ 48174993Srafan static char result[MB_LEN_MAX + 1]; 49174993Srafan 50174993Srafan memset(&my_cchar, 0, sizeof(my_cchar)); 51174993Srafan my_cchar.chars[0] = c; 52174993Srafan my_cchar.chars[1] = L'\0'; 53174993Srafan 54174993Srafan my_wchars = wunctrl(&my_cchar); 55174993Srafan len = wcstombs(result, my_wchars, sizeof(result) - 1); 56174993Srafan if (isEILSEQ(len) || (len == 0)) { 57184989Srafan return 0; 58174993Srafan } 59174993Srafan 60174993Srafan result[len] = '\0'; 61174993Srafan return result; 62174993Srafan} 63