2 Copyright 1985, 1987, 1990, 1998 The Open Group
3 Copyright 2008 Dan Nicholson
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the names of the authors or their
23 institutions shall not be used in advertising or otherwise to promote the
24 sale, use or other dealings in this Software without prior written
25 authorization from the authors.
33 #include "ks_tables.h"
36 xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size)
39 const unsigned char *entry;
40 unsigned char val1, val2, val3, val4;
42 if ((ks & ((unsigned long) ~0x1fffffff)) != 0) {
43 snprintf(buffer, size, "Invalid");
47 /* Not listed in keysymdef.h for hysterical raisins. */
48 if (ks == XKB_KEY_NoSymbol) {
49 snprintf(buffer, size, "NoSymbol");
53 /* Try to find it in our hash table. */
54 if (ks <= 0x1fffffff) {
56 val2 = (ks >> 16) & 0xff;
57 val3 = (ks >> 8) & 0xff;
63 while ((idx = hashKeysym[i])) {
64 entry = &_XkeyTable[idx];
66 if ((entry[0] == val1) && (entry[1] == val2) &&
67 (entry[2] == val3) && (entry[3] == val4)) {
68 snprintf(buffer, size, "%s", entry + 4);
81 if (ks >= 0x01000100 && ks <= 0x0110ffff)
82 /* Unnamed Unicode codepoint. */
83 snprintf(buffer, size, "U%lx", ks & 0xffffffUL);
85 /* Unnamed, non-Unicode, symbol (shouldn't generally happen). */
86 snprintf(buffer, size, "0x%08x", ks);
89 _X_EXPORT xkb_keysym_t
90 xkb_keysym_from_name(const char *s)
96 const unsigned char *entry;
97 unsigned char sig1, sig2;
101 sig = (sig << 1) + c;
103 i = sig % KTABLESIZE;
105 sig1 = (sig >> 8) & 0xff;
109 while ((idx = hashString[i])) {
110 entry = &_XkeyTable[idx];
112 if ((entry[0] == sig1) && (entry[1] == sig2) &&
113 !strcmp(s, (const char *)entry + 6))
115 val = (entry[2] << 24) | (entry[3] << 16) |
116 (entry[4] << 8) | entry[5];
118 val = XKB_KEY_VoidSymbol;
131 val = strtoul(&s[1], &tmp, 16);
132 if (tmp && *tmp != '\0')
133 return XKB_KEY_NoSymbol;
135 if (val < 0x20 || (val > 0x7e && val < 0xa0))
136 return XKB_KEY_NoSymbol;
140 return XKB_KEY_NoSymbol;
141 return val | 0x01000000;
143 else if (s[0] == '0' && s[1] == 'x') {
144 val = strtoul(&s[2], &tmp, 16);
145 if (tmp && *tmp != '\0')
146 return XKB_KEY_NoSymbol;
151 /* Stupid inconsistency between the headers and XKeysymDB: the former has
152 * no separating underscore, while some XF86* syms in the latter did.
153 * As a last ditch effort, try without. */
154 if (strncmp(s, "XF86_", 5) == 0) {
158 return XKB_KEY_NoSymbol;
159 memmove(&tmp[4], &tmp[5], strlen(s) - 5 + 1);
160 ret = xkb_keysym_from_name(tmp);
165 return XKB_KEY_NoSymbol;