1/****************************************************************************
2 * Copyright 2020 Thomas E. Dickey                                          *
3 * Copyright 2001-2011,2012 Free Software Foundation, Inc.                  *
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/*
31**	lib_wunctrl.c
32**
33**	The routine wunctrl().
34**
35*/
36
37#include <curses.priv.h>
38
39MODULE_ID("$Id: lib_wunctrl.c,v 1.17 2020/02/02 23:34:34 tom Exp $")
40
41NCURSES_EXPORT(wchar_t *)
42NCURSES_SP_NAME(wunctrl) (NCURSES_SP_DCLx cchar_t *wc)
43{
44    static wchar_t str[CCHARW_MAX + 1], *wsp;
45    wchar_t *result;
46
47    if (wc == 0) {
48	result = 0;
49    } else if (SP_PARM != 0 && Charable(*wc)) {
50	const char *p =
51	NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx
52				 (unsigned) _nc_to_char((wint_t)CharOf(*wc)));
53
54	for (wsp = str; *p; ++p) {
55	    *wsp++ = (wchar_t) _nc_to_widechar(*p);
56	}
57	*wsp = 0;
58	result = str;
59    } else {
60	result = wc->chars;
61    }
62    return result;
63}
64
65#if NCURSES_SP_FUNCS
66NCURSES_EXPORT(wchar_t *)
67wunctrl(cchar_t *wc)
68{
69    return NCURSES_SP_NAME(wunctrl) (CURRENT_SCREEN, wc);
70}
71#endif
72