Mercurial > emacs
annotate src/xrdb.c @ 24658:7de5cc79a8b4
(file-name-buffer-file-type-alist): Remove various
file extension regexps which aren't necessarily binary files.
author | Andrew Innes <andrewi@gnu.org> |
---|---|
date | Sun, 02 May 1999 09:36:07 +0000 |
parents | d11ac02f9d6a |
children | f1632be03391 |
rev | line source |
---|---|
159 | 1 /* Deal with the X Resource Manager. |
7307 | 2 Copyright (C) 1990, 1993, 1994 Free Software Foundation. |
159 | 3 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
4 This file is part of GNU Emacs. |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
5 |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
6 GNU Emacs is free software; you can redistribute it and/or modify |
159 | 7 it under the terms of the GNU General Public License as published by |
620 | 8 the Free Software Foundation; either version 2, or (at your option) |
159 | 9 any later version. |
10 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
11 GNU Emacs is distributed in the hope that it will be useful, |
159 | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
17 along with GNU Emacs; see the file COPYING. If not, write to |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
10463
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
159 | 20 |
21 /* Written by jla, 4/90 */ | |
22 | |
1019
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
23 #ifdef emacs |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4538
diff
changeset
|
24 #include <config.h> |
1019
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
25 #endif |
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
26 |
21514 | 27 #ifdef HAVE_UNISTD_H |
28 #include <unistd.h> | |
29 #endif | |
30 | |
24412
d11ac02f9d6a
Use epaths.h istead of paths.h.
Richard M. Stallman <rms@gnu.org>
parents:
21514
diff
changeset
|
31 #include <epaths.h> |
19393 | 32 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
33 #include <stdio.h> |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
34 |
1019
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
35 #if 1 /* I'd really appreciate it if this code could go away... -JimB */ |
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
36 /* this avoids lossage in the `dual-universe' headers on AT&T SysV X11 */ |
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
37 #ifdef USG5 |
8295
51cebd28b474
[USG5] (SYSV): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents:
7342
diff
changeset
|
38 #ifndef SYSV |
1019
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
39 #define SYSV |
8295
51cebd28b474
[USG5] (SYSV): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents:
7342
diff
changeset
|
40 #endif |
1019
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
41 #include <unistd.h> |
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
42 #endif /* USG5 */ |
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
43 |
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
44 #endif /* 1 */ |
1389
517c3893ec5b
* xterm.c, xrdb.c: #include <stdio.h> before "xterm.h", to avoid
Jim Blandy <jimb@redhat.com>
parents:
1200
diff
changeset
|
45 |
159 | 46 #include <X11/Xlib.h> |
47 #include <X11/Xatom.h> | |
1126
94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
Jim Blandy <jimb@redhat.com>
parents:
1051
diff
changeset
|
48 #if 0 |
159 | 49 #include <X11/Xos.h> |
1126
94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
Jim Blandy <jimb@redhat.com>
parents:
1051
diff
changeset
|
50 #endif |
159 | 51 #include <X11/X.h> |
52 #include <X11/Xutil.h> | |
53 #include <X11/Xresource.h> | |
556 | 54 #ifdef VMS |
55 #include "vms-pwd.h" | |
56 #else | |
159 | 57 #include <pwd.h> |
556 | 58 #endif |
159 | 59 #include <sys/stat.h> |
60 | |
5650
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
61 #if !defined(S_ISDIR) && defined(S_IFDIR) |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
62 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
63 #endif |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
64 |
159 | 65 extern char *getenv (); |
1934
458a1fceb462
* xrdb.c (getuid): Remove declaration.
Jim Blandy <jimb@redhat.com>
parents:
1389
diff
changeset
|
66 |
458a1fceb462
* xrdb.c (getuid): Remove declaration.
Jim Blandy <jimb@redhat.com>
parents:
1389
diff
changeset
|
67 /* This does cause trouble on AIX. I'm going to take the comment at |
458a1fceb462
* xrdb.c (getuid): Remove declaration.
Jim Blandy <jimb@redhat.com>
parents:
1389
diff
changeset
|
68 face value. */ |
458a1fceb462
* xrdb.c (getuid): Remove declaration.
Jim Blandy <jimb@redhat.com>
parents:
1389
diff
changeset
|
69 #if 0 |
1126
94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
Jim Blandy <jimb@redhat.com>
parents:
1051
diff
changeset
|
70 extern short getuid (); /* If this causes portability problems, |
94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
Jim Blandy <jimb@redhat.com>
parents:
1051
diff
changeset
|
71 I think we should just delete it; it'll |
94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
Jim Blandy <jimb@redhat.com>
parents:
1051
diff
changeset
|
72 default to `int' anyway. */ |
1934
458a1fceb462
* xrdb.c (getuid): Remove declaration.
Jim Blandy <jimb@redhat.com>
parents:
1389
diff
changeset
|
73 #endif |
458a1fceb462
* xrdb.c (getuid): Remove declaration.
Jim Blandy <jimb@redhat.com>
parents:
1389
diff
changeset
|
74 |
8775
36f01bbb7d71
(getpwuid, getpwnam): Test just DECLARE_GETPWUID_WITH_UID_T, not __bsdi__.
Richard M. Stallman <rms@gnu.org>
parents:
8295
diff
changeset
|
75 #ifdef DECLARE_GETPWUID_WITH_UID_T |
3371
fe452e556782
[__bsdi__]: Alternate decls of getpwuid and getpwnam.
Richard M. Stallman <rms@gnu.org>
parents:
3142
diff
changeset
|
76 extern struct passwd *getpwuid (uid_t); |
fe452e556782
[__bsdi__]: Alternate decls of getpwuid and getpwnam.
Richard M. Stallman <rms@gnu.org>
parents:
3142
diff
changeset
|
77 extern struct passwd *getpwnam (const char *); |
fe452e556782
[__bsdi__]: Alternate decls of getpwuid and getpwnam.
Richard M. Stallman <rms@gnu.org>
parents:
3142
diff
changeset
|
78 #else |
159 | 79 extern struct passwd *getpwuid (); |
80 extern struct passwd *getpwnam (); | |
3371
fe452e556782
[__bsdi__]: Alternate decls of getpwuid and getpwnam.
Richard M. Stallman <rms@gnu.org>
parents:
3142
diff
changeset
|
81 #endif |
159 | 82 |
5735
87611653922f
(x_get_customization_string): Use get_system_name instead of gethostname.
Karl Heuer <kwzh@gnu.org>
parents:
5650
diff
changeset
|
83 extern char *get_system_name (); |
87611653922f
(x_get_customization_string): Use get_system_name instead of gethostname.
Karl Heuer <kwzh@gnu.org>
parents:
5650
diff
changeset
|
84 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
85 /* Make sure not to #include anything after these definitions. Let's |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
86 not step on anyone's prototypes. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
87 #ifdef emacs |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
88 #define malloc xmalloc |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
89 #define realloc xrealloc |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
90 #define free xfree |
21514 | 91 extern long *xmalloc (), *xrealloc (); |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
92 #endif |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
93 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
94 char *x_get_string_resource (); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
95 static int file_p (); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
96 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
97 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
98 /* X file search path processing. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
99 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
100 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
101 /* The string which gets substituted for the %C escape in XFILESEARCHPATH |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
102 and friends, or zero if none was specified. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
103 char *x_customization_string; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
104 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
105 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
106 /* Return the value of the emacs.customization (Emacs.Customization) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
107 resource, for later use in search path decoding. If we find no |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
108 such resource, return zero. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
109 char * |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
110 x_get_customization_string (db, name, class) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
111 XrmDatabase db; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
112 char *name, *class; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
113 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
114 char *full_name |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
115 = (char *) alloca (strlen (name) + sizeof ("customization") + 3); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
116 char *full_class |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
117 = (char *) alloca (strlen (class) + sizeof ("Customization") + 3); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
118 char *result; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
119 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
120 sprintf (full_name, "%s.%s", name, "customization"); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
121 sprintf (full_class, "%s.%s", class, "Customization"); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
122 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
123 result = x_get_string_resource (db, full_name, full_class); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
124 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
125 if (result) |
4538
0fd9dd894f9f
(x_get_customization_string): Don't use value of strcpy.
Richard M. Stallman <rms@gnu.org>
parents:
4366
diff
changeset
|
126 { |
0fd9dd894f9f
(x_get_customization_string): Don't use value of strcpy.
Richard M. Stallman <rms@gnu.org>
parents:
4366
diff
changeset
|
127 char *copy = (char *) malloc (strlen (result) + 1); |
0fd9dd894f9f
(x_get_customization_string): Don't use value of strcpy.
Richard M. Stallman <rms@gnu.org>
parents:
4366
diff
changeset
|
128 strcpy (copy, result); |
0fd9dd894f9f
(x_get_customization_string): Don't use value of strcpy.
Richard M. Stallman <rms@gnu.org>
parents:
4366
diff
changeset
|
129 return copy; |
0fd9dd894f9f
(x_get_customization_string): Don't use value of strcpy.
Richard M. Stallman <rms@gnu.org>
parents:
4366
diff
changeset
|
130 } |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
131 else |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
132 return 0; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
133 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
134 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
135 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
136 /* Expand all the Xt-style %-escapes in STRING, whose length is given |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
137 by STRING_LEN. Here are the escapes we're supposed to recognize: |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
138 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
139 %N The value of the application's class name |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
140 %T The value of the type parameter ("app-defaults" in this |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
141 context) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
142 %S The value of the suffix parameter ("" in this context) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
143 %L The language string associated with the specified display |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
144 (We use the "LANG" environment variable here, if it's set.) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
145 %l The language part of the display's language string |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
146 (We treat this just like %L. If someone can tell us what |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
147 we're really supposed to do, dandy.) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
148 %t The territory part of the display's language string |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
149 (This never gets used.) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
150 %c The codeset part of the display's language string |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
151 (This never gets used either.) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
152 %C The customization string retrieved from the resource |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
153 database associated with display. |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
154 (This is x_customization_string.) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
155 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
156 Return the expanded file name if it exists and is readable, and |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
157 refers to %L only when the LANG environment variable is set, or |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
158 otherwise provided by X. |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
159 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
160 ESCAPED_SUFFIX and SUFFIX are postpended to STRING if they are |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
161 non-zero. %-escapes in ESCAPED_SUFFIX are expanded; STRING is left |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
162 alone. |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
163 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
164 Return NULL otherwise. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
165 |
159 | 166 static char * |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
167 magic_file_p (string, string_len, class, escaped_suffix, suffix) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
168 char *string; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
169 int string_len; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
170 char *class, *escaped_suffix, *suffix; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
171 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
172 char *lang = getenv ("LANG"); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
173 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
174 int path_size = 100; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
175 char *path = (char *) malloc (path_size); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
176 int path_len = 0; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
177 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
178 char *p = string; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
179 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
180 while (p < string + string_len) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
181 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
182 /* The chunk we're about to stick on the end of result. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
183 char *next; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
184 int next_len; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
185 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
186 if (*p == '%') |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
187 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
188 p++; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
189 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
190 if (p >= string + string_len) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
191 next_len = 0; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
192 else |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
193 switch (*p) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
194 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
195 case '%': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
196 next = "%"; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
197 next_len = 1; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
198 break; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
199 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
200 case 'C': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
201 next = (x_customization_string |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
202 ? x_customization_string |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
203 : ""); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
204 next_len = strlen (next); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
205 break; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
206 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
207 case 'N': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
208 next = class; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
209 next_len = strlen (class); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
210 break; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
211 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
212 case 'T': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
213 next = "app-defaults"; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
214 next_len = strlen (next); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
215 break; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
216 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
217 default: |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
218 case 'S': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
219 next_len = 0; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
220 break; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
221 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
222 case 'L': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
223 case 'l': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
224 if (! lang) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
225 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
226 free (path); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
227 return NULL; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
228 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
229 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
230 next = lang; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
231 next_len = strlen (next); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
232 break; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
233 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
234 case 't': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
235 case 'c': |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
236 free (path); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
237 return NULL; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
238 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
239 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
240 else |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
241 next = p, next_len = 1; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
242 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
243 /* Do we have room for this component followed by a '\0' ? */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
244 if (path_len + next_len + 1 > path_size) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
245 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
246 path_size = (path_len + next_len + 1) * 2; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
247 path = (char *) realloc (path, path_size); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
248 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
249 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
250 bcopy (next, path + path_len, next_len); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
251 path_len += next_len; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
252 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
253 p++; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
254 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
255 /* If we've reached the end of the string, append ESCAPED_SUFFIX. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
256 if (p >= string + string_len && escaped_suffix) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
257 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
258 string = escaped_suffix; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
259 string_len = strlen (string); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
260 p = string; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
261 escaped_suffix = NULL; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
262 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
263 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
264 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
265 /* Perhaps we should add the SUFFIX now. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
266 if (suffix) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
267 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
268 int suffix_len = strlen (suffix); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
269 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
270 if (path_len + suffix_len + 1 > path_size) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
271 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
272 path_size = (path_len + suffix_len + 1); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
273 path = (char *) realloc (path, path_size); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
274 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
275 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
276 bcopy (suffix, path + path_len, suffix_len); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
277 path_len += suffix_len; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
278 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
279 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
280 path[path_len] = '\0'; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
281 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
282 if (! file_p (path)) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
283 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
284 free (path); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
285 return NULL; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
286 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
287 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
288 return path; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
289 } |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
290 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
291 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
292 static char * |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
293 gethomedir () |
159 | 294 { |
295 struct passwd *pw; | |
296 char *ptr; | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
297 char *copy; |
159 | 298 |
299 if ((ptr = getenv ("HOME")) == NULL) | |
300 { | |
5917
91caeed50c64
(gethomedir): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents:
5735
diff
changeset
|
301 if ((ptr = getenv ("LOGNAME")) != NULL |
91caeed50c64
(gethomedir): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents:
5735
diff
changeset
|
302 || (ptr = getenv ("USER")) != NULL) |
159 | 303 pw = getpwnam (ptr); |
304 else | |
5917
91caeed50c64
(gethomedir): Look at LOGNAME before USER.
Karl Heuer <kwzh@gnu.org>
parents:
5735
diff
changeset
|
305 pw = getpwuid (getuid ()); |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
306 |
159 | 307 if (pw) |
308 ptr = pw->pw_dir; | |
309 } | |
310 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
311 if (ptr == NULL) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
312 return "/"; |
159 | 313 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
314 copy = (char *) malloc (strlen (ptr) + 2); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
315 strcpy (copy, ptr); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
316 strcat (copy, "/"); |
159 | 317 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
318 return copy; |
159 | 319 } |
320 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
321 |
159 | 322 static int |
323 file_p (path) | |
324 char *path; | |
325 { | |
326 struct stat status; | |
327 | |
1126
94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
Jim Blandy <jimb@redhat.com>
parents:
1051
diff
changeset
|
328 return (access (path, 4) == 0 /* exists and is readable */ |
159 | 329 && stat (path, &status) == 0 /* get the status */ |
5650
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
330 && (S_ISDIR (status.st_mode)) == 0); /* not a directory */ |
159 | 331 } |
332 | |
333 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
334 /* Find the first element of SEARCH_PATH which exists and is readable, |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
335 after expanding the %-escapes. Return 0 if we didn't find any, and |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
336 the path name of the one we found otherwise. */ |
159 | 337 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
338 static char * |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
339 search_magic_path (search_path, class, escaped_suffix, suffix) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
340 char *search_path, *class, *escaped_suffix, *suffix; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
341 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
342 register char *s, *p; |
159 | 343 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
344 for (s = search_path; *s; s = p) |
159 | 345 { |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
346 for (p = s; *p && *p != ':'; p++) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
347 ; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
348 |
5650
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
349 if (p > s) |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
350 { |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
351 char *path = magic_file_p (s, p - s, class, escaped_suffix, suffix); |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
352 if (path) |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
353 return path; |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
354 } |
1476768ef7fc
(S_ISDIR): Define if not defined.
Richard M. Stallman <rms@gnu.org>
parents:
5116
diff
changeset
|
355 else if (*p == ':') |
159 | 356 { |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
357 char *path; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
358 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
359 s = "%N%S"; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
360 path = magic_file_p (s, strlen (s), class, escaped_suffix, suffix); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
361 if (path) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
362 return path; |
159 | 363 } |
364 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
365 if (*p == ':') |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
366 p++; |
159 | 367 } |
368 | |
369 return 0; | |
370 } | |
371 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
372 /* Producing databases for individual sources. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
373 |
159 | 374 static XrmDatabase |
375 get_system_app (class) | |
376 char *class; | |
377 { | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
378 XrmDatabase db = NULL; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
379 char *path; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
380 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
381 path = getenv ("XFILESEARCHPATH"); |
19388
0f27d1477c21
(get_system_app): Use PATH_X_DEFAULTS.
Richard M. Stallman <rms@gnu.org>
parents:
19318
diff
changeset
|
382 if (! path) path = PATH_X_DEFAULTS; |
159 | 383 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
384 path = search_magic_path (path, class, 0, 0); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
385 if (path) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
386 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
387 db = XrmGetFileDatabase (path); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
388 free (path); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
389 } |
159 | 390 |
391 return db; | |
392 } | |
393 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
394 |
159 | 395 static XrmDatabase |
396 get_fallback (display) | |
397 Display *display; | |
398 { | |
399 XrmDatabase db; | |
400 | |
401 return NULL; | |
402 } | |
403 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
404 |
159 | 405 static XrmDatabase |
406 get_user_app (class) | |
407 char *class; | |
408 { | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
409 char *path; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
410 char *file = 0; |
17572
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
411 char *free_it = 0; |
159 | 412 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
413 /* Check for XUSERFILESEARCHPATH. It is a path of complete file |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
414 names, not directories. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
415 if (((path = getenv ("XUSERFILESEARCHPATH")) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
416 && (file = search_magic_path (path, class, 0, 0))) |
159 | 417 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
418 /* Check for APPLRESDIR; it is a path of directories. In each, |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
419 we have to search for LANG/CLASS and then CLASS. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
420 || ((path = getenv ("XAPPLRESDIR")) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
421 && ((file = search_magic_path (path, class, "/%L/%N", 0)) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
422 || (file = search_magic_path (path, class, "/%N", 0)))) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
423 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
424 /* Check in the home directory. This is a bit of a hack; let's |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
425 hope one's home directory doesn't contain any %-escapes. */ |
17572
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
426 || (free_it = gethomedir (), |
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
427 ((file = search_magic_path (free_it, class, "%L/%N", 0)) |
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
428 || (file = search_magic_path (free_it, class, "%N", 0))))) |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
429 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
430 XrmDatabase db = XrmGetFileDatabase (file); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
431 free (file); |
17572
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
432 if (free_it) |
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
433 free (free_it); |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
434 return db; |
159 | 435 } |
17572
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
436 |
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
437 if (free_it) |
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
438 free (free_it); |
73d867b4a654
(get_user_app): Free the gethomedir value.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
439 return NULL; |
159 | 440 } |
441 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
442 |
159 | 443 static XrmDatabase |
444 get_user_db (display) | |
445 Display *display; | |
446 { | |
447 XrmDatabase db; | |
448 char *xdefs; | |
449 | |
2126
616aeb5c1432
* xrdb.c (get_user_db): Since xrdb.c doesn't #include xterm.h,
Jim Blandy <jimb@redhat.com>
parents:
1934
diff
changeset
|
450 #ifdef PBaseSize /* Cheap way to test for X11R4 or later. */ |
1051
777ed2b92359
* xrdb.c (get_user_db): Use XResourceManagerString when available
Jim Blandy <jimb@redhat.com>
parents:
1019
diff
changeset
|
451 xdefs = XResourceManagerString (display); |
777ed2b92359
* xrdb.c (get_user_db): Use XResourceManagerString when available
Jim Blandy <jimb@redhat.com>
parents:
1019
diff
changeset
|
452 #else |
1019
aaa628aaf808
* xrdb.c [USG5]: Define SYSV, and then include <unistd.h>. I
Jim Blandy <jimb@redhat.com>
parents:
620
diff
changeset
|
453 xdefs = display->xdefaults; |
1051
777ed2b92359
* xrdb.c (get_user_db): Use XResourceManagerString when available
Jim Blandy <jimb@redhat.com>
parents:
1019
diff
changeset
|
454 #endif |
777ed2b92359
* xrdb.c (get_user_db): Use XResourceManagerString when available
Jim Blandy <jimb@redhat.com>
parents:
1019
diff
changeset
|
455 |
159 | 456 if (xdefs != NULL) |
457 db = XrmGetStringDatabase (xdefs); | |
458 else | |
459 { | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
460 char *home; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
461 char *xdefault; |
159 | 462 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
463 home = gethomedir (); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
464 xdefault = (char *) malloc (strlen (home) + sizeof (".Xdefaults")); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
465 strcpy (xdefault, home); |
159 | 466 strcat (xdefault, ".Xdefaults"); |
467 db = XrmGetFileDatabase (xdefault); | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
468 free (home); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
469 free (xdefault); |
159 | 470 } |
471 | |
4366
04bd0c1a6245
* config.h.in (HAVE_XSCREENRESOURCESTRING): New #undef for
Jim Blandy <jimb@redhat.com>
parents:
4233
diff
changeset
|
472 #ifdef HAVE_XSCREENRESOURCESTRING |
3654
d9313b9a63ad
* xrdb.c (get_user_db): Get the screen-specific database too.
Jim Blandy <jimb@redhat.com>
parents:
3371
diff
changeset
|
473 /* Get the screen-specific resources too. */ |
d9313b9a63ad
* xrdb.c (get_user_db): Get the screen-specific database too.
Jim Blandy <jimb@redhat.com>
parents:
3371
diff
changeset
|
474 xdefs = XScreenResourceString (DefaultScreenOfDisplay (display)); |
d9313b9a63ad
* xrdb.c (get_user_db): Get the screen-specific database too.
Jim Blandy <jimb@redhat.com>
parents:
3371
diff
changeset
|
475 if (xdefs != NULL) |
3873
e67c6c10dd7c
* xrdb.c (get_user_db): Remember to free the screen-local resource
Jim Blandy <jimb@redhat.com>
parents:
3654
diff
changeset
|
476 { |
e67c6c10dd7c
* xrdb.c (get_user_db): Remember to free the screen-local resource
Jim Blandy <jimb@redhat.com>
parents:
3654
diff
changeset
|
477 XrmMergeDatabases (XrmGetStringDatabase (xdefs), &db); |
e67c6c10dd7c
* xrdb.c (get_user_db): Remember to free the screen-local resource
Jim Blandy <jimb@redhat.com>
parents:
3654
diff
changeset
|
478 XFree (xdefs); |
e67c6c10dd7c
* xrdb.c (get_user_db): Remember to free the screen-local resource
Jim Blandy <jimb@redhat.com>
parents:
3654
diff
changeset
|
479 } |
3654
d9313b9a63ad
* xrdb.c (get_user_db): Get the screen-specific database too.
Jim Blandy <jimb@redhat.com>
parents:
3371
diff
changeset
|
480 #endif |
d9313b9a63ad
* xrdb.c (get_user_db): Get the screen-specific database too.
Jim Blandy <jimb@redhat.com>
parents:
3371
diff
changeset
|
481 |
159 | 482 return db; |
483 } | |
484 | |
485 static XrmDatabase | |
486 get_environ_db () | |
487 { | |
488 XrmDatabase db; | |
489 char *p; | |
5735
87611653922f
(x_get_customization_string): Use get_system_name instead of gethostname.
Karl Heuer <kwzh@gnu.org>
parents:
5650
diff
changeset
|
490 char *path = 0, *home = 0, *host; |
159 | 491 |
492 if ((p = getenv ("XENVIRONMENT")) == NULL) | |
493 { | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
494 home = gethomedir (); |
5735
87611653922f
(x_get_customization_string): Use get_system_name instead of gethostname.
Karl Heuer <kwzh@gnu.org>
parents:
5650
diff
changeset
|
495 host = get_system_name (); |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
496 path = (char *) malloc (strlen (home) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
497 + sizeof (".Xdefaults-") |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
498 + strlen (host)); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
499 sprintf (path, "%s%s%s", home, ".Xdefaults-", host); |
159 | 500 p = path; |
501 } | |
502 | |
503 db = XrmGetFileDatabase (p); | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
504 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
505 if (path) free (path); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
506 if (home) free (home); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
507 |
159 | 508 return db; |
509 } | |
510 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
511 /* External interface. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
512 |
159 | 513 /* Types of values that we can find in a database */ |
514 | |
515 #define XrmStringType "String" /* String representation */ | |
516 XrmRepresentation x_rm_string; /* Quark representation */ | |
517 | |
518 /* Load X resources based on the display and a possible -xrm option. */ | |
519 | |
520 XrmDatabase | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
521 x_load_resources (display, xrm_string, myname, myclass) |
159 | 522 Display *display; |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
523 char *xrm_string, *myname, *myclass; |
159 | 524 { |
525 char *xdefs; | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
526 XrmDatabase user_database; |
159 | 527 XrmDatabase rdb; |
528 XrmDatabase db; | |
529 | |
530 x_rm_string = XrmStringToQuark (XrmStringType); | |
7342
4cf4669565af
(x_load_resources) [USE_X_TOOLKIT]: Don't call XrmInitialize.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
531 #ifndef USE_X_TOOLKIT |
4cf4669565af
(x_load_resources) [USE_X_TOOLKIT]: Don't call XrmInitialize.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
532 /* pmr@osf.org says this shouldn't be done if USE_X_TOOLKIT. |
4cf4669565af
(x_load_resources) [USE_X_TOOLKIT]: Don't call XrmInitialize.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
533 I suspect it's because the toolkit version does this elsewhere. */ |
159 | 534 XrmInitialize (); |
7342
4cf4669565af
(x_load_resources) [USE_X_TOOLKIT]: Don't call XrmInitialize.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
535 #endif |
159 | 536 rdb = XrmGetStringDatabase (""); |
537 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
538 user_database = get_user_db (display); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
539 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
540 /* Figure out what the "customization string" is, so we can use it |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
541 to decode paths. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
542 if (x_customization_string) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
543 free (x_customization_string); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
544 x_customization_string |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
545 = x_get_customization_string (user_database, myname, myclass); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
546 |
159 | 547 /* Get application system defaults */ |
548 db = get_system_app (myclass); | |
549 if (db != NULL) | |
550 XrmMergeDatabases (db, &rdb); | |
551 | |
552 /* Get Fallback resources */ | |
553 db = get_fallback (display); | |
554 if (db != NULL) | |
555 XrmMergeDatabases (db, &rdb); | |
556 | |
557 /* Get application user defaults */ | |
558 db = get_user_app (myclass); | |
559 if (db != NULL) | |
560 XrmMergeDatabases (db, &rdb); | |
561 | |
562 /* get User defaults */ | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
563 if (user_database != NULL) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
564 XrmMergeDatabases (user_database, &rdb); |
159 | 565 |
566 /* Get Environment defaults. */ | |
567 db = get_environ_db (); | |
568 if (db != NULL) | |
569 XrmMergeDatabases (db, &rdb); | |
570 | |
571 /* Last, merge in any specification from the command line. */ | |
572 if (xrm_string != NULL) | |
573 { | |
574 db = XrmGetStringDatabase (xrm_string); | |
575 if (db != NULL) | |
576 XrmMergeDatabases (db, &rdb); | |
577 } | |
578 | |
579 return rdb; | |
580 } | |
581 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
582 |
159 | 583 /* Retrieve the value of the resource specified by NAME with class CLASS |
584 and of type TYPE from database RDB. The value is returned in RET_VALUE. */ | |
585 | |
586 int | |
587 x_get_resource (rdb, name, class, expected_type, ret_value) | |
588 XrmDatabase rdb; | |
589 char *name, *class; | |
590 XrmRepresentation expected_type; | |
591 XrmValue *ret_value; | |
592 { | |
593 XrmValue value; | |
594 XrmName namelist[100]; | |
595 XrmClass classlist[100]; | |
596 XrmRepresentation type; | |
597 | |
598 XrmStringToNameList(name, namelist); | |
599 XrmStringToClassList(class, classlist); | |
600 | |
601 if (XrmQGetResource (rdb, namelist, classlist, &type, &value) == True | |
602 && (type == expected_type)) | |
603 { | |
604 if (type == x_rm_string) | |
1200
d2360c870787
* xrdb.c (x_get_resource): Cast the value being assigned to
Jim Blandy <jimb@redhat.com>
parents:
1126
diff
changeset
|
605 ret_value->addr = (char *) value.addr; |
159 | 606 else |
607 bcopy (value.addr, ret_value->addr, ret_value->size); | |
608 | |
609 return value.size; | |
610 } | |
611 | |
612 return 0; | |
613 } | |
614 | |
615 /* Retrieve the string resource specified by NAME with CLASS from | |
616 database RDB. */ | |
617 | |
618 char * | |
619 x_get_string_resource (rdb, name, class) | |
620 XrmDatabase rdb; | |
621 char *name, *class; | |
622 { | |
623 XrmValue value; | |
624 | |
625 if (x_get_resource (rdb, name, class, x_rm_string, &value)) | |
626 return (char *) value.addr; | |
627 | |
628 return (char *) 0; | |
629 } | |
630 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
631 /* Stand-alone test facilities. */ |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
632 |
159 | 633 #ifdef TESTRM |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
634 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
635 typedef char **List; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
636 #define arg_listify(len, list) (list) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
637 #define car(list) (*(list)) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
638 #define cdr(list) (list + 1) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
639 #define NIL(list) (! *(list)) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
640 #define free_arglist(list) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
641 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
642 static List |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
643 member (elt, list) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
644 char *elt; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
645 List list; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
646 { |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
647 List p; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
648 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
649 for (p = list; ! NIL (p); p = cdr (p)) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
650 if (! strcmp (elt, car (p))) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
651 return p; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
652 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
653 return p; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
654 } |
159 | 655 |
656 static void | |
657 fatal (msg, prog, x1, x2, x3, x4, x5) | |
658 char *msg, *prog; | |
659 int x1, x2, x3, x4, x5; | |
660 { | |
661 extern int errno; | |
662 | |
663 if (errno) | |
664 perror (prog); | |
665 | |
666 (void) fprintf (stderr, msg, prog, x1, x2, x3, x4, x5); | |
667 exit (1); | |
668 } | |
669 | |
670 main (argc, argv) | |
671 int argc; | |
672 char **argv; | |
673 { | |
674 Display *display; | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
675 char *displayname, *resource_string, *class, *name; |
159 | 676 XrmDatabase xdb; |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
677 List arg_list, lp; |
159 | 678 |
679 arg_list = arg_listify (argc, argv); | |
680 | |
681 lp = member ("-d", arg_list); | |
682 if (!NIL (lp)) | |
683 displayname = car (cdr (lp)); | |
684 else | |
685 displayname = "localhost:0.0"; | |
686 | |
687 lp = member ("-xrm", arg_list); | |
688 if (! NIL (lp)) | |
689 resource_string = car (cdr (lp)); | |
690 else | |
691 resource_string = (char *) 0; | |
692 | |
693 lp = member ("-c", arg_list); | |
694 if (! NIL (lp)) | |
695 class = car (cdr (lp)); | |
696 else | |
697 class = "Emacs"; | |
698 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
699 lp = member ("-n", arg_list); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
700 if (! NIL (lp)) |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
701 name = car (cdr (lp)); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
702 else |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
703 name = "emacs"; |
159 | 704 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
705 free_arglist (arg_list); |
159 | 706 |
707 if (!(display = XOpenDisplay (displayname))) | |
708 fatal ("Can't open display '%s'\n", XDisplayName (displayname)); | |
709 | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
710 xdb = x_load_resources (display, resource_string, name, class); |
159 | 711 |
712 /* In a real program, you'd want to also do this: */ | |
713 display->db = xdb; | |
714 | |
715 while (1) | |
716 { | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
717 char query_name[90]; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
718 char query_class[90]; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
719 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
720 printf ("Name: "); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
721 gets (query_name); |
159 | 722 |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
723 if (strlen (query_name)) |
159 | 724 { |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
725 char *value; |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
726 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
727 printf ("Class: "); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
728 gets (query_class); |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
729 |
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
730 value = x_get_string_resource (xdb, query_name, query_class); |
159 | 731 |
732 if (value != NULL) | |
4232
f533d585cfc8
Implement search for app-defaults directory and
Jim Blandy <jimb@redhat.com>
parents:
3873
diff
changeset
|
733 printf ("\t%s(%s): %s\n\n", query_name, query_class, value); |
159 | 734 else |
735 printf ("\tNo Value.\n\n"); | |
736 } | |
737 else | |
738 break; | |
739 } | |
740 printf ("\tExit.\n\n"); | |
741 | |
742 XCloseDisplay (display); | |
743 } | |
744 #endif /* TESTRM */ |