-
Notifications
You must be signed in to change notification settings - Fork 1
/
cinfo.c
129 lines (122 loc) · 3.01 KB
/
cinfo.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Character class tables.
*
* Do it yourself character classification macros, that understand the
* multinational character set, and let me ask some questions the
* standard macros (in ctype.h) don't let you ask.
*/
#include "def.h"
/*
* This table, indexed by a character drawn from the 256 member
* character set, is used by my own character type macros to answer
* questions about the type of a character.
*
* Mg3a: Tweaked to be useful for Mg3a when the locale isn't
* recognized.
*/
const uint_least8_t cinfo[256] = {
_C, _C, _C, _C, /* 0x0X */
_C, _C, _C, _C,
_C, _C|_S, _C|_S, _C|_S,
_C|_S, _C|_S, _C, _C,
_C, _C, _C, _C, /* 0x1X */
_C, _C, _C, _C,
_C, _C, _C, _C,
_C, _C, _C, _C,
_S, 0, 0, 0, /* 0x2X */
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
_D|_W, _D|_W, _D|_W, _D|_W, /* 0x3X */
_D|_W, _D|_W, _D|_W, _D|_W,
_D|_W, _D|_W, 0, 0,
0, 0, 0, 0,
0, _U|_W, _U|_W, _U|_W, /* 0x4X */
_U|_W, _U|_W, _U|_W, _U|_W,
_U|_W, _U|_W, _U|_W, _U|_W,
_U|_W, _U|_W, _U|_W, _U|_W,
_U|_W, _U|_W, _U|_W, _U|_W, /* 0x5X */
_U|_W, _U|_W, _U|_W, _U|_W,
_U|_W, _U|_W, _U|_W, 0,
0, 0, 0, 0,
0, _L|_W, _L|_W, _L|_W, /* 0x6X */
_L|_W, _L|_W, _L|_W, _L|_W,
_L|_W, _L|_W, _L|_W, _L|_W,
_L|_W, _L|_W, _L|_W, _L|_W,
_L|_W, _L|_W, _L|_W, _L|_W, /* 0x7X */
_L|_W, _L|_W, _L|_W, _L|_W,
_L|_W, _L|_W, _L|_W, 0,
0, 0, 0, _C,
_W, _W, _W, _W, /* 0x8X */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0x9X */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0xAX */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0xBX */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0xCX */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0xDX */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0xEX */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W, /* 0xFX */
_W, _W, _W, _W,
_W, _W, _W, _W,
_W, _W, _W, _W,
};
/*
* Find the name of a keystroke. Returns a pointer to the terminating
* '\0'.
*/
char *
keyname(char *cp, INT k)
{
char *np;
if(k < 0) k = CHARMASK(k); /* sign extended char */
switch(k) {
// case CCHR('@'): np = "NUL"; break;
case CCHR('I'): np = "TAB"; break;
// case CCHR('J'): np = "LFD"; break; /* yuck, but that's what GNU calls it */
case CCHR('M'): np = "RET"; break;
case CCHR('['): np = "ESC"; break;
case ' ': np = "SPC"; break; /* yuck again */
case CCHR('?'): np = "DEL"; break;
default:
if (k >= 128) {
if (termcharset) {
sprintf(cp, "U+%04X", (int)k);
} else {
sprintf(cp, "0%o", (int)k);
}
cp += strlen(cp);
return cp;
}
if(k < ' ') {
*cp++ = 'C';
*cp++ = '-';
k = CCHR(k);
if(ISUPPER(k)) k = TOLOWER(k);
}
*cp++ = k;
*cp = '\0';
return cp;
}
strcpy(cp, np);
return cp + strlen(cp);
}