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