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