From 7b0bdde5c5ce290d52d6e6aba1cd73fe3130093a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 2 Aug 2016 00:51:13 +0200 Subject: update makekeys.c to libX11 1.3.4 (+ fix) --- nx-X11/lib/X11/util/makekeys.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib/X11/util') diff --git a/nx-X11/lib/X11/util/makekeys.c b/nx-X11/lib/X11/util/makekeys.c index 6cbce0693..ea8694d7d 100644 --- a/nx-X11/lib/X11/util/makekeys.c +++ b/nx-X11/lib/X11/util/makekeys.c @@ -33,9 +33,6 @@ from The Open Group. #include #include #include -#if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */ -char *malloc(); -#endif /* macII */ typedef unsigned long Signature; @@ -46,14 +43,14 @@ static struct info { KeySym val; } info[KTNUM]; -#define MIN_REHASH 10 +#define MIN_REHASH 15 #define MATCHES 10 -char tab[KTNUM]; -unsigned short offsets[KTNUM]; -unsigned short indexes[KTNUM]; -KeySym values[KTNUM]; -char buf[1024]; +static char tab[KTNUM]; +static unsigned short offsets[KTNUM]; +static unsigned short indexes[KTNUM]; +static KeySym values[KTNUM]; +static char buf[1024]; int main(int argc, char *argv[]) @@ -100,12 +97,11 @@ main(int argc, char *argv[]) key); continue; } - name = malloc((unsigned)strlen(key)+1); + name = strdup(key); if (!name) { fprintf(stderr, "makekeys: out of memory!\n"); exit(1); } - (void)strcpy(name, key); info[ksnum].name = name; ksnum++; if (ksnum == KTNUM) { -- cgit v1.2.3 From f573654008c47d8a9e8ea8bbb6d91edffa08ced2 Mon Sep 17 00:00:00 2001 From: James Cloos Date: Sat, 25 Oct 2008 09:13:08 -0400 Subject: Increase size of working arrays in the makekeys utility program. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makekeys is used to create an optimal hash of the keysyms defined in x11proto’s keysymdef.h. The recent addition of new keysyms there has triggered a bug in makekeys where it tries to use a zero on the rhs of the % (mod) operator (resulting in a divide by zero error) whenever it fails to find a solution within its constraints. Increasing the size of the arrays allows it to find a solution for the current set of keysyms. Makekeys is only run durring the build process, so this has no impact on users of libX11, only on the amount of VM needed to build it. It still needs a more complete fix, but this allows compiles to progress until that is completed. --- nx-X11/lib/X11/util/makekeys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib/X11/util') diff --git a/nx-X11/lib/X11/util/makekeys.c b/nx-X11/lib/X11/util/makekeys.c index ea8694d7d..0b515d758 100644 --- a/nx-X11/lib/X11/util/makekeys.c +++ b/nx-X11/lib/X11/util/makekeys.c @@ -36,7 +36,7 @@ from The Open Group. typedef unsigned long Signature; -#define KTNUM 3000 +#define KTNUM 4000 static struct info { char *name; -- cgit v1.2.3 From 70327993a44f2cfbe8ba46d42bdda7fea2327e1e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 17 Mar 2009 15:42:19 -0700 Subject: When makekeys fails to find a good hash, print error instead of divide-by-zero Signed-off-by: Alan Coopersmith --- nx-X11/lib/X11/util/makekeys.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'nx-X11/lib/X11/util') diff --git a/nx-X11/lib/X11/util/makekeys.c b/nx-X11/lib/X11/util/makekeys.c index 0b515d758..626abba6d 100644 --- a/nx-X11/lib/X11/util/makekeys.c +++ b/nx-X11/lib/X11/util/makekeys.c @@ -150,6 +150,11 @@ next1: ; } z = best_z; + if (z == 0) { + fprintf(stderr, "makekeys: failed to find small enough hash!\n" + "Try increasing KTNUM in makekeys.c\n"); + exit(1); + } printf("#ifdef NEEDKTABLE\n"); printf("const unsigned char _XkeyTable[] = {\n"); printf("0,\n"); @@ -230,6 +235,11 @@ next2: ; } z = best_z; + if (z == 0) { + fprintf(stderr, "makekeys: failed to find small enough hash!\n" + "Try increasing KTNUM in makekeys.c\n"); + exit(1); + } for (i = z; --i >= 0;) offsets[i] = 0; for (i = 0; i < ksnum; i++) { -- cgit v1.2.3 From c98265ab4634db314eeaa54e55ee8edb3c803967 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 15 Jun 2010 18:48:48 +0100 Subject: makekeys: Scan vendor keysyms as well as core Since we can't really live without vendor keysyms, scan them all in to generate ks_tables.h, rather than only doing the core ones, and leaving the vendor syms to be manually synchronised with XKeysymDB. Signed-off-by: Daniel Stone Reviewed-by: Alan Coopersmith --- nx-X11/lib/X11/util/makekeys.c | 127 +++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 44 deletions(-) (limited to 'nx-X11/lib/X11/util') diff --git a/nx-X11/lib/X11/util/makekeys.c b/nx-X11/lib/X11/util/makekeys.c index 626abba6d..55f8e346e 100644 --- a/nx-X11/lib/X11/util/makekeys.c +++ b/nx-X11/lib/X11/util/makekeys.c @@ -51,63 +51,102 @@ static unsigned short offsets[KTNUM]; static unsigned short indexes[KTNUM]; static KeySym values[KTNUM]; static char buf[1024]; +static int ksnum = 0; + +static int +parse_line(const char *buf, char *key, KeySym *val, char *prefix) +{ + int i; + char alias[128]; + char *tmp, *tmpa; + + /* See if we can catch a straight XK_foo 0x1234-style definition first; + * the trickery around tmp is to account for prefices. */ + i = sscanf(buf, "#define %127s 0x%lx", key, val); + if (i == 2 && (tmp = strstr(key, "XK_"))) { + memcpy(prefix, key, tmp - key); + prefix[tmp - key] = '\0'; + tmp += 3; + memmove(key, tmp, strlen(tmp) + 1); + return 1; + } + + /* Now try to catch alias (XK_foo XK_bar) definitions, and resolve them + * immediately: if the target is in the form XF86XK_foo, we need to + * canonicalise this to XF86foo before we do the lookup. */ + i = sscanf(buf, "#define %127s %127s", key, alias); + if (i == 2 && (tmp = strstr(key, "XK_")) && (tmpa = strstr(alias, "XK_"))) { + memcpy(prefix, key, tmp - key); + prefix[tmp - key] = '\0'; + tmp += 3; + memmove(key, tmp, strlen(tmp) + 1); + memmove(tmpa, tmpa + 3, strlen(tmpa + 3) + 1); + + for (i = ksnum - 1; i >= 0; i--) { + if (strcmp(info[i].name, alias) == 0) { + *val = info[i].val; + return 1; + } + } + + fprintf(stderr, "can't find matching definition %s for keysym %s%s\n", + alias, prefix, key); + } + + return 0; +} int main(int argc, char *argv[]) { - int ksnum = 0; int max_rehash; Signature sig; - register int i, j, k, z; - register char *name; - register char c; + int i, j, k, l, z; + FILE *fptr; + char *name; + char c; int first; int best_max_rehash; int best_z = 0; int num_found; KeySym val; - char key[128]; - char alias[128]; + char key[128], prefix[128]; + for (l = 1; l < argc; l++) { + fptr = fopen(argv[l], "r"); + if (!fptr) { + fprintf(stderr, "couldn't open %s\n", argv[l]); + continue; + } - while (fgets(buf, sizeof(buf), stdin)) { - i = sscanf(buf, "#define XK_%127s 0x%lx", key, &info[ksnum].val); - if (i != 2) { - i = sscanf(buf, "#define XK_%127s XK_%127s", key, alias); - if (i != 2) - continue; - for (i = ksnum - 1; i >= 0; i--) { - if (strcmp(info[i].name, alias) == 0) { - info[ksnum].val = info[i].val; - break; - } - } - if (i < 0) { /* Didn't find a match */ - fprintf(stderr, - "can't find matching definition %s for keysym %s\n", - alias, key); - continue; - } - } - if (info[ksnum].val == XK_VoidSymbol) - info[ksnum].val = 0; - if (info[ksnum].val > 0x1fffffff) { - fprintf(stderr, - "ignoring illegal keysym (%s), remove it from .h file!\n", - key); - continue; - } - name = strdup(key); - if (!name) { - fprintf(stderr, "makekeys: out of memory!\n"); - exit(1); - } - info[ksnum].name = name; - ksnum++; - if (ksnum == KTNUM) { - fprintf(stderr, "makekeys: too many keysyms!\n"); - exit(1); - } + while (fgets(buf, sizeof(buf), fptr)) { + if (!parse_line(buf, key, &val, prefix)) + continue; + + if (val == XK_VoidSymbol) + val = 0; + if (val > 0x1fffffff) { + fprintf(stderr, "ignoring illegal keysym (%s, %lx)\n", key, + val); + continue; + } + + name = malloc(strlen(prefix) + strlen(key) + 1); + if (!name) { + fprintf(stderr, "makekeys: out of memory!\n"); + exit(1); + } + sprintf(name, "%s%s", prefix, key); + info[ksnum].name = name; + info[ksnum].val = val; + ksnum++; + if (ksnum == KTNUM) { + fprintf(stderr, "makekeys: too many keysyms!\n"); + exit(1); + } + } + + fclose(fptr); } printf("/* This file is generated from keysymdef.h. */\n"); -- cgit v1.2.3 From 62e5b0ff80f91a66163386e2192bcb8e0b2d1721 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Thu, 22 Sep 2011 18:44:13 -0400 Subject: makekeys: Fix build/target word size mismatch when cross-compiling Since makekeys is built using build environment's gcc and runs natively, we have to make sure that the size of the Signature type is the same on both the native environment and the target, otherwise we get mismatches upon running X, and some LSB test failures (xts5). Use an unsigned 32-bit integer on all platforms. Also, eliminate the redundant multiple typedefs for the Signature type. Signed-off-by: Derek Buitenhuis Reviewed-by: Daniel Stone --- nx-X11/lib/X11/util/makekeys.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib/X11/util') diff --git a/nx-X11/lib/X11/util/makekeys.c b/nx-X11/lib/X11/util/makekeys.c index 55f8e346e..170ab5dee 100644 --- a/nx-X11/lib/X11/util/makekeys.c +++ b/nx-X11/lib/X11/util/makekeys.c @@ -30,11 +30,12 @@ from The Open Group. #include #include +#include #include #include #include -typedef unsigned long Signature; +#include "../Xresinternal.h" #define KTNUM 4000 @@ -212,7 +213,7 @@ next1: ; offsets[j] = k; indexes[i] = k; val = info[i].val; - printf("0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, ", + printf("0x%.2"PRIx32", 0x%.2"PRIx32", 0x%.2lx, 0x%.2lx, 0x%.2lx, 0x%.2lx, ", (sig >> 8) & 0xff, sig & 0xff, (val >> 24) & 0xff, (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff); -- cgit v1.2.3 From 6165dafdae0eaac74e46ffffb1ea85fcaa7a96a4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 13 Dec 2011 19:58:30 -0800 Subject: makekeys: move buf declaration from global to main to silence gcc -Wshadow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The global was only referenced in the main() function, which passes it as an argument of the same name to the parse_line() function, leading to gcc -Wshadow warnings: makekeys.c: In function ‘parse_line’: makekeys.c:58:24: warning: declaration of ‘buf’ shadows a global declaration makekeys.c:54:13: warning: shadowed declaration is here Signed-off-by: Alan Coopersmith --- nx-X11/lib/X11/util/makekeys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib/X11/util') diff --git a/nx-X11/lib/X11/util/makekeys.c b/nx-X11/lib/X11/util/makekeys.c index 170ab5dee..897b882dc 100644 --- a/nx-X11/lib/X11/util/makekeys.c +++ b/nx-X11/lib/X11/util/makekeys.c @@ -51,7 +51,6 @@ static char tab[KTNUM]; static unsigned short offsets[KTNUM]; static unsigned short indexes[KTNUM]; static KeySym values[KTNUM]; -static char buf[1024]; static int ksnum = 0; static int @@ -112,6 +111,7 @@ main(int argc, char *argv[]) int num_found; KeySym val; char key[128], prefix[128]; + static char buf[1024]; for (l = 1; l < argc; l++) { fptr = fopen(argv[l], "r"); -- cgit v1.2.3