[X2Go-Commits] [nx-libs] 05/219: Font.c: factor out font checks

git-admin at x2go.org git-admin at x2go.org
Sat Sep 28 12:10:11 CEST 2019


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

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

commit dff2e0a01fd9f2c2aa46a4a68ea2db6ece5878f7
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Wed Apr 3 22:33:33 2019 +0200

    Font.c: factor out font checks
---
 nx-X11/programs/Xserver/hw/nxagent/Font.c | 132 +++++++++---------------------
 1 file changed, 37 insertions(+), 95 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Font.c b/nx-X11/programs/Xserver/hw/nxagent/Font.c
index 57909d7fc..f967f82f0 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Font.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Font.c
@@ -1443,128 +1443,68 @@ static Bool nxagentGetFontServerPath(char * fontServerPath, int size)
   return True;
 }
 
-void nxagentVerifyDefaultFontPath(void)
+void nxagentVerifySingleFontPath(char **dest, const char *fontDir, const char *fontPath)
 {
   struct stat dirStat;
-  static char *fontPath;
-
-  #ifdef TEST
-  fprintf(stderr, "nxagentVerifyDefaultFontPath: Going to search for one or more valid font paths.\n");
-  #endif
-
-  /*
-   * Set the default font path as the first choice.
-   */
-
-  if ((fontPath = strdup(defaultFontPath)) == NULL)
-  {
-    #ifdef WARNING
-    fprintf(stderr, "nxagentVerifyDefaultFontPath: WARNING! Unable to allocate memory for a new font path. "
-                "Using the default font path [%s].\n", validateString(defaultFontPath));
-    #endif
+  char * newdest = NULL;
 
+  if (!dest || !*dest)
     return;
-  }
 
-  if (stat(NXAGENT_DEFAULT_FONT_DIR, &dirStat) == 0 &&
+  if (stat(fontDir, &dirStat) == 0 &&
           S_ISDIR(dirStat.st_mode) != 0)
   {
-    /*
-     * Let's use the old "/usr/share/nx/fonts" style.
-     */
-
     #ifdef TEST
-    fprintf(stderr, "nxagentVerifyDefaultFontPath: Assuming fonts in directory [%s].\n",
-                validateString(NXAGENT_DEFAULT_FONT_DIR));
+    fprintf(stderr, "%s: Assuming fonts in directory [%s].\n", __func__,
+                validateString(fontDir));
     #endif
 
-    if (*fontPath != '\0')
+    if (**dest != '\0')
     {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_DEFAULT_FONT_PATH) + 2);
-      strcat(fontPath, ",");
+      newdest = realloc(*dest, strlen(*dest) + strlen(fontPath) + 2);
+      if (newdest == NULL)
+        return;
+      strcat(newdest, ",");
     }
     else
     {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_DEFAULT_FONT_PATH) + 1);
+      newdest = realloc(*dest, strlen(*dest) + strlen(fontPath) + 1);
+      if (newdest == NULL)
+        return;
     }
 
-    strcat(fontPath, NXAGENT_DEFAULT_FONT_PATH);
+    strcat(newdest, fontPath);
+    *dest = newdest;
   }
+}
 
-  if (stat(NXAGENT_ALTERNATE_FONT_DIR, &dirStat) == 0 &&
-          S_ISDIR(dirStat.st_mode) != 0)
-  {
-    /*
-     * Let's use the new "/usr/share/X11/fonts" path.
-     */
-
-    #ifdef TEST
-    fprintf(stderr, "nxagentVerifyDefaultFontPath: Assuming fonts in directory [%s].\n",
-                validateString(NXAGENT_ALTERNATE_FONT_DIR));
-    #endif
+void nxagentVerifyDefaultFontPath(void)
+{
+  static char *fontPath;
 
-    if (*fontPath != '\0')
-    {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH) + 2);
-      strcat(fontPath, ",");
-    }
-    else
-    {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH) + 1);
-    }
+  #ifdef TEST
+  fprintf(stderr, "nxagentVerifyDefaultFontPath: Going to search for one or more valid font paths.\n");
+  #endif
 
-    strcat(fontPath, NXAGENT_ALTERNATE_FONT_PATH);
-  }
+  /*
+   * Set the default font path as the first choice.
+   */
 
-  if (stat(NXAGENT_ALTERNATE_FONT_DIR_2, &dirStat) == 0 &&
-          S_ISDIR(dirStat.st_mode) != 0)
+  if ((fontPath = strdup(defaultFontPath)) == NULL)
   {
-    /*
-     * Let's use the "/usr/share/fonts/X11" path.
-     */
-
-    #ifdef TEST
-    fprintf(stderr, "nxagentVerifyDefaultFontPath: Assuming fonts in directory [%s].\n",
-                validateString(NXAGENT_ALTERNATE_FONT_DIR_2));
+    #ifdef WARNING
+    fprintf(stderr, "nxagentVerifyDefaultFontPath: WARNING! Unable to allocate memory for a new font path. "
+                "Using the default font path [%s].\n", validateString(defaultFontPath));
     #endif
 
-    if (*fontPath != '\0')
-    {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH_2) + 2);
-      strcat(fontPath, ",");
-    }
-    else
-    {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH_2) + 1);
-    }
-
-    strcat(fontPath, NXAGENT_ALTERNATE_FONT_PATH_2);
+    return;
   }
 
-  if (stat(NXAGENT_ALTERNATE_FONT_DIR_3, &dirStat) == 0 &&
-          S_ISDIR(dirStat.st_mode) != 0)
-  {
-    /*
-     * Let's use the "/usr/X11R6/lib/X11/fonts" path.
-     */
-
-    #ifdef TEST
-    fprintf(stderr, "nxagentVerifyDefaultFontPath: Assuming fonts in directory [%s].\n",
-                validateString(NXAGENT_ALTERNATE_FONT_DIR_3));
-    #endif
+  nxagentVerifySingleFontPath(&fontPath, NXAGENT_DEFAULT_FONT_DIR, NXAGENT_DEFAULT_FONT_PATH);
+  nxagentVerifySingleFontPath(&fontPath, NXAGENT_ALTERNATE_FONT_DIR, NXAGENT_ALTERNATE_FONT_PATH);
+  nxagentVerifySingleFontPath(&fontPath, NXAGENT_ALTERNATE_FONT_DIR_2, NXAGENT_ALTERNATE_FONT_PATH_2);
+  nxagentVerifySingleFontPath(&fontPath, NXAGENT_ALTERNATE_FONT_DIR_3, NXAGENT_ALTERNATE_FONT_PATH_3);
 
-    if (*fontPath != '\0')
-    {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH_3) + 2);
-      strcat(fontPath, ",");
-    }
-    else
-    {
-      fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH_3) + 1);
-    }
-
-    strcat(fontPath, NXAGENT_ALTERNATE_FONT_PATH_3);
-  }
   if (*fontPath == '\0') 
   {
     #ifdef WARNING
@@ -1576,6 +1516,8 @@ void nxagentVerifyDefaultFontPath(void)
   }
   else
   {
+    /* do _not_ free defaultFontPath here - it's either set at compile time or
+       part of argv */
     defaultFontPath = fontPath;
  
     #ifdef TEST

--
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