xkbcomp: Lazy keysym parsing (avoid XStringToKeysym) Instead of calling XStringToKeysym on every keysym we parse, store it as a string until we need to store it in an actual keymap. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
diff --git a/configure.ac b/configure.ac
index 5f298ce..5a70315 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ XORG_CHECK_MALLOC_ZERO
XORG_CWARNFLAGS
PKG_CHECK_MODULES([X11], [xproto kbproto >= 1.0.99.1])
+PKG_CHECK_MODULES([XLIB], [x11])
dnl Ensure we have keysym headers
AC_MSG_CHECKING([for X11 includedir])
diff --git a/src/Makefile.am b/src/Makefile.am
index 0159a6d..916858f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,10 +1,10 @@
SUBDIRS = makekeys xkbcomp
-INCLUDES = -I$(top_srcdir)/include -I$(builddir)/makekeys
+INCLUDES = -I$(top_srcdir)/include -I$(builddir)/makekeys $(XLIB_CFLAGS)
AM_CFLAGS = $(X11_CFLAGS) $(CWARNFLAGS) $(XMALLOC_ZERO_CFLAGS)
lib_LTLIBRARIES = libxkbcommon.la
-libxkbcommon_la_LIBADD = xkbcomp/libxkbcomp.la
+libxkbcommon_la_LIBADD = xkbcomp/libxkbcomp.la $(XLIB_LIBS)
libxkbcommon_la_SOURCES = \
XKBcommonint.h \
alloc.c \
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index ed66263..9f6c0e4 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -393,7 +393,7 @@ ActionCreate(Atom name, ExprDef * args)
}
ExprDef *
-CreateKeysymList(KeySym sym)
+CreateKeysymList(char *sym)
{
ExprDef *def;
@@ -401,8 +401,8 @@ CreateKeysymList(KeySym sym)
if (def)
{
def->value.list.nSyms = 1;
- def->value.list.szSyms = 2;
- def->value.list.syms = uTypedCalloc(2, KeySym);
+ def->value.list.szSyms = 4;
+ def->value.list.syms = uTypedCalloc(4, char *);
if (def->value.list.syms != NULL)
{
def->value.list.syms[0] = sym;
@@ -601,7 +601,7 @@ DoodadCreate(unsigned type, Atom name, VarDef * body)
}
ExprDef *
-AppendKeysymList(ExprDef * list, KeySym sym)
+AppendKeysymList(ExprDef * list, char *sym)
{
if (list->value.list.nSyms >= list->value.list.szSyms)
{
@@ -609,7 +609,7 @@ AppendKeysymList(ExprDef * list, KeySym sym)
list->value.list.syms = uTypedRecalloc(list->value.list.syms,
list->value.list.nSyms,
list->value.list.szSyms,
- KeySym);
+ char *);
if (list->value.list.syms == NULL)
{
FATAL("Couldn't resize list of symbols for append\n");
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index 5e8f55b..ea04240 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -121,7 +121,7 @@ extern ExprDef *ActionCreate(Atom /* name */ ,
ExprDef * /* args */
);
-extern ExprDef *CreateKeysymList(KeySym /* sym */
+extern ExprDef *CreateKeysymList(char * /* sym */
);
extern ShapeDef *ShapeDeclCreate(Atom /* name */ ,
@@ -161,7 +161,7 @@ extern DoodadDef *DoodadCreate(unsigned /* type */ ,
);
extern ExprDef *AppendKeysymList(ExprDef * /* list */ ,
- KeySym /* sym */
+ char * /* sym */
);
extern int LookupKeysym(char * /* str */ ,
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index efc6555..ce97a6f 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -29,6 +29,7 @@
#include "xkbmisc.h"
#include "tokens.h"
#include "expr.h"
+#include "parseutils.h"
#include <X11/extensions/XKBfilecommon.h>
#include <X11/keysym.h>
@@ -969,8 +970,12 @@ AddSymbolsToKey(KeyInfo * key,
return False;
}
key->symsDefined |= (1 << ndx);
- memcpy((char *) key->syms[ndx], (char *) value->value.list.syms,
- nSyms * sizeof(KeySym));
+ for (i = 0; i < nSyms; i++) {
+ if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
+ WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
+ key->syms[ndx][i] = NoSymbol;
+ }
+ }
for (i = key->numLevels[ndx] - 1;
(i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
{
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index d3a64b9..c120e24 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -158,7 +158,7 @@ typedef struct _Expr
{
int nSyms;
int szSyms;
- KeySym *syms;
+ char **syms;
} list;
struct
{
diff --git a/src/xkbcomp/xkbparse.y b/src/xkbcomp/xkbparse.y
index f95dec9..68e261f 100644
--- a/src/xkbcomp/xkbparse.y
+++ b/src/xkbcomp/xkbparse.y
@@ -95,6 +95,7 @@
#define DEBUG_VAR parseDebug
#include "parseutils.h"
#include "xkbmisc.h"
+#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XKBgeomcommon.h>
#include <stdlib.h>
@@ -137,9 +138,9 @@ unsigned int parseDebug;
XkbFile *file;
}
%type <ival> Number Integer Float SignedNumber
-%type <uval> XkbCompositeType FileType MergeMode OptMergeMode KeySym
+%type <uval> XkbCompositeType FileType MergeMode OptMergeMode
%type <uval> DoodadType Flag Flags OptFlags
-%type <str> KeyName MapName OptMapName
+%type <str> KeyName MapName OptMapName KeySym
%type <sval> FieldSpec Ident Element String
%type <any> DeclList Decl
%type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
@@ -375,9 +376,9 @@ InterpretDecl : INTERPRET InterpretMatch OBRACE
;
InterpretMatch : KeySym PLUS Expr
- { $$= InterpCreate((KeySym)$1,$3); }
+ { $$= InterpCreate(XStringToKeysym($1), $3); }
| KeySym
- { $$= InterpCreate((KeySym)$1,NULL); }
+ { $$= InterpCreate(XStringToKeysym($1), NULL); }
;
VarDeclList : VarDeclList VarDecl
@@ -717,35 +718,25 @@ OptKeySymList : KeySymList { $$= $1; }
;
KeySymList : KeySymList COMMA KeySym
- { $$= AppendKeysymList($1,(KeySym)$3); }
+ { $$= AppendKeysymList($1,$3); }
| KeySym
- { $$= CreateKeysymList((KeySym)$1); }
+ { $$= CreateKeysymList($1); }
;
-KeySym : IDENT
+KeySym : IDENT { $$= scanStr; scanStr= NULL; }
+ | SECTION { $$= strdup("section"); }
+ | Integer
{
- KeySym sym;
- if (LookupKeysym(scanStr,&sym))
- $$= sym;
+ if ($1 < 10) { /* XK_0 .. XK_9 */
+ $$= malloc(2);
+ $$[0]= $1 + '0';
+ $$[1]= '\0';
+ }
else {
- char buf[120];
- snprintf(buf, sizeof(buf),
- "expected keysym, got %s",
- uStringText(scanStr));
- yyerror(buf);
- yynerrs++;
- $$= NoSymbol;
+ $$= malloc(17);
+ snprintf($$, 17, "%x", $1);
}
}
- | SECTION
- {
- $$= XK_section;
- }
- | Integer
- {
- if ($1<10) $$= $1+'0'; /* XK_0 .. XK_9 */
- else $$= $1;
- }
;
SignedNumber : MINUS Number { $$= -$2; }