[uim-commit] r2347 - trunk/xim

ekato at freedesktop.org ekato at freedesktop.org
Sat Dec 3 23:11:30 PST 2005


Author: ekato
Date: 2005-12-03 23:11:16 -0800 (Sat, 03 Dec 2005)
New Revision: 2347

Modified:
   trunk/xim/compose.cpp
Log:
* xim/compose.cpp (XimIM::get_compose_filename) : Use fallback
  directory for compose files on x86_64 Linux.


Modified: trunk/xim/compose.cpp
===================================================================
--- trunk/xim/compose.cpp	2005-12-04 04:50:35 UTC (rev 2346)
+++ trunk/xim/compose.cpp	2005-12-04 07:11:16 UTC (rev 2347)
@@ -52,6 +52,7 @@
 #define COMPOSE_FILE	"Compose"
 #define COMPOSE_DIR_FILE	"X11/locale/compose.dir"
 #define XLOCALE_DIR	"X11/locale"
+#define FALLBACK_XLIB_DIR	"/usr/X11R6/lib"
 
 #define XLC_BUFSIZE	256
 #define iscomment(ch)	((ch) == '#' || (ch) == '\0')
@@ -734,6 +735,7 @@
 
     FILE *fp;
     char buf[XLC_BUFSIZE], *name = NULL, *filename = NULL;
+    const char *xlib_dir = XLIB_DIR ;
 
     lang_region = get_lang_region();
     encoding = get_encoding();
@@ -755,9 +757,29 @@
 
     fp = fopen(compose_dir_file, "r");
     if (fp == NULL) {
-	free(locale);
-	free(compose_dir_file);
-	return NULL;
+	/* retry with fallback file */
+	if (strcmp(FALLBACK_XLIB_DIR, XLIB_DIR)) {
+	    compose_dir_file = (char *)realloc(compose_dir_file,
+			    strlen(FALLBACK_XLIB_DIR) +
+			    strlen(COMPOSE_DIR_FILE) + 2);
+	    if (compose_dir_file == NULL) {
+		free(locale);
+		return NULL;
+	    }
+	    sprintf(compose_dir_file, "%s/%s",
+			    FALLBACK_XLIB_DIR, COMPOSE_DIR_FILE);
+	    fp = fopen(compose_dir_file, "r");
+	    if (fp == NULL) {
+		free(locale);
+		free(compose_dir_file);
+		return NULL;
+	    }
+	    xlib_dir = FALLBACK_XLIB_DIR;
+	} else {
+	    free(locale);
+	    free(compose_dir_file);
+	    return NULL;
+	}
     }
 
     while (fgets(buf, XLC_BUFSIZE, fp) != NULL) {
@@ -790,10 +812,11 @@
     if (name == NULL)
 	return NULL;
 
-    filename = (char *)malloc(sizeof(char) * (strlen(XLIB_DIR) + strlen(XLOCALE_DIR) + strlen(name) + 3));
+    filename = (char *)malloc(strlen(xlib_dir) + strlen(XLOCALE_DIR) +
+		    strlen(name) + 3);
     if (filename == NULL)
 	return NULL;
-    sprintf(filename, "%s/%s/%s", XLIB_DIR, XLOCALE_DIR, name);
+    sprintf(filename, "%s/%s/%s", xlib_dir, XLOCALE_DIR, name);
     free(name);
 
     return filename;



More information about the uim-commit mailing list