summaryrefslogtreecommitdiffstats
path: root/lib/libncurses/lib_unctrl.c
blob: b0f10c2b4ef584759df4bae339462a8836ca53ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifdef __FreeBSD__
#include <ctype.h>
#endif
#include <unctrl.h>

char *
 unctrl(register unsigned char uch)
{
    static char buffer[3] = "^x";

#ifdef __FreeBSD__
    if (isprint(uch)) {
#else
    if ((uch & 0x60) != 0 && uch != 0x7F) {
#endif
	/*
	 * Printable character. Simply return the character as a one-character
	 * string.
	 */
	buffer[1] = uch;
	return &buffer[1];
    }
    uch &= ~0x80;
    /*
     * It is a control character. DEL is handled specially (^?). All others
     * use ^x notation, where x is the character code for the control character
     * with 0x40 ORed in. (Control-A becomes ^A etc.).
     */ buffer[1] = (uch == 0x7F ? '?' : (uch | 0x40));

    return buffer;

}
OpenPOWER on IntegriCloud