]> code.delx.au - gnu-emacs/blobdiff - src/xrdb.c
* make-dist: Distribute some VMS files we got from Richard Levitte.
[gnu-emacs] / src / xrdb.c
index 930b4d54d43a5e70b22dbbdea22e290b23d690fb..a83cb37fe53e9c9ef9cd530b74237a08a117bfd8 100644 (file)
@@ -1,9 +1,9 @@
 /* Deal with the X Resource Manager.
 /* Deal with the X Resource Manager.
-   Copyright (C) 1990 Free Software Foundation.
+   Copyright (C) 1990, 1992 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
 
 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
-the Free Software Foundation; either version 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 This program is distributed in the hope that it will be useful,
 any later version.
 
 This program is distributed in the hope that it will be useful,
@@ -17,22 +17,52 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 /* Written by jla, 4/90 */
 
 
 /* Written by jla, 4/90 */
 
+#ifdef emacs
+#include "config.h"
+#endif
+
+#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
+#define SYSV
+#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>
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
+#if 0
 #include <X11/Xos.h>
 #include <X11/Xos.h>
+#endif
 #include <X11/X.h>
 #include <X11/Xutil.h>
 #include <X11/Xresource.h>
 #include <X11/X.h>
 #include <X11/Xutil.h>
 #include <X11/Xresource.h>
-#include <sys/param.h>
+#ifdef VMS
+#include "vms-pwd.h"
+#else
 #include <pwd.h>
 #include <pwd.h>
+#endif
 #include <sys/stat.h>
 
 #include <sys/stat.h>
 
-#ifdef emacs
-#include "config.h"
+#ifndef MAXPATHLEN
+#define MAXPATHLEN     256
 #endif
 
 extern char *getenv ();
 #endif
 
 extern char *getenv ();
-extern int getuid ();
+
+/* This does cause trouble on AIX.  I'm going to take the comment at
+   face value.  */
+#if 0
+extern short getuid ();                /* If this causes portability problems,
+                                  I think we should just delete it; it'll
+                                  default to `int' anyway.  */
+#endif
+
 extern struct passwd *getpwuid ();
 extern struct passwd *getpwnam ();
 
 extern struct passwd *getpwuid ();
 extern struct passwd *getpwnam ();
 
@@ -79,7 +109,7 @@ file_p (path)
 {
   struct stat status;
 
 {
   struct stat status;
 
-  return (access (path, R_OK) == 0             /* exists and is readable */
+  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 */
 }
          && stat (path, &status) == 0          /* get the status */
          && (status.st_mode & S_IFDIR) == 0);  /* not a directory */
 }
@@ -141,7 +171,10 @@ magic_searchpath_decoder (incantation_string, file, return_path)
 {
   register char *s = incantation_string;
   register char *p;
 {
   register char *s = incantation_string;
   register char *p;
-  register char string[MAXPATHLEN];
+
+  /* Must be big enough for "%N%S".  */
+  register int string_size = MAXPATHLEN;
+  register char *string = (char *) alloca (string_size * sizeof (*string));
 
   while (*s)
     {
 
   while (*s)
     {
@@ -152,6 +185,7 @@ magic_searchpath_decoder (incantation_string, file, return_path)
 
       if (*p == ':' && *(p + 1) == ':')
        {
 
       if (*p == ':' && *(p + 1) == ':')
        {
+         /* We know string is big enough for this.  */
          bcopy ("%N%S", string, 5);
          if (decode_magic (string, file, return_path))
            return 1;
          bcopy ("%N%S", string, 5);
          if (decode_magic (string, file, return_path))
            return 1;
@@ -164,6 +198,11 @@ magic_searchpath_decoder (incantation_string, file, return_path)
        {
          int len = p - s;
 
        {
          int len = p - s;
 
+         if (string_size < len+1)
+           {
+             string_size = 2 * len;
+             string = (char *) alloca (string_size * sizeof (*string));
+           }
          bcopy (s, string, len);
          string[len + 1] = '\0';
          if (decode_magic (string, file, return_path))
          bcopy (s, string, len);
          string[len + 1] = '\0';
          if (decode_magic (string, file, return_path))
@@ -253,7 +292,12 @@ get_user_db (display)
   XrmDatabase db;
   char *xdefs;
 
   XrmDatabase db;
   char *xdefs;
 
+#ifdef PBaseSize               /* Cheap way to test for X11R4 or later.  */
   xdefs = XResourceManagerString (display);
   xdefs = XResourceManagerString (display);
+#else
+  xdefs = display->xdefaults;
+#endif
+
   if (xdefs != NULL)
     db = XrmGetStringDatabase (xdefs);
   else
   if (xdefs != NULL)
     db = XrmGetStringDatabase (xdefs);
   else
@@ -365,7 +409,7 @@ x_get_resource (rdb, name, class, expected_type, ret_value)
       && (type == expected_type))
     {
       if (type == x_rm_string)
       && (type == expected_type))
     {
       if (type == x_rm_string)
-       (char *) ret_value->addr = value.addr;
+       ret_value->addr = (char *) value.addr;
       else
        bcopy (value.addr, ret_value->addr, ret_value->size);
 
       else
        bcopy (value.addr, ret_value->addr, ret_value->size);