aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2019-04-03 22:33:33 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2019-05-10 16:24:03 +0200
commitdff2e0a01fd9f2c2aa46a4a68ea2db6ece5878f7 (patch)
tree6602d8f66279facd12de0e7c98589dd203cacfd3
parentd94e9ba24b6b02c44d0c8086631d9cddd01c952a (diff)
downloadnx-libs-dff2e0a01fd9f2c2aa46a4a68ea2db6ece5878f7.tar.gz
nx-libs-dff2e0a01fd9f2c2aa46a4a68ea2db6ece5878f7.tar.bz2
nx-libs-dff2e0a01fd9f2c2aa46a4a68ea2db6ece5878f7.zip
Font.c: factor out font checks
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Font.c132
1 files 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