Normalize display name in building a cached metrics filename

Jeremy White jwhite at codeweavers.com
Thu Aug 2 21:59:07 CDT 2001


At least on RedHat distributions, the DISPLAY variable differs
depending on which shell you are in, or whether an application
is started from a Window Manager.    This causes Wine
(on RedHat systems I've observed) to build a
cachedmetrics.:0.0 as well as a cachedmetrics.:0
file (it also builds a cachedmetrics.unix:0.0 file sometimes, too).

This, obviously, slows things down a bit.

Changelog:
    Normalize the display name used to build the cached metric
filename so that ':0', ':0.0', and 'unix:0.0' all resolve to the
same file.
-------------- next part --------------
Index: graphics/x11drv/xfont.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/xfont.c,v
retrieving revision 1.80
diff -u -r1.80 xfont.c
--- graphics/x11drv/xfont.c	2001/07/28 00:18:05	1.80
+++ graphics/x11drv/xfont.c	2001/08/03 02:45:06
@@ -1813,13 +1813,54 @@
  * 
  * Returns expanded name for the cachedmetrics file.
  * Now it also appends the current value of the $DISPLAY variable.
+ * 
  */
 static char* XFONT_UserMetricsCache( char* buffer, int* buf_size )
 {
     const char *confdir = get_config_dir();
-    const char *display_name = XDisplayName(NULL);
-    int len = strlen(confdir) + strlen(INIFontMetrics) + strlen(display_name) + 2;
 
+    char *display_name;
+    char normalized_name[MAX_PATH];
+
+    int display = 0;
+    int screen = 0;
+    int len;
+
+    char *p;
+
+    display_name = XDisplayName(NULL);
+    if (display_name == NULL || strlen(display_name)  > sizeof(normalized_name) - 30)
+    {
+        ERR("Irrational XDisplayName [%s]\n", display_name);
+        ExitProcess(1);
+    }
+
+    /*
+    **  Normalize the display name, since on Red Hat systems, DISPLAY
+    **      is commonly set to one of either 'unix:0.0' or ':0' or ':0.0'.
+    **      after this code, all of the above will resolve to ':0.0'.
+    */
+    memset(normalized_name, '\0', sizeof(normalized_name));
+    p = strchr(display_name, ':');
+    if (p)
+    {
+        sscanf(p + 1, "%d.%d", &display, &screen);
+        if (p > display_name)
+            memcpy(normalized_name, display_name, p - display_name);
+    }
+    else
+        strcpy(normalized_name, display_name);
+    if (strcmp(normalized_name, "unix") == 0)
+        strcpy(normalized_name, "");
+
+    sprintf(normalized_name + strlen(normalized_name), ":%d.%d", display, screen);
+
+
+    /* 
+    **  Allocate, build, and return the result
+    */
+    len = strlen(confdir) + strlen(INIFontMetrics) + strlen(normalized_name) + 2;
+
     if ((len > *buf_size) &&
         !(buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, *buf_size = len )))
     {
@@ -1827,7 +1868,7 @@
         ExitProcess(1);
     }
 
-    sprintf( buffer, "%s/%s%s", confdir, INIFontMetrics, display_name );
+    sprintf( buffer, "%s/%s%s", confdir, INIFontMetrics, normalized_name);
     return buffer;
 }
 


More information about the wine-patches mailing list