Commit | Line | Data |
---|---|---|
f3a0bf5c | 1 | /* Deal with the X Resource Manager. |
0b5538bd | 2 | Copyright (C) 1990, 1993, 1994, 2000, 2001, 2002, 2003, 2004, |
76b6f707 | 3 | 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
f3a0bf5c | 4 | |
90324359 GM |
5 | Author: Joseph Arceneaux |
6 | Created: 4/90 | |
7 | ||
3b7ad313 EN |
8 | This file is part of GNU Emacs. |
9 | ||
9ec0b715 | 10 | GNU Emacs is free software: you can redistribute it and/or modify |
f3a0bf5c | 11 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
12 | the Free Software Foundation, either version 3 of the License, or |
13 | (at your option) any later version. | |
f3a0bf5c | 14 | |
3b7ad313 | 15 | GNU Emacs is distributed in the hope that it will be useful, |
f3a0bf5c JB |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 21 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
f3a0bf5c | 22 | |
a2a4d43e | 23 | #ifdef emacs |
18160b98 | 24 | #include <config.h> |
a2a4d43e JB |
25 | #endif |
26 | ||
dfcf069d AS |
27 | #ifdef HAVE_UNISTD_H |
28 | #include <unistd.h> | |
29 | #endif | |
30 | ||
57bda87a | 31 | #include <epaths.h> |
012c3e71 | 32 | |
837255fb JB |
33 | #include <stdio.h> |
34 | ||
a2a4d43e | 35 | #if 1 /* I'd really appreciate it if this code could go away... -JimB */ |
cca1b1d7 GM |
36 | /* This avoids lossage in the `dual-universe' headers on AT&T SysV |
37 | X11. Don't do it on Solaris, because it breaks compilation with | |
38 | XFree86 4.0.3 (and probably many other X11R6 releases) on Solaris | |
39 | 2 */ | |
40 | #if defined(USG5) && !defined(SOLARIS2) | |
8f510a71 | 41 | #ifndef SYSV |
a2a4d43e | 42 | #define SYSV |
8f510a71 | 43 | #endif |
cca1b1d7 | 44 | #endif /* USG5 && !SOLARIS2 */ |
a2a4d43e JB |
45 | |
46 | #endif /* 1 */ | |
54c908b5 | 47 | |
f3a0bf5c JB |
48 | #include <X11/Xlib.h> |
49 | #include <X11/Xatom.h> | |
dfc35f5f | 50 | #if 0 |
f3a0bf5c | 51 | #include <X11/Xos.h> |
dfc35f5f | 52 | #endif |
f3a0bf5c JB |
53 | #include <X11/X.h> |
54 | #include <X11/Xutil.h> | |
55 | #include <X11/Xresource.h> | |
5b9c0a1d | 56 | #ifdef HAVE_PWD_H |
f3a0bf5c | 57 | #include <pwd.h> |
531ff254 | 58 | #endif |
f3a0bf5c JB |
59 | #include <sys/stat.h> |
60 | ||
0f2cd61f RS |
61 | #if !defined(S_ISDIR) && defined(S_IFDIR) |
62 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
63 | #endif | |
64 | ||
4da4f201 GM |
65 | #include "lisp.h" |
66 | ||
f3a0bf5c | 67 | extern char *getenv (); |
3d5d61ae JB |
68 | |
69 | /* This does cause trouble on AIX. I'm going to take the comment at | |
70 | face value. */ | |
71 | #if 0 | |
dfc35f5f JB |
72 | extern short getuid (); /* If this causes portability problems, |
73 | I think we should just delete it; it'll | |
74 | default to `int' anyway. */ | |
3d5d61ae JB |
75 | #endif |
76 | ||
2d487ae5 | 77 | #ifdef DECLARE_GETPWUID_WITH_UID_T |
3e0be4d0 RS |
78 | extern struct passwd *getpwuid (uid_t); |
79 | extern struct passwd *getpwnam (const char *); | |
80 | #else | |
f3a0bf5c JB |
81 | extern struct passwd *getpwuid (); |
82 | extern struct passwd *getpwnam (); | |
3e0be4d0 | 83 | #endif |
f3a0bf5c | 84 | |
e29ad342 KH |
85 | extern char *get_system_name (); |
86 | ||
837255fb JB |
87 | /* Make sure not to #include anything after these definitions. Let's |
88 | not step on anyone's prototypes. */ | |
89 | #ifdef emacs | |
0cf36656 KR |
90 | /* darwin.h may have already defined these. */ |
91 | #undef malloc | |
92 | #undef realloc | |
93 | #undef free | |
837255fb JB |
94 | #define malloc xmalloc |
95 | #define realloc xrealloc | |
96 | #define free xfree | |
97 | #endif | |
98 | ||
99 | char *x_get_string_resource (); | |
100 | static int file_p (); | |
101 | ||
102 | \f | |
103 | /* X file search path processing. */ | |
104 | ||
105 | ||
106 | /* The string which gets substituted for the %C escape in XFILESEARCHPATH | |
107 | and friends, or zero if none was specified. */ | |
108 | char *x_customization_string; | |
109 | ||
110 | ||
111 | /* Return the value of the emacs.customization (Emacs.Customization) | |
112 | resource, for later use in search path decoding. If we find no | |
113 | such resource, return zero. */ | |
114 | char * | |
115 | x_get_customization_string (db, name, class) | |
116 | XrmDatabase db; | |
117 | char *name, *class; | |
118 | { | |
119 | char *full_name | |
120 | = (char *) alloca (strlen (name) + sizeof ("customization") + 3); | |
121 | char *full_class | |
122 | = (char *) alloca (strlen (class) + sizeof ("Customization") + 3); | |
123 | char *result; | |
124 | ||
125 | sprintf (full_name, "%s.%s", name, "customization"); | |
126 | sprintf (full_class, "%s.%s", class, "Customization"); | |
127 | ||
128 | result = x_get_string_resource (db, full_name, full_class); | |
129 | ||
130 | if (result) | |
abfc2e5f RS |
131 | { |
132 | char *copy = (char *) malloc (strlen (result) + 1); | |
133 | strcpy (copy, result); | |
134 | return copy; | |
135 | } | |
837255fb JB |
136 | else |
137 | return 0; | |
138 | } | |
139 | ||
140 | ||
141 | /* Expand all the Xt-style %-escapes in STRING, whose length is given | |
142 | by STRING_LEN. Here are the escapes we're supposed to recognize: | |
143 | ||
144 | %N The value of the application's class name | |
145 | %T The value of the type parameter ("app-defaults" in this | |
146 | context) | |
147 | %S The value of the suffix parameter ("" in this context) | |
148 | %L The language string associated with the specified display | |
149 | (We use the "LANG" environment variable here, if it's set.) | |
150 | %l The language part of the display's language string | |
151 | (We treat this just like %L. If someone can tell us what | |
152 | we're really supposed to do, dandy.) | |
153 | %t The territory part of the display's language string | |
154 | (This never gets used.) | |
155 | %c The codeset part of the display's language string | |
156 | (This never gets used either.) | |
157 | %C The customization string retrieved from the resource | |
158 | database associated with display. | |
159 | (This is x_customization_string.) | |
160 | ||
161 | Return the expanded file name if it exists and is readable, and | |
162 | refers to %L only when the LANG environment variable is set, or | |
163 | otherwise provided by X. | |
164 | ||
165 | ESCAPED_SUFFIX and SUFFIX are postpended to STRING if they are | |
166 | non-zero. %-escapes in ESCAPED_SUFFIX are expanded; STRING is left | |
167 | alone. | |
168 | ||
169 | Return NULL otherwise. */ | |
170 | ||
171 | static char * | |
172 | magic_file_p (string, string_len, class, escaped_suffix, suffix) | |
173 | char *string; | |
174 | int string_len; | |
175 | char *class, *escaped_suffix, *suffix; | |
176 | { | |
177 | char *lang = getenv ("LANG"); | |
178 | ||
179 | int path_size = 100; | |
180 | char *path = (char *) malloc (path_size); | |
181 | int path_len = 0; | |
182 | ||
183 | char *p = string; | |
184 | ||
185 | while (p < string + string_len) | |
186 | { | |
187 | /* The chunk we're about to stick on the end of result. */ | |
6bbd7a29 | 188 | char *next = NULL; |
837255fb JB |
189 | int next_len; |
190 | ||
191 | if (*p == '%') | |
192 | { | |
193 | p++; | |
194 | ||
195 | if (p >= string + string_len) | |
196 | next_len = 0; | |
197 | else | |
198 | switch (*p) | |
199 | { | |
200 | case '%': | |
201 | next = "%"; | |
202 | next_len = 1; | |
203 | break; | |
204 | ||
205 | case 'C': | |
206 | next = (x_customization_string | |
207 | ? x_customization_string | |
208 | : ""); | |
209 | next_len = strlen (next); | |
210 | break; | |
211 | ||
212 | case 'N': | |
213 | next = class; | |
214 | next_len = strlen (class); | |
215 | break; | |
216 | ||
217 | case 'T': | |
218 | next = "app-defaults"; | |
219 | next_len = strlen (next); | |
220 | break; | |
221 | ||
222 | default: | |
223 | case 'S': | |
224 | next_len = 0; | |
225 | break; | |
226 | ||
227 | case 'L': | |
228 | case 'l': | |
229 | if (! lang) | |
230 | { | |
231 | free (path); | |
232 | return NULL; | |
233 | } | |
427ec082 | 234 | |
837255fb JB |
235 | next = lang; |
236 | next_len = strlen (next); | |
237 | break; | |
427ec082 | 238 | |
837255fb JB |
239 | case 't': |
240 | case 'c': | |
241 | free (path); | |
242 | return NULL; | |
243 | } | |
244 | } | |
245 | else | |
246 | next = p, next_len = 1; | |
247 | ||
248 | /* Do we have room for this component followed by a '\0' ? */ | |
249 | if (path_len + next_len + 1 > path_size) | |
250 | { | |
251 | path_size = (path_len + next_len + 1) * 2; | |
252 | path = (char *) realloc (path, path_size); | |
253 | } | |
427ec082 | 254 | |
837255fb JB |
255 | bcopy (next, path + path_len, next_len); |
256 | path_len += next_len; | |
257 | ||
258 | p++; | |
259 | ||
260 | /* If we've reached the end of the string, append ESCAPED_SUFFIX. */ | |
261 | if (p >= string + string_len && escaped_suffix) | |
262 | { | |
263 | string = escaped_suffix; | |
264 | string_len = strlen (string); | |
265 | p = string; | |
266 | escaped_suffix = NULL; | |
267 | } | |
268 | } | |
269 | ||
270 | /* Perhaps we should add the SUFFIX now. */ | |
271 | if (suffix) | |
272 | { | |
273 | int suffix_len = strlen (suffix); | |
274 | ||
275 | if (path_len + suffix_len + 1 > path_size) | |
276 | { | |
277 | path_size = (path_len + suffix_len + 1); | |
278 | path = (char *) realloc (path, path_size); | |
279 | } | |
280 | ||
281 | bcopy (suffix, path + path_len, suffix_len); | |
282 | path_len += suffix_len; | |
283 | } | |
284 | ||
285 | path[path_len] = '\0'; | |
286 | ||
287 | if (! file_p (path)) | |
288 | { | |
289 | free (path); | |
290 | return NULL; | |
291 | } | |
292 | ||
293 | return path; | |
294 | } | |
295 | ||
296 | ||
f3a0bf5c | 297 | static char * |
837255fb | 298 | gethomedir () |
f3a0bf5c | 299 | { |
f3a0bf5c JB |
300 | struct passwd *pw; |
301 | char *ptr; | |
837255fb | 302 | char *copy; |
f3a0bf5c JB |
303 | |
304 | if ((ptr = getenv ("HOME")) == NULL) | |
305 | { | |
1cac1f6f KH |
306 | if ((ptr = getenv ("LOGNAME")) != NULL |
307 | || (ptr = getenv ("USER")) != NULL) | |
f3a0bf5c JB |
308 | pw = getpwnam (ptr); |
309 | else | |
1cac1f6f | 310 | pw = getpwuid (getuid ()); |
837255fb | 311 | |
f3a0bf5c JB |
312 | if (pw) |
313 | ptr = pw->pw_dir; | |
f3a0bf5c JB |
314 | } |
315 | ||
427ec082 | 316 | if (ptr == NULL) |
8fd0f424 | 317 | return xstrdup ("/"); |
f3a0bf5c | 318 | |
837255fb JB |
319 | copy = (char *) malloc (strlen (ptr) + 2); |
320 | strcpy (copy, ptr); | |
321 | strcat (copy, "/"); | |
f3a0bf5c | 322 | |
837255fb | 323 | return copy; |
f3a0bf5c JB |
324 | } |
325 | ||
837255fb | 326 | |
f3a0bf5c | 327 | static int |
aa7e4660 RS |
328 | file_p (filename) |
329 | char *filename; | |
f3a0bf5c JB |
330 | { |
331 | struct stat status; | |
332 | ||
aa7e4660 RS |
333 | return (access (filename, 4) == 0 /* exists and is readable */ |
334 | && stat (filename, &status) == 0 /* get the status */ | |
0f2cd61f | 335 | && (S_ISDIR (status.st_mode)) == 0); /* not a directory */ |
f3a0bf5c JB |
336 | } |
337 | ||
f3a0bf5c | 338 | |
837255fb | 339 | /* Find the first element of SEARCH_PATH which exists and is readable, |
427ec082 | 340 | after expanding the %-escapes. Return 0 if we didn't find any, and |
837255fb | 341 | the path name of the one we found otherwise. */ |
f3a0bf5c | 342 | |
837255fb JB |
343 | static char * |
344 | search_magic_path (search_path, class, escaped_suffix, suffix) | |
345 | char *search_path, *class, *escaped_suffix, *suffix; | |
f3a0bf5c | 346 | { |
837255fb | 347 | register char *s, *p; |
d4327fec | 348 | |
837255fb | 349 | for (s = search_path; *s; s = p) |
f3a0bf5c | 350 | { |
837255fb JB |
351 | for (p = s; *p && *p != ':'; p++) |
352 | ; | |
427ec082 | 353 | |
0f2cd61f | 354 | if (p > s) |
f3a0bf5c | 355 | { |
0f2cd61f | 356 | char *path = magic_file_p (s, p - s, class, escaped_suffix, suffix); |
837255fb JB |
357 | if (path) |
358 | return path; | |
f3a0bf5c | 359 | } |
0f2cd61f | 360 | else if (*p == ':') |
f3a0bf5c | 361 | { |
0f2cd61f RS |
362 | char *path; |
363 | ||
364 | s = "%N%S"; | |
365 | path = magic_file_p (s, strlen (s), class, escaped_suffix, suffix); | |
837255fb JB |
366 | if (path) |
367 | return path; | |
f3a0bf5c JB |
368 | } |
369 | ||
837255fb JB |
370 | if (*p == ':') |
371 | p++; | |
f3a0bf5c JB |
372 | } |
373 | ||
374 | return 0; | |
375 | } | |
376 | \f | |
837255fb JB |
377 | /* Producing databases for individual sources. */ |
378 | ||
f3a0bf5c JB |
379 | static XrmDatabase |
380 | get_system_app (class) | |
381 | char *class; | |
382 | { | |
837255fb JB |
383 | XrmDatabase db = NULL; |
384 | char *path; | |
f3a0bf5c | 385 | |
837255fb | 386 | path = getenv ("XFILESEARCHPATH"); |
58c7da0c | 387 | if (! path) path = PATH_X_DEFAULTS; |
f3a0bf5c | 388 | |
837255fb JB |
389 | path = search_magic_path (path, class, 0, 0); |
390 | if (path) | |
391 | { | |
392 | db = XrmGetFileDatabase (path); | |
393 | free (path); | |
394 | } | |
f3a0bf5c | 395 | |
f3a0bf5c JB |
396 | return db; |
397 | } | |
398 | ||
837255fb | 399 | |
f3a0bf5c JB |
400 | static XrmDatabase |
401 | get_fallback (display) | |
402 | Display *display; | |
403 | { | |
f3a0bf5c JB |
404 | return NULL; |
405 | } | |
406 | ||
837255fb | 407 | |
f3a0bf5c JB |
408 | static XrmDatabase |
409 | get_user_app (class) | |
410 | char *class; | |
411 | { | |
837255fb JB |
412 | char *path; |
413 | char *file = 0; | |
3fa18fb2 | 414 | char *free_it = 0; |
837255fb JB |
415 | |
416 | /* Check for XUSERFILESEARCHPATH. It is a path of complete file | |
417 | names, not directories. */ | |
418 | if (((path = getenv ("XUSERFILESEARCHPATH")) | |
419 | && (file = search_magic_path (path, class, 0, 0))) | |
420 | ||
421 | /* Check for APPLRESDIR; it is a path of directories. In each, | |
422 | we have to search for LANG/CLASS and then CLASS. */ | |
423 | || ((path = getenv ("XAPPLRESDIR")) | |
424 | && ((file = search_magic_path (path, class, "/%L/%N", 0)) | |
425 | || (file = search_magic_path (path, class, "/%N", 0)))) | |
427ec082 | 426 | |
837255fb JB |
427 | /* Check in the home directory. This is a bit of a hack; let's |
428 | hope one's home directory doesn't contain any %-escapes. */ | |
3fa18fb2 RS |
429 | || (free_it = gethomedir (), |
430 | ((file = search_magic_path (free_it, class, "%L/%N", 0)) | |
431 | || (file = search_magic_path (free_it, class, "%N", 0))))) | |
f3a0bf5c | 432 | { |
837255fb JB |
433 | XrmDatabase db = XrmGetFileDatabase (file); |
434 | free (file); | |
c2cd06e6 | 435 | free (free_it); |
837255fb | 436 | return db; |
f3a0bf5c | 437 | } |
3fa18fb2 | 438 | |
c2cd06e6 | 439 | free (free_it); |
3fa18fb2 | 440 | return NULL; |
f3a0bf5c JB |
441 | } |
442 | ||
837255fb | 443 | |
f3a0bf5c JB |
444 | static XrmDatabase |
445 | get_user_db (display) | |
446 | Display *display; | |
447 | { | |
448 | XrmDatabase db; | |
449 | char *xdefs; | |
450 | ||
2c8d1900 | 451 | #ifdef PBaseSize /* Cheap way to test for X11R4 or later. */ |
b631f177 JB |
452 | xdefs = XResourceManagerString (display); |
453 | #else | |
a2a4d43e | 454 | xdefs = display->xdefaults; |
b631f177 JB |
455 | #endif |
456 | ||
f3a0bf5c JB |
457 | if (xdefs != NULL) |
458 | db = XrmGetStringDatabase (xdefs); | |
459 | else | |
460 | { | |
837255fb JB |
461 | char *home; |
462 | char *xdefault; | |
f3a0bf5c | 463 | |
837255fb JB |
464 | home = gethomedir (); |
465 | xdefault = (char *) malloc (strlen (home) + sizeof (".Xdefaults")); | |
466 | strcpy (xdefault, home); | |
f3a0bf5c JB |
467 | strcat (xdefault, ".Xdefaults"); |
468 | db = XrmGetFileDatabase (xdefault); | |
837255fb JB |
469 | free (home); |
470 | free (xdefault); | |
f3a0bf5c JB |
471 | } |
472 | ||
d8717d15 | 473 | #ifdef HAVE_XSCREENRESOURCESTRING |
9b37b1c2 JB |
474 | /* Get the screen-specific resources too. */ |
475 | xdefs = XScreenResourceString (DefaultScreenOfDisplay (display)); | |
476 | if (xdefs != NULL) | |
fdce0b39 JB |
477 | { |
478 | XrmMergeDatabases (XrmGetStringDatabase (xdefs), &db); | |
479 | XFree (xdefs); | |
480 | } | |
9b37b1c2 JB |
481 | #endif |
482 | ||
f3a0bf5c JB |
483 | return db; |
484 | } | |
485 | ||
486 | static XrmDatabase | |
487 | get_environ_db () | |
488 | { | |
489 | XrmDatabase db; | |
490 | char *p; | |
e29ad342 | 491 | char *path = 0, *home = 0, *host; |
f3a0bf5c JB |
492 | |
493 | if ((p = getenv ("XENVIRONMENT")) == NULL) | |
494 | { | |
837255fb | 495 | home = gethomedir (); |
e29ad342 | 496 | host = get_system_name (); |
837255fb JB |
497 | path = (char *) malloc (strlen (home) |
498 | + sizeof (".Xdefaults-") | |
499 | + strlen (host)); | |
500 | sprintf (path, "%s%s%s", home, ".Xdefaults-", host); | |
f3a0bf5c JB |
501 | p = path; |
502 | } | |
503 | ||
504 | db = XrmGetFileDatabase (p); | |
837255fb | 505 | |
c2cd06e6 JM |
506 | free (path); |
507 | free (home); | |
837255fb | 508 | |
f3a0bf5c JB |
509 | return db; |
510 | } | |
511 | \f | |
837255fb JB |
512 | /* External interface. */ |
513 | ||
f3a0bf5c JB |
514 | /* Types of values that we can find in a database */ |
515 | ||
516 | #define XrmStringType "String" /* String representation */ | |
517 | XrmRepresentation x_rm_string; /* Quark representation */ | |
518 | ||
519 | /* Load X resources based on the display and a possible -xrm option. */ | |
520 | ||
521 | XrmDatabase | |
837255fb | 522 | x_load_resources (display, xrm_string, myname, myclass) |
f3a0bf5c | 523 | Display *display; |
837255fb | 524 | char *xrm_string, *myname, *myclass; |
f3a0bf5c | 525 | { |
837255fb | 526 | XrmDatabase user_database; |
f3a0bf5c JB |
527 | XrmDatabase rdb; |
528 | XrmDatabase db; | |
4da4f201 | 529 | char line[256]; |
6ca30ba4 | 530 | |
4da4f201 | 531 | char *helv = "-*-helvetica-medium-r-*--*-120-*-*-*-*-iso8859-1"; |
6ca30ba4 | 532 | |
8d56e206 | 533 | #ifdef USE_MOTIF |
4da4f201 GM |
534 | char *courier = "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1"; |
535 | extern Lisp_Object Vdouble_click_time; | |
8d56e206 | 536 | #endif |
f3a0bf5c JB |
537 | |
538 | x_rm_string = XrmStringToQuark (XrmStringType); | |
082dc211 RS |
539 | #ifndef USE_X_TOOLKIT |
540 | /* pmr@osf.org says this shouldn't be done if USE_X_TOOLKIT. | |
541 | I suspect it's because the toolkit version does this elsewhere. */ | |
f3a0bf5c | 542 | XrmInitialize (); |
082dc211 | 543 | #endif |
f3a0bf5c JB |
544 | rdb = XrmGetStringDatabase (""); |
545 | ||
4da4f201 GM |
546 | /* Add some font defaults. If the font `helv' doesn't exist, widgets |
547 | will use some other default font. */ | |
548 | #ifdef USE_MOTIF | |
427ec082 | 549 | |
cf9b4b0b | 550 | sprintf (line, "%s.pane.background: grey75", myclass); |
06bbf618 | 551 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 552 | sprintf (line, "%s*fontList: %s", myclass, helv); |
4da4f201 | 553 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 554 | sprintf (line, "%s*menu*background: grey75", myclass); |
4da4f201 | 555 | XrmPutLineResource (&rdb, line); |
b6a15240 | 556 | sprintf (line, "%s*menubar*background: grey75", myclass); |
4da4f201 | 557 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 558 | sprintf (line, "%s*verticalScrollBar.background: grey75", myclass); |
4da4f201 | 559 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 560 | sprintf (line, "%s*verticalScrollBar.troughColor: grey75", myclass); |
06bbf618 | 561 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 562 | sprintf (line, "%s.dialog*.background: grey75", myclass); |
4da4f201 | 563 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 564 | sprintf (line, "%s*fsb.Text.background: white", myclass); |
4da4f201 | 565 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 566 | sprintf (line, "%s*fsb.FilterText.background: white", myclass); |
4da4f201 | 567 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 568 | sprintf (line, "%s*fsb*DirList.background: white", myclass); |
4da4f201 | 569 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 570 | sprintf (line, "%s*fsb*ItemsList.background: white", myclass); |
4da4f201 | 571 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 572 | sprintf (line, "%s*fsb*background: grey75", myclass); |
4da4f201 | 573 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 574 | sprintf (line, "%s*fsb.Text.fontList: %s", myclass, courier); |
4da4f201 | 575 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 576 | sprintf (line, "%s*fsb.FilterText.fontList: %s", myclass, courier); |
4da4f201 | 577 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 578 | sprintf (line, "%s*fsb*ItemsList.fontList: %s", myclass, courier); |
4da4f201 | 579 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 580 | sprintf (line, "%s*fsb*DirList.fontList: %s", myclass, courier); |
4da4f201 GM |
581 | XrmPutLineResource (&rdb, line); |
582 | ||
583 | /* Set double click time of list boxes in the file selection | |
584 | dialog from `double-click-time'. */ | |
585 | if (INTEGERP (Vdouble_click_time) && XINT (Vdouble_click_time) > 0) | |
586 | { | |
587 | sprintf (line, "%s*fsb*DirList.doubleClickInterval: %d", | |
cf9b4b0b | 588 | myclass, XFASTINT (Vdouble_click_time)); |
4da4f201 GM |
589 | XrmPutLineResource (&rdb, line); |
590 | sprintf (line, "%s*fsb*ItemsList.doubleClickInterval: %d", | |
cf9b4b0b | 591 | myclass, XFASTINT (Vdouble_click_time)); |
4da4f201 GM |
592 | XrmPutLineResource (&rdb, line); |
593 | } | |
594 | ||
595 | #else /* not USE_MOTIF */ | |
427ec082 | 596 | |
fc6c5dfe | 597 | sprintf (line, "Emacs.dialog*.font: %s", helv); |
4da4f201 | 598 | XrmPutLineResource (&rdb, line); |
fc6c5dfe | 599 | sprintf (line, "Emacs.dialog*.background: grey75"); |
4da4f201 | 600 | XrmPutLineResource (&rdb, line); |
fc6c5dfe | 601 | sprintf (line, "*XlwMenu*font: %s", helv); |
4da4f201 | 602 | XrmPutLineResource (&rdb, line); |
fc6c5dfe | 603 | sprintf (line, "*XlwMenu*background: grey75"); |
4da4f201 | 604 | XrmPutLineResource (&rdb, line); |
fc6c5dfe | 605 | sprintf (line, "Emacs*verticalScrollBar.background: grey75"); |
4da4f201 | 606 | XrmPutLineResource (&rdb, line); |
427ec082 | 607 | |
4da4f201 GM |
608 | #endif /* not USE_MOTIF */ |
609 | ||
837255fb JB |
610 | user_database = get_user_db (display); |
611 | ||
612 | /* Figure out what the "customization string" is, so we can use it | |
613 | to decode paths. */ | |
c2cd06e6 | 614 | free (x_customization_string); |
837255fb JB |
615 | x_customization_string |
616 | = x_get_customization_string (user_database, myname, myclass); | |
617 | ||
f3a0bf5c JB |
618 | /* Get application system defaults */ |
619 | db = get_system_app (myclass); | |
620 | if (db != NULL) | |
621 | XrmMergeDatabases (db, &rdb); | |
622 | ||
623 | /* Get Fallback resources */ | |
624 | db = get_fallback (display); | |
625 | if (db != NULL) | |
626 | XrmMergeDatabases (db, &rdb); | |
627 | ||
628 | /* Get application user defaults */ | |
629 | db = get_user_app (myclass); | |
630 | if (db != NULL) | |
631 | XrmMergeDatabases (db, &rdb); | |
632 | ||
633 | /* get User defaults */ | |
837255fb JB |
634 | if (user_database != NULL) |
635 | XrmMergeDatabases (user_database, &rdb); | |
f3a0bf5c JB |
636 | |
637 | /* Get Environment defaults. */ | |
638 | db = get_environ_db (); | |
639 | if (db != NULL) | |
640 | XrmMergeDatabases (db, &rdb); | |
427ec082 | 641 | |
f3a0bf5c JB |
642 | /* Last, merge in any specification from the command line. */ |
643 | if (xrm_string != NULL) | |
644 | { | |
645 | db = XrmGetStringDatabase (xrm_string); | |
646 | if (db != NULL) | |
647 | XrmMergeDatabases (db, &rdb); | |
648 | } | |
649 | ||
650 | return rdb; | |
651 | } | |
652 | ||
837255fb | 653 | |
f3a0bf5c JB |
654 | /* Retrieve the value of the resource specified by NAME with class CLASS |
655 | and of type TYPE from database RDB. The value is returned in RET_VALUE. */ | |
656 | ||
657 | int | |
658 | x_get_resource (rdb, name, class, expected_type, ret_value) | |
659 | XrmDatabase rdb; | |
660 | char *name, *class; | |
661 | XrmRepresentation expected_type; | |
662 | XrmValue *ret_value; | |
663 | { | |
664 | XrmValue value; | |
665 | XrmName namelist[100]; | |
666 | XrmClass classlist[100]; | |
667 | XrmRepresentation type; | |
668 | ||
669 | XrmStringToNameList(name, namelist); | |
670 | XrmStringToClassList(class, classlist); | |
671 | ||
672 | if (XrmQGetResource (rdb, namelist, classlist, &type, &value) == True | |
673 | && (type == expected_type)) | |
674 | { | |
675 | if (type == x_rm_string) | |
41ab0754 | 676 | ret_value->addr = (char *) value.addr; |
f3a0bf5c JB |
677 | else |
678 | bcopy (value.addr, ret_value->addr, ret_value->size); | |
679 | ||
680 | return value.size; | |
681 | } | |
682 | ||
683 | return 0; | |
684 | } | |
685 | ||
686 | /* Retrieve the string resource specified by NAME with CLASS from | |
687 | database RDB. */ | |
688 | ||
689 | char * | |
690 | x_get_string_resource (rdb, name, class) | |
691 | XrmDatabase rdb; | |
692 | char *name, *class; | |
693 | { | |
694 | XrmValue value; | |
695 | ||
696 | if (x_get_resource (rdb, name, class, x_rm_string, &value)) | |
697 | return (char *) value.addr; | |
698 | ||
699 | return (char *) 0; | |
700 | } | |
701 | \f | |
837255fb JB |
702 | /* Stand-alone test facilities. */ |
703 | ||
f3a0bf5c | 704 | #ifdef TESTRM |
837255fb JB |
705 | |
706 | typedef char **List; | |
707 | #define arg_listify(len, list) (list) | |
708 | #define car(list) (*(list)) | |
709 | #define cdr(list) (list + 1) | |
710 | #define NIL(list) (! *(list)) | |
711 | #define free_arglist(list) | |
712 | ||
713 | static List | |
714 | member (elt, list) | |
715 | char *elt; | |
716 | List list; | |
717 | { | |
718 | List p; | |
719 | ||
720 | for (p = list; ! NIL (p); p = cdr (p)) | |
721 | if (! strcmp (elt, car (p))) | |
722 | return p; | |
723 | ||
724 | return p; | |
725 | } | |
f3a0bf5c JB |
726 | |
727 | static void | |
728 | fatal (msg, prog, x1, x2, x3, x4, x5) | |
729 | char *msg, *prog; | |
730 | int x1, x2, x3, x4, x5; | |
731 | { | |
732 | extern int errno; | |
733 | ||
734 | if (errno) | |
735 | perror (prog); | |
736 | ||
737 | (void) fprintf (stderr, msg, prog, x1, x2, x3, x4, x5); | |
738 | exit (1); | |
739 | } | |
740 | ||
741 | main (argc, argv) | |
742 | int argc; | |
743 | char **argv; | |
744 | { | |
745 | Display *display; | |
837255fb | 746 | char *displayname, *resource_string, *class, *name; |
f3a0bf5c | 747 | XrmDatabase xdb; |
837255fb | 748 | List arg_list, lp; |
f3a0bf5c JB |
749 | |
750 | arg_list = arg_listify (argc, argv); | |
751 | ||
752 | lp = member ("-d", arg_list); | |
753 | if (!NIL (lp)) | |
754 | displayname = car (cdr (lp)); | |
755 | else | |
756 | displayname = "localhost:0.0"; | |
757 | ||
758 | lp = member ("-xrm", arg_list); | |
759 | if (! NIL (lp)) | |
760 | resource_string = car (cdr (lp)); | |
761 | else | |
762 | resource_string = (char *) 0; | |
763 | ||
764 | lp = member ("-c", arg_list); | |
765 | if (! NIL (lp)) | |
766 | class = car (cdr (lp)); | |
767 | else | |
768 | class = "Emacs"; | |
769 | ||
837255fb JB |
770 | lp = member ("-n", arg_list); |
771 | if (! NIL (lp)) | |
772 | name = car (cdr (lp)); | |
773 | else | |
774 | name = "emacs"; | |
f3a0bf5c | 775 | |
837255fb | 776 | free_arglist (arg_list); |
f3a0bf5c JB |
777 | |
778 | if (!(display = XOpenDisplay (displayname))) | |
779 | fatal ("Can't open display '%s'\n", XDisplayName (displayname)); | |
780 | ||
837255fb | 781 | xdb = x_load_resources (display, resource_string, name, class); |
f3a0bf5c | 782 | |
f3a0bf5c JB |
783 | /* In a real program, you'd want to also do this: */ |
784 | display->db = xdb; | |
f3a0bf5c JB |
785 | |
786 | while (1) | |
787 | { | |
837255fb JB |
788 | char query_name[90]; |
789 | char query_class[90]; | |
790 | ||
791 | printf ("Name: "); | |
792 | gets (query_name); | |
f3a0bf5c | 793 | |
837255fb | 794 | if (strlen (query_name)) |
f3a0bf5c | 795 | { |
837255fb JB |
796 | char *value; |
797 | ||
798 | printf ("Class: "); | |
799 | gets (query_class); | |
800 | ||
801 | value = x_get_string_resource (xdb, query_name, query_class); | |
f3a0bf5c JB |
802 | |
803 | if (value != NULL) | |
837255fb | 804 | printf ("\t%s(%s): %s\n\n", query_name, query_class, value); |
f3a0bf5c JB |
805 | else |
806 | printf ("\tNo Value.\n\n"); | |
807 | } | |
808 | else | |
809 | break; | |
810 | } | |
811 | printf ("\tExit.\n\n"); | |
812 | ||
813 | XCloseDisplay (display); | |
814 | } | |
815 | #endif /* TESTRM */ | |
ab5796a9 MB |
816 | |
817 | /* arch-tag: 37e6fbab-ed05-4363-9e76-6c4109ed511f | |
818 | (do not change this comment) */ |