[PATCH] Locale specific app-defaults files.

Malcolm Purvis malcolmp at xemacs.org
Sun Oct 22 08:14:37 EDT 2006


Slightly connected to Mats' recent comments on running XEmacs under a non-"C"
locale, here is the first of two patches that fix locale problems that I've
found.

The locale package provides locale specific X resources and splash screens.
The files are stored in directories called <language> (eg 'fr'), and accessed
directly from the contents of $LANG.  Unfortunately the general form of $LANG
these days is <language>_<country>.<encoding>.

This patch fixes the loading of a locale specific app-defaults file so that
<language>_<country> and <language> are searched as well.

Malcolm

src/ChangeLog addition:

2006-10-22  Malcolm Purvis  <malcolmp at xemacs.org>

	* device-x.c (x_init_device):  Look in more directories when
	searching for the locale specific app-defaults files.


xemacs-locale source patch:
Diff command:   cvs -q diff -u
Files affected: src/device-x.c

Index: src/device-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/device-x.c,v
retrieving revision 1.67
diff -u -r1.67 device-x.c
--- src/device-x.c	2006/06/21 17:30:35	1.67
+++ src/device-x.c	2006/10/22 11:59:01
@@ -665,8 +665,10 @@
        does not override resources defined elsewhere */
     const Extbyte *data_dir;
     Extbyte *path;
+    Extbyte *format;
     XrmDatabase db = XtDatabase (dpy); /* #### XtScreenDatabase(dpy) ? */
-    const Extbyte *locale = XrmLocaleOfDatabase (db);
+    Extbyte *locale = xstrdup (XrmLocaleOfDatabase (db));
+    Extbyte *locale_end;
 
     if (STRINGP (Vx_app_defaults_directory) &&
 	XSTRING_LENGTH (Vx_app_defaults_directory) > 0)
@@ -674,18 +676,42 @@
 	LISP_STRING_TO_EXTERNAL (Vx_app_defaults_directory, data_dir,
 				 Qfile_name);
 	path = alloca_extbytes (strlen (data_dir) + strlen (locale) + 7);
-	sprintf (path, "%s%s/Emacs", data_dir, locale);
-	if (!access (path, R_OK))
-	  XrmCombineFileDatabase (path, &db, False);
+	format = "%s%s/Emacs";
       }
     else if (STRINGP (Vdata_directory) && XSTRING_LENGTH (Vdata_directory) > 0)
       {
 	LISP_STRING_TO_EXTERNAL (Vdata_directory, data_dir, Qfile_name);
 	path = alloca_extbytes (strlen (data_dir) + 13 + strlen (locale) + 7);
-	sprintf (path, "%sapp-defaults/%s/Emacs", data_dir, locale);
-	if (!access (path, R_OK))
-	  XrmCombineFileDatabase (path, &db, False);
+	format = "%sapp-defaults/%s/Emacs";
       }
+
+    /*
+     * The general form for $LANG is <language>_<country>.<encoding>.  Try
+     * that form, <language>_<country> and <language> and load for first
+     * app-defaults file found.
+     */
+
+    sprintf (path, format, data_dir, locale);
+    if (!access (path, R_OK))
+      XrmCombineFileDatabase (path, &db, False);
+
+    if ((locale_end = strchr(locale, '.'))) {
+      *locale_end = '\0';
+      sprintf (path, format, data_dir, locale);
+
+      if (!access (path, R_OK))
+	XrmCombineFileDatabase (path, &db, False);
+    }
+
+    if ((locale_end = strchr(locale, '_'))) {
+      *locale_end = '\0';
+      sprintf (path, format, data_dir, locale);
+
+      if (!access (path, R_OK))
+	XrmCombineFileDatabase (path, &db, False);
+    }
+
+    xfree (locale, Extbyte*);
  }
 #endif /* MULE */
 

-- 
		     Malcolm Purvis <malcolmp at xemacs.org>



More information about the XEmacs-Patches mailing list