3 Copyright 1990, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
29 /* Constructs hash tables for XStringToKeysym and XKeysymToString. */
31 #include "xkbcommon/xkbcommon.h"
33 #include <X11/keysymdef.h>
39 typedef uint32_t Signature;
51 static char tab[KTNUM];
52 static unsigned short offsets[KTNUM];
53 static unsigned short indexes[KTNUM];
54 static xkb_keysym_t values[KTNUM];
58 parse_line(const char *buf, char *key, xkb_keysym_t *val, char *prefix)
64 /* See if we can catch a straight XK_foo 0x1234-style definition first;
65 * the trickery around tmp is to account for prefices. */
66 i = sscanf(buf, "#define %127s 0x%lx", key, val);
67 if (i == 2 && (tmp = strstr(key, "XK_"))) {
68 memcpy(prefix, key, tmp - key);
69 prefix[tmp - key] = '\0';
71 memmove(key, tmp, strlen(tmp) + 1);
75 /* Now try to catch alias (XK_foo XK_bar) definitions, and resolve them
76 * immediately: if the target is in the form XF86XK_foo, we need to
77 * canonicalise this to XF86foo before we do the lookup. */
78 i = sscanf(buf, "#define %127s %127s", key, alias);
79 if (i == 2 && (tmp = strstr(key, "XK_")) && (tmpa = strstr(alias, "XK_"))) {
80 memcpy(prefix, key, tmp - key);
81 prefix[tmp - key] = '\0';
83 memmove(key, tmp, strlen(tmp) + 1);
84 memmove(tmpa, tmpa + 3, strlen(tmpa + 3) + 1);
86 for (i = ksnum - 1; i >= 0; i--) {
87 if (strcmp(info[i].name, alias) == 0) {
93 fprintf(stderr, "can't find matching definition %s for keysym %s%s\n",
101 main(int argc, char *argv[])
114 char key[128], prefix[128];
117 for (l = 1; l < argc; l++) {
118 fptr = fopen(argv[l], "r");
120 fprintf(stderr, "couldn't open %s\n", argv[l]);
124 while (fgets(buf, sizeof(buf), fptr)) {
125 if (!parse_line(buf, key, &val, prefix))
128 if (val == XK_VoidSymbol)
130 if (val > 0x1fffffff) {
131 fprintf(stderr, "ignoring illegal keysym (%s, %lx)\n", key,
136 name = malloc(strlen(prefix) + strlen(key) + 1);
138 fprintf(stderr, "makekeys: out of memory!\n");
141 sprintf(name, "%s%s", prefix, key);
142 info[ksnum].name = name;
143 info[ksnum].val = val;
145 if (ksnum == KTNUM) {
146 fprintf(stderr, "makekeys: too many keysyms!\n");
154 /* Special case NoSymbol. */
155 info[ksnum].name = strdup("NoSymbol");
156 info[ksnum].val = 0L;
159 printf("/* This file is generated from keysymdef.h. */\n");
160 printf("/* Do not edit. */\n");
163 best_max_rehash = ksnum;
165 for (z = ksnum; z < KTNUM; z++) {
167 for (name = tab, i = z; --i >= 0;)
169 for (i = 0; i < ksnum; i++) {
172 while ((c = *name++))
173 sig = (sig << 1) + c;
175 for (k = 0; tab[j]; k++) {
186 if (max_rehash < MIN_REHASH) {
187 if (max_rehash < best_max_rehash) {
188 best_max_rehash = max_rehash;
192 if (num_found >= MATCHES)
199 printf("#ifndef KS_TABLES_H\n");
200 printf("#define KS_TABLES_H\n\n");
201 printf("static const unsigned char _XkeyTable[] = {\n");
203 fprintf(stderr, "makekeys: failed to find small enough hash!\n"
204 "Try increasing KTNUM in makekeys.c\n");
209 for (i = 0; i < ksnum; i++) {
212 while ((c = *name++))
213 sig = (sig << 1) + c;
223 printf("0x%.2"PRIx32", 0x%.2"PRIx32", 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, ",
224 (sig >> 8) & 0xff, sig & 0xff,
225 (val >> 24) & 0xff, (val >> 16) & 0xff,
226 (val >> 8) & 0xff, val & 0xff);
227 for (name = info[i].name, k += 7; (c = *name++); k++)
229 printf((i == (ksnum-1)) ? "0\n" : "0,\n");
233 printf("#define KTABLESIZE %d\n", z);
234 printf("#define KMAXHASH %d\n", best_max_rehash + 1);
236 printf("static const unsigned short hashString[KTABLESIZE] = {\n");
237 for (i = 0; i < z;) {
238 printf("0x%.4x", offsets[i]);
242 printf((i & 7) ? ", " : ",\n");
247 best_max_rehash = ksnum;
249 for (z = ksnum; z < KTNUM; z++) {
251 for (name = tab, i = z; --i >= 0;)
253 for (i = 0; i < ksnum; i++) {
256 for (k = 0; tab[j]; k++) {
257 if (values[j] == val)
271 if (max_rehash < MIN_REHASH) {
272 if (max_rehash < best_max_rehash) {
273 best_max_rehash = max_rehash;
277 if (num_found >= MATCHES)
285 fprintf(stderr, "makekeys: failed to find small enough hash!\n"
286 "Try increasing KTNUM in makekeys.c\n");
289 for (i = z; --i >= 0;)
291 for (i = 0; i < ksnum; i++) {
295 if (values[j] == val)
301 offsets[j] = indexes[i] + 2;
306 printf("#define VTABLESIZE %d\n", z);
307 printf("#define VMAXHASH %d\n", best_max_rehash + 1);
309 printf("static const unsigned short hashKeysym[VTABLESIZE] = {\n");
310 for (i = 0; i < z;) {
311 printf("0x%.4x", offsets[i]);
315 printf((i & 7) ? ", " : ",\n");
319 printf("\n#endif /* KS_TABLES_H */\n");