1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /* LINTLIBRARY */
28
29 /*
30 * wunctrl.c
31 *
32 * XCurses Library
33 *
34 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
35 *
36 */
37
38 #if M_RCSID
39 #ifndef lint
40 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/wunctrl.c 1.1 "
41 "1995/05/16 15:15:37 ant Exp $";
42 #endif
43 #endif
44
45 #include <private.h>
46
47 static const wchar_t *carat[] = {
48 L"^?",
49 L"^@",
50 L"^A",
51 L"^B",
52 L"^C",
53 L"^D",
54 L"^E",
55 L"^F",
56 L"^G",
57 L"^H",
58 L"^I",
59 L"^J",
60 L"^K",
61 L"^L",
62 L"^M",
63 L"^N",
64 L"^O",
65 L"^P",
66 L"^Q",
67 L"^R",
68 L"^S",
69 L"^T",
70 L"^U",
71 L"^V",
72 L"^W",
73 L"^X",
74 L"^Y",
75 L"^Z",
76 L"^[",
77 L"^\\",
78 L"^]",
79 L"^^",
80 L"^_"
81 };
82
83 wchar_t *
wunctrl(cchar_t * cc)84 wunctrl(cchar_t *cc)
85 {
86 int i;
87 wint_t wc;
88 static wchar_t wcs[_M_CCHAR_MAX + 1];
89
90 if (cc->_n <= 0)
91 return (NULL);
92
93 /* Map wide character to a wide string. */
94 wc = cc->_wc[0];
95 if (iswcntrl(wc)) {
96 if (wc == 127)
97 return ((wchar_t *)carat[0]);
98 if (0 <= wc && wc <= 32)
99 return ((wchar_t *)carat[wc+1]);
100 return (NULL);
101 }
102
103 for (i = 0; i < cc->_n; ++i)
104 wcs[i] = cc->_wc[i];
105 wcs[i] = L'\0';
106
107 return (wcs);
108 }
109