]> code.delx.au - gnu-emacs/blobdiff - src/xrdb.c
(have_menus_p): Renamed from using_x_p.
[gnu-emacs] / src / xrdb.c
index ea0cbc89b3187db8b191da1162d1d97fce003413..ea2bdd13c007679af7684990e7e6f8ff3297b04d 100644 (file)
@@ -1,5 +1,5 @@
 /* Deal with the X Resource Manager.
-   Copyright (C) 1990, 1993 Free Software Foundation.
+   Copyright (C) 1990, 1993, 1994 Free Software Foundation.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Written by jla, 4/90 */
 
 #ifdef emacs
-#include "config.h"
+#include <config.h>
 #endif
 
 #include <stdio.h>
@@ -26,16 +26,14 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #if 1 /* I'd really appreciate it if this code could go away...  -JimB */
 /* this avoids lossage in the `dual-universe' headers on AT&T SysV X11 */
 #ifdef USG5
+#ifndef SYSV
 #define SYSV
+#endif
 #include <unistd.h>
 #endif /* USG5 */
 
 #endif /* 1 */
 
-/* This should be included before the X include files; otherwise, we get
-   warnings about redefining NULL under BSD 4.3.  */
-#include <sys/param.h>
-
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #if 0
@@ -51,8 +49,8 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif
 #include <sys/stat.h>
 
-#ifndef MAXPATHLEN
-#define MAXPATHLEN     256
+#if !defined(S_ISDIR) && defined(S_IFDIR)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 #endif
 
 extern char *getenv ();
@@ -65,7 +63,7 @@ extern short getuid ();               /* If this causes portability problems,
                                   default to `int' anyway.  */
 #endif
 
-#if defined (__bsdi__) || defined (DECLARE_GETPWUID_WITH_UID_T)
+#ifdef DECLARE_GETPWUID_WITH_UID_T
 extern struct passwd *getpwuid (uid_t);
 extern struct passwd *getpwnam (const char *);
 #else
@@ -73,6 +71,8 @@ extern struct passwd *getpwuid ();
 extern struct passwd *getpwnam ();
 #endif
 
+extern char *get_system_name ();
+
 /* Make sure not to #include anything after these definitions.  Let's
    not step on anyone's prototypes.  */
 #ifdef emacs
@@ -113,7 +113,11 @@ x_get_customization_string (db, name, class)
   result = x_get_string_resource (db, full_name, full_class);
 
   if (result)
-    return strcpy ((char *) malloc (strlen (result) + 1), result);
+    {
+      char *copy = (char *) malloc (strlen (result) + 1);
+      strcpy (copy, result);
+      return copy;
+    }
   else
     return 0;
 }
@@ -278,20 +282,17 @@ magic_file_p (string, string_len, class, escaped_suffix, suffix)
 static char *
 gethomedir ()
 {
-  int uid;
   struct passwd *pw;
   char *ptr;
   char *copy;
 
   if ((ptr = getenv ("HOME")) == NULL)
     {
-      if ((ptr = getenv ("USER")) != NULL)
+      if ((ptr = getenv ("LOGNAME")) != NULL
+         || (ptr = getenv ("USER")) != NULL)
        pw = getpwnam (ptr);
       else
-       {
-         uid = getuid ();
-         pw = getpwuid (uid);
-       }
+       pw = getpwuid (getuid ());
 
       if (pw)
        ptr = pw->pw_dir;
@@ -316,7 +317,7 @@ file_p (path)
 
   return (access (path, 4) == 0                        /* exists and is readable */
          && stat (path, &status) == 0          /* get the status */
-         && (status.st_mode & S_IFDIR) == 0);  /* not a directory */
+         && (S_ISDIR (status.st_mode)) == 0);  /* not a directory */
 }
 
 
@@ -335,22 +336,18 @@ search_magic_path (search_path, class, escaped_suffix, suffix)
       for (p = s; *p && *p != ':'; p++)
        ;
       
-      if (*p == ':' && *(p + 1) == ':')
+      if (p > s)
        {
-         char *path;
-
-         s = "%N%S";
-         path = magic_file_p (s, strlen (s), class, escaped_suffix, suffix);
+         char *path = magic_file_p (s, p - s, class, escaped_suffix, suffix);
          if (path)
            return path;
-
-         s = p + 1;
-         continue;
        }
-
-      if (p > s)
+      else if (*p == ':')
        {
-         char *path = magic_file_p (s, p - s, class, escaped_suffix, suffix);
+         char *path;
+
+         s = "%N%S";
+         path = magic_file_p (s, strlen (s), class, escaped_suffix, suffix);
          if (path)
            return path;
        }
@@ -477,26 +474,12 @@ get_environ_db ()
 {
   XrmDatabase db;
   char *p;
-  char *path = 0, *home = 0, *host = 0;
+  char *path = 0, *home = 0, *host;
 
   if ((p = getenv ("XENVIRONMENT")) == NULL)
     {
       home = gethomedir ();
-
-      {
-       int host_size = 100;
-       host = (char *) malloc (host_size);
-       
-       for (;;)
-         {
-           host[host_size - 1] = '\0';
-           gethostname (host, host_size - 1);
-           if (strlen (host) < host_size - 1)
-             break;
-           host = (char *) realloc (host, host_size *= 2);
-         }
-      }
-
+      host = get_system_name ();
       path = (char *) malloc (strlen (home)
                              + sizeof (".Xdefaults-")
                              + strlen (host));
@@ -508,7 +491,6 @@ get_environ_db ()
 
   if (path) free (path);
   if (home) free (home);
-  if (host) free (host);
 
   return db;
 }
@@ -533,7 +515,11 @@ x_load_resources (display, xrm_string, myname, myclass)
   XrmDatabase db;
 
   x_rm_string = XrmStringToQuark (XrmStringType);
+#ifndef USE_X_TOOLKIT
+  /* pmr@osf.org says this shouldn't be done if USE_X_TOOLKIT.
+     I suspect it's because the toolkit version does this elsewhere.  */
   XrmInitialize ();
+#endif
   rdb = XrmGetStringDatabase ("");
 
   user_database = get_user_db (display);