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