Commit dff2e0a0 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Font.c: factor out font checks

parent d94e9ba2
...@@ -1443,128 +1443,68 @@ static Bool nxagentGetFontServerPath(char * fontServerPath, int size) ...@@ -1443,128 +1443,68 @@ static Bool nxagentGetFontServerPath(char * fontServerPath, int size)
return True; return True;
} }
void nxagentVerifyDefaultFontPath(void) void nxagentVerifySingleFontPath(char **dest, const char *fontDir, const char *fontPath)
{ {
struct stat dirStat; struct stat dirStat;
static char *fontPath; char * newdest = NULL;
#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
if (!dest || !*dest)
return; return;
}
if (stat(NXAGENT_DEFAULT_FONT_DIR, &dirStat) == 0 && if (stat(fontDir, &dirStat) == 0 &&
S_ISDIR(dirStat.st_mode) != 0) S_ISDIR(dirStat.st_mode) != 0)
{ {
/*
* Let's use the old "/usr/share/nx/fonts" style.
*/
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentVerifyDefaultFontPath: Assuming fonts in directory [%s].\n", fprintf(stderr, "%s: Assuming fonts in directory [%s].\n", __func__,
validateString(NXAGENT_DEFAULT_FONT_DIR)); validateString(fontDir));
#endif #endif
if (*fontPath != '\0') if (**dest != '\0')
{ {
fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_DEFAULT_FONT_PATH) + 2); newdest = realloc(*dest, strlen(*dest) + strlen(fontPath) + 2);
strcat(fontPath, ","); if (newdest == NULL)
return;
strcat(newdest, ",");
} }
else 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 && void nxagentVerifyDefaultFontPath(void)
S_ISDIR(dirStat.st_mode) != 0) {
{ static char *fontPath;
/*
* 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
if (*fontPath != '\0') #ifdef TEST
{ fprintf(stderr, "nxagentVerifyDefaultFontPath: Going to search for one or more valid font paths.\n");
fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH) + 2); #endif
strcat(fontPath, ",");
}
else
{
fontPath = realloc(fontPath, strlen(fontPath) + strlen(NXAGENT_ALTERNATE_FONT_PATH) + 1);
}
strcat(fontPath, NXAGENT_ALTERNATE_FONT_PATH); /*
} * Set the default font path as the first choice.
*/
if (stat(NXAGENT_ALTERNATE_FONT_DIR_2, &dirStat) == 0 && if ((fontPath = strdup(defaultFontPath)) == NULL)
S_ISDIR(dirStat.st_mode) != 0)
{ {
/* #ifdef WARNING
* Let's use the "/usr/share/fonts/X11" path. fprintf(stderr, "nxagentVerifyDefaultFontPath: WARNING! Unable to allocate memory for a new font path. "
*/ "Using the default font path [%s].\n", validateString(defaultFontPath));
#ifdef TEST
fprintf(stderr, "nxagentVerifyDefaultFontPath: Assuming fonts in directory [%s].\n",
validateString(NXAGENT_ALTERNATE_FONT_DIR_2));
#endif #endif
if (*fontPath != '\0') return;
{
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);
} }
if (stat(NXAGENT_ALTERNATE_FONT_DIR_3, &dirStat) == 0 && nxagentVerifySingleFontPath(&fontPath, NXAGENT_DEFAULT_FONT_DIR, NXAGENT_DEFAULT_FONT_PATH);
S_ISDIR(dirStat.st_mode) != 0) 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);
* 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
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') if (*fontPath == '\0')
{ {
#ifdef WARNING #ifdef WARNING
...@@ -1576,6 +1516,8 @@ void nxagentVerifyDefaultFontPath(void) ...@@ -1576,6 +1516,8 @@ void nxagentVerifyDefaultFontPath(void)
} }
else else
{ {
/* do _not_ free defaultFontPath here - it's either set at compile time or
part of argv */
defaultFontPath = fontPath; defaultFontPath = fontPath;
#ifdef TEST #ifdef TEST
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment