[X2Go-Commits] [nx-libs] 17/51: Keyboard.c: move keyboard file creation to extra function

git-admin at x2go.org git-admin at x2go.org
Fri Feb 8 05:40:04 CET 2019


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository nx-libs.

commit d610e9c3c878e39ae908f04843ed563b4669732f
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Sat Jul 22 17:34:22 2017 +0200

    Keyboard.c: move keyboard file creation to extra function
---
 nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 108 ++++++++++++++------------
 1 file changed, 57 insertions(+), 51 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
index c2c36ad..0b4e269 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
@@ -83,6 +83,8 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
 
 static void nxagentKeycodeConversionSetup(void);
 
+void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options);
+
 #endif /* XKB */
 
 /*
@@ -1557,6 +1559,56 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
   return n;
 }
 
+void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options)
+{
+  if (ruleslen)
+  {
+    char *sessionpath = nxagentGetSessionPath();
+    if (sessionpath)
+    {
+      char *keyboard_file_path = NULL;
+      FILE *keyboard_file;
+      if ((asprintf(&keyboard_file_path, "%s/keyboard", sessionpath) == -1))
+      {
+        free(sessionpath);
+        FatalError("malloc for keyboard file path failed.");
+      }
+      free(sessionpath);
+      if ((keyboard_file = fopen(keyboard_file_path, "w")))
+      {
+        if (rules)
+          fprintf(keyboard_file, "rules=\"%s\"\n", rules[0] == '\0' ? "," : rules);
+        if (model)
+          fprintf(keyboard_file, "model=\"%s\"\n", model[0] == '\0' ? "," : model);
+        if (layout)
+          fprintf(keyboard_file, "layout=\"%s\"\n", layout[0] == '\0' ? "," : layout);
+        /* FIXME: this is not correct. We need to match the number of
+           comma separated values between variant and layout */
+        if (variant)
+          fprintf(keyboard_file, "variant=\"%s\"\n", variant[0] == '\0' ? "," : variant);
+        if (options)
+          fprintf(keyboard_file, "options=\"%s\"\n", options[0] == '\0' ? "," : options);
+        fclose(keyboard_file);
+        fprintf(stderr, "Info: keyboard file created: '%s'\n", keyboard_file_path);
+      }
+      else
+      {
+        int save_err = errno;
+        fprintf(stderr, "Error: keyboard file not created: %s\n", strerror(save_err));
+      }
+      free(keyboard_file_path);
+    }
+    else
+    {
+      fprintf(stderr, "Warning: Failed to create keyboard file: SessionPath not defined\n");
+    }
+  }
+  else
+  {
+    fprintf(stderr, "Warning: Failed to create the keyboard file\n");
+  }
+}
+
 void nxagentKeycodeConversionSetup(void)
 {
   char *drules = NULL;
@@ -1587,69 +1639,23 @@ void nxagentKeycodeConversionSetup(void)
   #ifdef DEBUG
   if (drulesLen != 0 && drules && dmodel)
   {
-    fprintf(stderr, "nxagentKeycodeConversionSetup: "
-                    "Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
-                    drules, dmodel, dlayout, dvariant, doptions);
+    fprintf(stderr, "%s: Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
+            __func__, drules, dmodel, dlayout, dvariant, doptions);
   }
   else
   {
-    fprintf(stderr, "nxagentKeycodeConversionSetup: "
-                "Failed to retrieve remote rules.\n");
+    fprintf(stderr, "%s: Failed to retrieve remote rules.\n", __func__);
   }
   #endif
 
-  if (drulesLen != 0)
-  {
-    char *sessionpath = nxagentGetSessionPath();
-    if (sessionpath)
-    {
-      char *keyboard_file_path = NULL;
-      FILE *keyboard_file;
-      if ((asprintf(&keyboard_file_path, "%s/keyboard", sessionpath) == -1))
-      {
-        free(sessionpath);
-        FatalError("malloc for keyboard file path failed.");
-      }
-      free(sessionpath);
-      if ((keyboard_file = fopen(keyboard_file_path, "w")))
-      {
-        if (drules)
-          fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules);
-        if (dmodel)
-          fprintf(keyboard_file, "model=\"%s\"\n", dmodel[0] == '\0' ? "," : dmodel);
-        if (dlayout)
-          fprintf(keyboard_file, "layout=\"%s\"\n", dlayout[0] == '\0' ? "," : dlayout);
-        if (dvariant)
-          fprintf(keyboard_file, "variant=\"%s\"\n", dvariant[0] == '\0' ? "," : dvariant);
-        if (doptions)
-          fprintf(keyboard_file, "options=\"%s\"\n", doptions[0] == '\0' ? "," : doptions);
-        fclose(keyboard_file);
-        fprintf(stderr, "Info: keyboard file created: '%s'\n", keyboard_file_path);
-      }
-      else
-      {
-        int save_err = errno;
-        fprintf(stderr, "Error: keyboard file not created: %s\n", strerror(save_err));
-      }
-      free(keyboard_file_path);
-    }
-    else
-    {
-      fprintf(stderr, "Warning: SessionPath not defined\n");
-    }
-  }
-  else
-  {
-    fprintf(stderr, "Warning: Failed to create the keyboard file\n");
-  }
+  nxagentWriteKeyboardFile(drulesLen, drules, dmodel, dlayout, dvariant, doptions);
 
   if (drules && dmodel &&
       (strcmp(drules, "evdev") == 0 ||
        strcmp(dmodel, "evdev") == 0))
   {
     #ifdef DEBUG
-    fprintf(stderr, "nxagentKeycodeConversionSetup: "
-                "Activating KeyCode conversion.\n");
+    fprintf(stderr, "%s: Activating KeyCode conversion.\n", __func__);
     #endif
 
     fprintf(stderr, "Info: Keycode conversion auto-determined as on\n");

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list