summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2010-06-15 18:48:48 +0100
committerDaniel Stone <daniel@fooishbar.org>2010-09-20 16:03:58 +1000
commita32370c0854c8ad6f526dd997f14dbe3f466d4db (patch)
treeb0b34e8f59ea10536f42b897b6555e563d3b9c8d
parent77cb2bda308b39dc0a8267f18d92e7b4bf178aa1 (diff)
downloadxorg-lib-libX11-a32370c0854c8ad6f526dd997f14dbe3f466d4db.tar.gz
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 <daniel@fooishbar.org> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac21
-rw-r--r--src/Makefile.am6
-rw-r--r--src/util/makekeys.c127
3 files changed, 98 insertions, 56 deletions
diff --git a/configure.ac b/configure.ac
index 449af55f..d0b96d48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -354,15 +354,18 @@ AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], )
#
# Find keysymdef.h
#
-AC_MSG_CHECKING([keysymdef.h])
-dir=`$PKG_CONFIG --variable=includedir xproto`
-KEYSYMDEF="$dir/X11/keysymdef.h"
-if test -f "$KEYSYMDEF"; then
- AC_MSG_RESULT([$KEYSYMDEF])
-else
- AC_MSG_ERROR([Cannot find keysymdef.h])
-fi
-AC_SUBST(KEYSYMDEF)
+AC_MSG_CHECKING([keysym definitions])
+KEYSYMDEFDIR=`$PKG_CONFIG --variable=includedir xproto`/X11
+FILES="keysymdef.h XF86keysym.h Sunkeysym.h DECkeysym.h HPkeysym.h"
+for i in $FILES; do
+ if test -f "$KEYSYMDEFDIR/$i"; then
+ KEYSYMDEFS="$KEYSYMDEFS $KEYSYMDEFDIR/$i"
+ elif test "x$i" = "xkeysymdef.h"; then
+ AC_MSG_ERROR([Cannot find keysymdef.h])
+ fi
+done
+AC_MSG_RESULT([$KEYSYMDEFS])
+AC_SUBST(KEYSYMDEFS)
AM_CONDITIONAL(UDC, test xfalse = xtrue)
diff --git a/src/Makefile.am b/src/Makefile.am
index 256e6f15..2a23b602 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -425,10 +425,10 @@ endif MAKE_LINT_LIB
# Building ks_tables.h requires the makekeys utility
#
-KEYSYMDEF=@KEYSYMDEF@
+KEYSYMDEFS=@KEYSYMDEFS@
-ks_tables.h: $(KEYSYMDEF) $(top_builddir)/src/util/makekeys$(EXEEXT)
- $(top_builddir)/src/util/makekeys < $(KEYSYMDEF) > ks_tables_h
+ks_tables.h: $(KEYSYMDEFS) $(top_builddir)/src/util/makekeys$(EXEEXT)
+ $(top_builddir)/src/util/makekeys $(KEYSYMDEFS) > ks_tables_h
mv ks_tables_h $@
$(top_builddir)/src/util/makekeys$(EXEEXT): force
diff --git a/src/util/makekeys.c b/src/util/makekeys.c
index 1c27e6b2..8f88bebc 100644
--- a/src/util/makekeys.c
+++ b/src/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");