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