diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2017-07-17 09:50:26 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2017-07-17 09:50:26 +0200 |
commit | 4ccb7eda5563ce7594245eb70aab6754e7b104c2 (patch) | |
tree | f23ff4bf86e6fdb78b33262867cf61f807147d76 /nx-X11/programs/Xserver/hw | |
parent | ccd7c6962bb50faa4a1549011824e34c0d0792b9 (diff) | |
parent | 79001dd8a1472886a573b3eecf7ab763210c541c (diff) | |
download | nx-libs-4ccb7eda5563ce7594245eb70aab6754e7b104c2.tar.gz nx-libs-4ccb7eda5563ce7594245eb70aab6754e7b104c2.tar.bz2 nx-libs-4ccb7eda5563ce7594245eb70aab6754e7b104c2.zip |
Merge branch 'uli42-pr/fix_keystroke_files' into 3.6.x
Attributes GH PR #487: https://github.com/ArcticaProject/nx-libs/pull/487
Diffstat (limited to 'nx-X11/programs/Xserver/hw')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Keystroke.c | 87 |
1 files changed, 35 insertions, 52 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c index 1e3ebca8f..f790090bf 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c @@ -253,6 +253,24 @@ static Bool read_binding_from_xmlnode(xmlNode *node, struct nxagentSpecialKeystr return False; } +char *checkKeystrokeFile(char *filename) +{ + if (!filename) + return NULL; + + if (access(filename, R_OK) == 0) + { + return filename; + } + else + { + #ifdef WARNING + fprintf(stderr, "Warning: Cannot read keystroke file '%s'.\n", filename); + #endif + return NULL; + } +} + /* * searches a keystroke xml file * @@ -302,63 +320,24 @@ void nxagentInitKeystrokes(Bool force) envvar = "NXAGENT_KEYSTROKEFILE"; } - if (nxagentKeystrokeFile && access(nxagentKeystrokeFile, R_OK) == 0) + char *homepath = NULL; + char *homedir = getenv("HOME"); + if (homedir) { - if (!(filename = strdup(nxagentKeystrokeFile))) + if (!(homepath = calloc(1, strlen(homedir) + strlen(homefile) + 1))) { fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); } - } - else if (nxagentKeystrokeFile) - { - fprintf(stderr, "Warning: Cannot read keystroke file '%s'.\n", nxagentKeystrokeFile); - if ((filename = getenv(envvar)) && access(filename, R_OK) == 0) - { - if (!(filename = strdup(filename))) - { - fprintf(stderr, "malloc failed"); - exit(EXIT_FAILURE); - } - } - else - { - char *homedir = getenv("HOME"); - filename = NULL; - if (homedir) - { - if (!(filename = calloc(1, strlen(homefile) + strlen(homedir) + 1))) - { - fprintf(stderr, "malloc failed"); - exit(EXIT_FAILURE); - } - strcpy(filename, homedir); - strcpy(filename + strlen(homedir), homefile); - } - - if (access(filename, R_OK) == 0) - { - /* empty */ - } - else if (access(etcfile, R_OK) == 0) - { - free(filename); - if (!(filename = strdup(etcfile))) - { - fprintf(stderr, "malloc failed"); - exit(EXIT_FAILURE); - } - } - else - { - free(filename); - filename = NULL; - } - } + strcpy(homepath, homedir); + strcpy(homepath + strlen(homedir), homefile); } - /* now we know which file to read, if any */ - if (filename) + /* if any of the files can be read we have our candidate */ + if ((filename = checkKeystrokeFile(nxagentKeystrokeFile)) || + (filename = checkKeystrokeFile(getenv(envvar))) || + (filename = checkKeystrokeFile(homepath)) || + (filename = checkKeystrokeFile(etcfile))) { LIBXML_TEST_VERSION xmlDoc *doc = xmlReadFile(filename, NULL, 0); @@ -405,9 +384,11 @@ void nxagentInitKeystrokes(Bool force) map[j].modifierMask == map[idx].modifierMask && map[j].modifierAltMeta == map[idx].modifierAltMeta) { + #ifdef WARNING fprintf(stderr, "Warning: ignoring keystroke '%s' (already in use by '%s')\n", nxagentSpecialKeystrokeNames[map[idx].stroke], nxagentSpecialKeystrokeNames[map[j].stroke]); + #endif store = False; break; } @@ -430,13 +411,15 @@ void nxagentInitKeystrokes(Bool force) xmlFreeDoc(doc); xmlCleanupParser(); } - else + #ifdef WARNING + else /* if (doc) */ { fprintf(stderr, "Warning: could not read/parse keystrokes file '%s'\n", filename); } - free(filename); + #endif filename = NULL; } + free(homepath); if (map == default_map) { |