]> code.delx.au - gnu-emacs/blobdiff - src/xrdb.c
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / src / xrdb.c
index 982a6e46a134e3064dc99daf0354e15b2345e19b..c25c25d6f33dde6f3a72cad82c3e87a4361d0ece 100644 (file)
@@ -1,5 +1,6 @@
 /* Deal with the X Resource Manager.
-   Copyright (C) 1990, 1993-1994, 2000-2012 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1993-1994, 2000-2013 Free Software Foundation,
+   Inc.
 
 Author: Joseph Arceneaux
 Created: 4/90
@@ -21,7 +22,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
-#include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
 #include <epaths.h>
@@ -42,7 +42,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #endif
-#include <sys/stat.h>
 
 #ifdef USE_MOTIF
 /* For Vdouble_click_time.  */
@@ -51,7 +50,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 char *x_get_string_resource (XrmDatabase rdb, const char *name,
                             const char *class);
-static int file_p (const char *filename);
 
 \f
 /* X file search path processing.  */
@@ -109,7 +107,7 @@ x_get_customization_string (XrmDatabase db, const char *name,
                database associated with display.
                (This is x_customization_string.)
 
-   Return the expanded file name if it exists and is readable, and
+   Return the resource database if its file was read successfully, and
    refers to %L only when the LANG environment variable is set, or
    otherwise provided by X.
 
@@ -118,10 +116,11 @@ x_get_customization_string (XrmDatabase db, const char *name,
 
    Return NULL otherwise.  */
 
-static char *
-magic_file_p (const char *string, ptrdiff_t string_len, const char *class,
-             const char *escaped_suffix)
+static XrmDatabase
+magic_db (const char *string, ptrdiff_t string_len, const char *class,
+         const char *escaped_suffix)
 {
+  XrmDatabase db;
   char *lang = getenv ("LANG");
 
   ptrdiff_t path_size = 100;
@@ -218,14 +217,9 @@ magic_file_p (const char *string, ptrdiff_t string_len, const char *class,
     }
 
   path[path_len] = '\0';
-
-  if (! file_p (path))
-    {
-      xfree (path);
-      return NULL;
-    }
-
-  return path;
+  db = XrmGetFileDatabase (path);
+  xfree (path);
+  return db;
 }
 
 
@@ -259,19 +253,11 @@ gethomedir (void)
 }
 
 
-static int
-file_p (const char *filename)
-{
-  return (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) == 0
-         && ! file_directory_p (filename));
-}
-
-
 /* Find the first element of SEARCH_PATH which exists and is readable,
    after expanding the %-escapes.  Return 0 if we didn't find any, and
    the path name of the one we found otherwise.  */
 
-static char *
+static XrmDatabase
 search_magic_path (const char *search_path, const char *class,
                   const char *escaped_suffix)
 {
@@ -284,18 +270,16 @@ search_magic_path (const char *search_path, const char *class,
 
       if (p > s)
        {
-         char *path = magic_file_p (s, p - s, class, escaped_suffix);
-         if (path)
-           return path;
+         XrmDatabase db = magic_db (s, p - s, class, escaped_suffix);
+         if (db)
+           return db;
        }
       else if (*p == ':')
        {
-         char *path;
-
-         s = "%N%S";
-         path = magic_file_p (s, strlen (s), class, escaped_suffix);
-         if (path)
-           return path;
+         static char const ns[] = "%N%S";
+         XrmDatabase db = magic_db (ns, strlen (ns), class, escaped_suffix);
+         if (db)
+           return db;
        }
 
       if (*p == ':')
@@ -310,21 +294,12 @@ search_magic_path (const char *search_path, const char *class,
 static XrmDatabase
 get_system_app (const char *class)
 {
-  XrmDatabase db = NULL;
   const char *path;
-  char *p;
 
   path = getenv ("XFILESEARCHPATH");
   if (! path) path = PATH_X_DEFAULTS;
 
-  p = search_magic_path (path, class, 0);
-  if (p)
-    {
-      db = XrmGetFileDatabase (p);
-      xfree (p);
-    }
-
-  return db;
+  return search_magic_path (path, class, 0);
 }
 
 
@@ -338,35 +313,40 @@ get_fallback (Display *display)
 static XrmDatabase
 get_user_app (const char *class)
 {
+  XrmDatabase db = 0;
   const char *path;
-  char *file = 0;
-  char *free_it = 0;
 
   /* Check for XUSERFILESEARCHPATH.  It is a path of complete file
      names, not directories.  */
-  if (((path = getenv ("XUSERFILESEARCHPATH"))
-       && (file = search_magic_path (path, class, 0)))
+  path = getenv ("XUSERFILESEARCHPATH");
+  if (path)
+    db = search_magic_path (path, class, 0);
 
+  if (! db)
+    {
       /* Check for APPLRESDIR; it is a path of directories.  In each,
         we have to search for LANG/CLASS and then CLASS.  */
-      || ((path = getenv ("XAPPLRESDIR"))
-         && ((file = search_magic_path (path, class, "/%L/%N"))
-             || (file = search_magic_path (path, class, "/%N"))))
+      path = getenv ("XAPPLRESDIR");
+      if (path)
+       {
+         db = search_magic_path (path, class, "/%L/%N");
+         if (!db)
+           db = search_magic_path (path, class, "/%N");
+       }
+    }
 
+  if (! db)
+    {
       /* Check in the home directory.  This is a bit of a hack; let's
         hope one's home directory doesn't contain any %-escapes.  */
-      || (free_it = gethomedir (),
-         ((file = search_magic_path (free_it, class, "%L/%N"))
-          || (file = search_magic_path (free_it, class, "%N")))))
-    {
-      XrmDatabase db = XrmGetFileDatabase (file);
-      xfree (file);
-      xfree (free_it);
-      return db;
+      char *home = gethomedir ();
+      db = search_magic_path (home, class, "%L/%N");
+      if (! db)
+       db = search_magic_path (home, class, "%N");
+      xfree (home);
     }
 
-  xfree (free_it);
-  return NULL;
+  return db;
 }