From cb9a1d01468732196fd25c6422991e784639ffce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 12 Mar 2014 17:18:22 +1000 Subject: [PATCH] xkb: factor out xkb loading to LoadXkm MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Hutterer Reviewed-by: Kristian Høgsberg --- xkb/ddxLoad.c | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index 33247cf..0361b9b 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -291,6 +291,35 @@ XkbDDXOpenConfigFile(const char *mapName, char *fileNameRtrn, int fileNameRtrnLe return file; } +static unsigned +LoadXKM(unsigned want, unsigned need, const char *keymap, XkbDescPtr *xkbRtrn) +{ + FILE *file; + char fileName[PATH_MAX]; + unsigned missing; + + file = XkbDDXOpenConfigFile(keymap, fileName, PATH_MAX); + if (file == NULL) { + LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n", + fileName); + return 0; + } + missing = XkmReadFile(file, need, want, xkbRtrn); + if (*xkbRtrn == NULL) { + LogMessage(X_ERROR, "Error loading keymap %s\n", fileName); + fclose(file); + (void) unlink(fileName); + return 0; + } + else { + DebugF("Loaded XKB keymap %s, defined=0x%x\n", fileName, + (*xkbRtrn)->defined); + } + fclose(file); + (void) unlink(fileName); + return (need | want) & (~missing); +} + unsigned XkbDDXLoadKeymapByNames(DeviceIntPtr keybd, XkbComponentNamesPtr names, @@ -299,9 +328,6 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd, XkbDescPtr *xkbRtrn, char *nameRtrn, int nameRtrnLen) { XkbDescPtr xkb; - FILE *file; - char fileName[PATH_MAX]; - unsigned missing; *xkbRtrn = NULL; if ((keybd == NULL) || (keybd->key == NULL) || @@ -321,26 +347,8 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd, LogMessage(X_ERROR, "XKB: Couldn't compile keymap\n"); return 0; } - file = XkbDDXOpenConfigFile(nameRtrn, fileName, PATH_MAX); - if (file == NULL) { - LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n", - fileName); - return 0; - } - missing = XkmReadFile(file, need, want, xkbRtrn); - if (*xkbRtrn == NULL) { - LogMessage(X_ERROR, "Error loading keymap %s\n", fileName); - fclose(file); - (void) unlink(fileName); - return 0; - } - else { - DebugF("Loaded XKB keymap %s, defined=0x%x\n", fileName, - (*xkbRtrn)->defined); - } - fclose(file); - (void) unlink(fileName); - return (need | want) & (~missing); + + return LoadXKM(want, need, nameRtrn, xkbRtrn); } Bool -- 2.7.4