/* 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
/* Written by jla, 4/90 */
#ifdef emacs
-#include "config.h"
+#include <config.h>
#endif
#include <stdio.h>
#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
#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 ();
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
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
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;
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 */
}
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;
}
{
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));
if (path) free (path);
if (home) free (home);
- if (host) free (host);
return db;
}
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);