1 /* Portions of this code are Copyright 1990, 1998 The Open Group
3 Permission to use, copy, modify, distribute, and sell this software and its
4 documentation for any purpose is hereby granted without fee, provided that
5 the above copyright notice appear in all copies and that both that
6 copyright notice and this permission notice appear in supporting
9 The above copyright notice and this permission notice shall be included
10 in all copies or substantial portions of the Software.
12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
16 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
17 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
18 OTHER DEALINGS IN THE SOFTWARE.
20 Except as contained in this notice, the name of The Open Group shall
21 not be used in advertising or otherwise to promote the sale, use or
22 other dealings in this Software without prior written authorization
30 #include <X11/keysymdef.h>
36 typedef struct _Info Info;
40 long unsigned int val;
43 /* local function prototypes */
44 static int _parseline(const char *buf, char *key, long unsigned int *val, char *prefix);
47 static char tab[TBLNUM];
48 static unsigned short offsets[TBLNUM];
49 static unsigned short indexes[TBLNUM];
50 static long unsigned int values[TBLNUM];
51 static char buf[1024];
55 main(int argc, char **argv)
59 int i = 0, j = 0, k = 0, l = 0, z = 0;
62 int first = 0, num_found = 0;
63 int best_max_rehash = 0, best_z = 0;
64 long unsigned int val;
65 char key[128], prefix[128];
67 for (l = 1; l < argc; l++)
69 if (!(fptr = fopen(argv[l], "r")))
71 fprintf(stderr, "Could not open %s\n", argv[l]);
75 while (fgets(buf, sizeof(buf), fptr))
77 if (!_parseline(buf, key, &val, prefix))
80 if (val == XK_VoidSymbol) val = 0;
83 fprintf(stderr, "Ignoring illegal keysym (%s %lx)\n",
88 if (!(name = malloc(strlen(prefix) + strlen(key) + 1)))
90 fprintf(stderr, "Makekeys: Out Of Memory !!\n");
94 sprintf(name, "%s%s", prefix, key);
95 info[ksnum].name = name;
96 info[ksnum].val = val;
100 fprintf(stderr, "Makekeys: Too Many Keysyms!!\n");
108 printf("/* This file is generated from keysymdef.h. */\n");
109 printf("/* Do Not Edit !! */\n\n");
111 best_max_rehash = ksnum;
113 for (z = ksnum; z < TBLNUM; z++)
116 for (name = tab, i = z; --i >= 0;)
118 for (i = 0; i < ksnum; i++)
122 while ((c = *name++))
123 sig = (sig << 1) + c;
125 for (k = 0; tab[j]; k++)
129 if (j == first) goto next1;
132 if (k > max_rehash) max_rehash = k;
134 if (max_rehash < MIN_REHASH)
136 if (max_rehash < best_max_rehash)
138 best_max_rehash = max_rehash;
142 if (num_found >= MATCHES)
151 fprintf(stderr, "Makekeys: Failed to find small enough hash !!\n"
152 "Try increasing TBLNUM in makekeys.c\n");
156 printf("#ifdef NEED_KEYSYM_TABLE\n");
157 printf("const unsigned char _ecore_xcb_keytable[] = {\n");
160 for (i = 0; i < ksnum; i++)
164 while ((c = *name++))
165 sig = (sig << 1) + c;
175 printf("0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, ",
176 (sig >> 8) & 0xff, sig & 0xff,
177 (val >> 24) & 0xff, (val >> 16) & 0xff,
178 (val >> 8) & 0xff, val & 0xff);
179 for (name = info[i].name, k += 7; (c = *name++); k++)
181 printf((i == (ksnum - 1)) ? "0\n" : "0,\n");
185 printf("#define KTABLESIZE %d\n", z);
186 printf("#define KMAXHASH %d\n", (best_max_rehash + 1));
188 printf("static const unsigned short hashString[KTABLESIZE] = {\n");
192 printf("0x%.4x", offsets[i]);
195 printf((i & 7) ? ", " : ",\n");
202 best_max_rehash = ksnum;
204 for (z = ksnum; z < TBLNUM; z++)
207 for (name = tab, i = z; --i >= 0;)
209 for (i = 0; i < ksnum; i++)
213 for (k = 0; tab[j]; k++)
215 if (values[j] == val) goto skip1;
218 if (j == first) goto next2;
222 if (k > max_rehash) max_rehash = k;
225 if (max_rehash < MIN_REHASH)
227 if (max_rehash < best_max_rehash)
229 best_max_rehash = max_rehash;
233 if (num_found >= MATCHES) break;
241 fprintf(stderr, "Makekeys: Failed to find small enough hash !!\n"
242 "Try increasing TBLNUM in makekeys.c\n");
245 for (i = z; --i >= 0;)
248 for (i = 0; i < ksnum; i++)
254 if (values[j] == val) goto skip2;
258 offsets[j] = indexes[i] + 2;
264 printf("#ifdef NEED_VTABLE\n");
265 printf("#define VTABLESIZE %d\n", z);
266 printf("#define VMAXHASH %d\n", best_max_rehash + 1);
268 printf("static const unsigned short hashKeysym[VTABLESIZE] = {\n");
271 printf("0x%.4x", offsets[i]);
274 printf((i & 7) ? ", " : ",\n");
283 /* local functions */
285 _parseline(const char *buf, char *key, long unsigned int *val, char *prefix)
289 char *tmp = NULL, *tmpa = NULL;
291 /* try to match XK_foo first */
292 i = sscanf(buf, "#define %127s 0x%lx", key, val);
293 if ((i == 2) && (tmp = strstr(key, "XK_")))
295 memcpy(prefix, key, (tmp - key));
296 prefix[tmp - key] = '\0';
298 memmove(key, tmp, strlen(tmp) + 1);
302 /* try to match an alias */
303 i = sscanf(buf, "#define %127s %127s", key, alias);
304 if (((i == 2) && (tmp = strstr(key, "XK_"))) &&
305 (tmpa = strstr(alias, "XK_")))
307 memcpy(prefix, key, (tmp - key));
308 prefix[tmp - key] = '\0';
310 memmove(key, tmp, strlen(tmp) + 1);
311 memmove(tmpa, tmpa + 3, strlen(tmpa + 3) + 1);
313 for (i = ksnum - 1; i >= 0; i--)
315 if (!strcmp(info[i].name, alias))
321 fprintf(stderr, "Cannot find matching definition %s for keysym %s%s\n",