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. */
33 #include <X11/keysymdef.h>
38 typedef uint32_t Signature;
50 static char tab[KTNUM];
51 static unsigned short offsets[KTNUM];
52 static unsigned short indexes[KTNUM];
53 static KeySym values[KTNUM];
56 * XFree86 special action keys - for some reason, these have an
57 * underscore after the XF86 prefix.
59 static const char *xf86_special_keys[] = {
80 is_xf86_special(const char *key)
82 const char **s = xf86_special_keys;
84 if (strcmp(key, *s) == 0)
92 get_keysym(const char *buf, char *key, int ndx)
94 if (sscanf(buf, "#define XK_%127s 0x%lx", key, &info[ndx].val) != 2)
100 get_keysym_alias(const char *buf, char *key, int ndx)
105 if (sscanf(buf, "#define XK_%127s XK_%127s", key, alias) != 2)
108 for (i = ndx - 1; i >= 0; i--) {
109 if (strcmp(info[i].name, alias) == 0) {
110 info[ndx].val = info[i].val;
115 /* Didn't find a match */
116 fprintf(stderr, "can't find matching definition %s for keysym %s\n",
122 get_xf86_keysym(const char *buf, char *key, size_t len, int ndx)
126 if (sscanf(buf, "#define XF86XK_%127s 0x%lx", tmp, &info[ndx].val) != 2)
129 /* Prepend XF86 or XF86_ to the key */
130 snprintf(key, len, "XF86%s%s", is_xf86_special(tmp) ? "_" : "", tmp);
136 get_xf86_keysym_alias(const char *buf, char *key, size_t len, int ndx)
139 char alias[128], ktmp[128], atmp[128];
141 /* Try to handle both XF86XK and XK aliases */
142 if (sscanf(buf, "#define XF86XK_%127s XF86XK_%127s", ktmp, atmp) == 2) {
143 /* Prepend XF86 to the key and alias */
144 snprintf(key, len, "XF86%s%s", is_xf86_special(ktmp) ? "_" : "",
146 snprintf(alias, sizeof(alias), "XF86%s%s",
147 is_xf86_special(atmp) ? "_" : "", atmp);
149 if (sscanf(buf, "#define XF86XK_%127s XK_%127s", ktmp, alias) != 2)
151 /* Prepend XF86 to the key */
152 snprintf(key, len, "XF86%s%s", is_xf86_special(ktmp) ? "_" : "",
156 for (i = ndx - 1; i >= 0; i--) {
157 if (strcmp(info[i].name, alias) == 0) {
158 info[ndx].val = info[i].val;
163 /* Didn't find a match */
164 fprintf(stderr, "can't find matching definition %s for keysym %s\n",
170 main(int argc, char *argv[])
187 while (fgets(buf, sizeof(buf), stdin)) {
190 /* Manage keysyms from keysymdef.h */
191 ret = get_keysym(buf, key, ksnum);
193 ret = get_keysym_alias(buf, key, ksnum);
198 /* Manage keysyms from XF86keysym.h */
200 ret = get_xf86_keysym(buf, key, sizeof(key), ksnum);
202 ret = get_xf86_keysym_alias(buf, key, sizeof(key), ksnum);
207 if (info[ksnum].val > 0x1fffffff) {
209 "ignoring illegal keysym (%s), remove it from .h file!\n",
213 name = malloc((unsigned)strlen(key) + 1);
215 fprintf(stderr, "makekeys: out of memory!\n");
218 (void)strcpy(name, key);
219 info[ksnum].name = name;
221 if (ksnum == KTNUM) {
222 fprintf(stderr, "makekeys: too many keysyms!\n");
227 /* Special case NoSymbol. */
228 info[ksnum].name = strdup("NoSymbol");
229 info[ksnum].val = 0L;
232 printf("/* This file is generated from keysymdef.h. */\n");
233 printf("/* Do not edit. */\n");
236 best_max_rehash = ksnum;
238 for (z = ksnum; z < KTNUM; z++) {
240 for (name = tab, i = z; --i >= 0;)
242 for (i = 0; i < ksnum; i++) {
245 while ((c = *name++))
246 sig = (sig << 1) + c;
248 for (k = 0; tab[j]; k++) {
259 if (max_rehash < MIN_REHASH) {
260 if (max_rehash < best_max_rehash) {
261 best_max_rehash = max_rehash;
265 if (num_found >= MATCHES)
272 printf("#ifndef KS_TABLES_H\n");
273 printf("#define KS_TABLES_H\n\n");
274 printf("static const unsigned char _XkeyTable[] = {\n");
276 fprintf(stderr, "makekeys: failed to find small enough hash!\n"
277 "Try increasing KTNUM in makekeys.c\n");
282 for (i = 0; i < ksnum; i++) {
285 while ((c = *name++))
286 sig = (sig << 1) + c;
296 printf("0x%.2"PRIx32", 0x%.2"PRIx32", 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, ",
297 (sig >> 8) & 0xff, sig & 0xff,
298 (val >> 24) & 0xff, (val >> 16) & 0xff,
299 (val >> 8) & 0xff, val & 0xff);
300 for (name = info[i].name, k += 7; (c = *name++); k++)
302 printf((i == (ksnum-1)) ? "0\n" : "0,\n");
306 printf("#define KTABLESIZE %d\n", z);
307 printf("#define KMAXHASH %d\n", best_max_rehash + 1);
309 printf("static const unsigned short hashString[KTABLESIZE] = {\n");
310 for (i = 0; i < z;) {
311 printf("0x%.4x", offsets[i]);
315 printf((i & 7) ? ", " : ",\n");
320 best_max_rehash = ksnum;
322 for (z = ksnum; z < KTNUM; z++) {
324 for (name = tab, i = z; --i >= 0;)
326 for (i = 0; i < ksnum; i++) {
329 for (k = 0; tab[j]; k++) {
330 if (values[j] == val)
344 if (max_rehash < MIN_REHASH) {
345 if (max_rehash < best_max_rehash) {
346 best_max_rehash = max_rehash;
350 if (num_found >= MATCHES)
358 fprintf(stderr, "makekeys: failed to find small enough hash!\n"
359 "Try increasing KTNUM in makekeys.c\n");
362 for (i = z; --i >= 0;)
364 for (i = 0; i < ksnum; i++) {
368 if (values[j] == val)
374 offsets[j] = indexes[i] + 2;
379 printf("#define VTABLESIZE %d\n", z);
380 printf("#define VMAXHASH %d\n", best_max_rehash + 1);
382 printf("static const unsigned short hashKeysym[VTABLESIZE] = {\n");
383 for (i = 0; i < z;) {
384 printf("0x%.4x", offsets[i]);
388 printf((i & 7) ? ", " : ",\n");
392 printf("\n#endif /* KS_TABLES_H */\n");