2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/* LINTLIBRARY */
2N/A
2N/A/*
2N/A * unctrl.c
2N/A *
2N/A * XCurses Library
2N/A *
2N/A * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A
2N/A#if M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] =
2N/A"$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
2N/A"libxcurses/src/libc/xcurses/rcs/unctrl.c 1.3 1998/05/29 15:58:55 "
2N/A"cbates Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <private.h>
2N/A#include <limits.h>
2N/A#include <ctype.h>
2N/A
2N/Astatic const char *carat[] = {
2N/A "^?",
2N/A "^@",
2N/A "^A",
2N/A "^B",
2N/A "^C",
2N/A "^D",
2N/A "^E",
2N/A "^F",
2N/A "^G",
2N/A "^H",
2N/A "^I",
2N/A "^J",
2N/A "^K",
2N/A "^L",
2N/A "^M",
2N/A "^N",
2N/A "^O",
2N/A "^P",
2N/A "^Q",
2N/A "^R",
2N/A "^S",
2N/A "^T",
2N/A "^U",
2N/A "^V",
2N/A "^W",
2N/A "^X",
2N/A "^Y",
2N/A "^Z",
2N/A "^[",
2N/A "^\\",
2N/A "^]",
2N/A "^^",
2N/A "^_"
2N/A};
2N/A
2N/Achar *
2N/Aunctrl(chtype ch)
2N/A{
2N/A char *str;
2N/A int c, msb;
2N/A static char chr[5];
2N/A
2N/A
2N/A /* Map wide character to a wide string. */
2N/A c = (int)(ch & A_CHARTEXT);
2N/A msb = 1 << (CHAR_BIT-1);
2N/A
2N/A if (c & ~((1 << CHAR_BIT) - 1)) {
2N/A /* Only know about single-byte characters I guess ... */
2N/A return (NULL);
2N/A }
2N/A if (iscntrl(c)) {
2N/A /* ASCII DEL */
2N/A if (c == 127)
2N/A return ((char *)carat[0]);
2N/A
2N/A /* ASCII control codes. */
2N/A if (0 <= c && c < 32)
2N/A return ((char *)carat[c+1]);
2N/A
2N/A /* Something we don't know what to do with. */
2N/A return (NULL);
2N/A } else if (c & msb) {
2N/A /* Meta key notation if high bit is set on character. */
2N/A c &= ~msb;
2N/A
2N/A chr[0] = 'M';
2N/A chr[1] = '-';
2N/A
2N/A if (iscntrl(c)) {
2N/A str = (char *) unctrl(c);
2N/A chr[2] = *str++;
2N/A chr[3] = *str;
2N/A chr[4] = '\0';
2N/A } else {
2N/A chr[2] = (char)c;
2N/A chr[3] = '\0';
2N/A }
2N/A } else {
2N/A /* Return byte as is. */
2N/A chr[0] = (char)c;
2N/A chr[1] = '\0';
2N/A }
2N/A
2N/A return (chr);
2N/A}