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.
32 #include <X11/keysymdef.h>
34 #include "X11/extensions/XKBcommon.h"
38 #include "ks_tables.h"
41 XkbcKeysymToString(KeySym ks)
44 const unsigned char *entry;
45 unsigned char val1, val2, val3, val4;
47 if (!ks || (ks & ((unsigned long) ~0x1fffffff)) != 0)
50 if (ks == XK_VoidSymbol)
53 if (ks <= 0x1fffffff) {
55 val2 = (ks >> 16) & 0xff;
56 val3 = (ks >> 8) & 0xff;
62 while ((idx = hashKeysym[i])) {
63 entry = &_XkeyTable[idx];
65 if ((entry[0] == val1) && (entry[1] == val2) &&
66 (entry[2] == val3) && (entry[3] == val4))
67 return ((char *)entry + 4);
78 if (ks >= 0x01000100 && ks <= 0x0110ffff) {
79 KeySym val = ks & 0xffffff;
100 s[i] = 'A' + val1 - 10;
110 XkbcStringToKeysym(const char *s)
113 unsigned long sig = 0;
115 const unsigned char *entry;
116 unsigned char sig1, sig2;
120 sig = (sig << 1) + c;
122 i = sig % KTABLESIZE;
124 sig1 = (sig >> 8) & 0xff;
128 while ((idx = hashString[i])) {
129 entry = &_XkeyTable[idx];
131 if ((entry[0] == sig1) && (entry[1] == sig2) &&
132 !strcmp(s, (char *)entry + 6))
134 val = (entry[2] << 24) | (entry[3] << 16) |
135 (entry[4] << 8) | entry[5];
152 for (p = &s[1]; *p; p++) {
155 if ('0' <= c && c <= '9')
156 val = (val << 4) + c - '0';
157 else if ('a' <= c && c <= 'f')
158 val = (val << 4) + c - 'a' + 10;
159 else if ('A' <= c && c <= 'F')
160 val = (val << 4) + c - 'A' + 10;
168 if (val < 0x20 || (val > 0x7e && val < 0xa0))
172 return val | 0x01000000;