Commit | Line | Data |
---|---|---|
f3a0bf5c | 1 | /* Deal with the X Resource Manager. |
acaf905b | 2 | Copyright (C) 1990, 1993-1994, 2000-2012 Free Software Foundation, Inc. |
f3a0bf5c | 3 | |
90324359 GM |
4 | Author: Joseph Arceneaux |
5 | Created: 4/90 | |
6 | ||
3b7ad313 EN |
7 | This file is part of GNU Emacs. |
8 | ||
9ec0b715 | 9 | GNU Emacs is free software: you can redistribute it and/or modify |
f3a0bf5c | 10 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
11 | the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | |
f3a0bf5c | 13 | |
3b7ad313 | 14 | GNU Emacs is distributed in the hope that it will be useful, |
f3a0bf5c JB |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 20 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
f3a0bf5c | 21 | |
18160b98 | 22 | #include <config.h> |
a2a4d43e | 23 | |
dfcf069d | 24 | #include <unistd.h> |
42a2c622 | 25 | #include <errno.h> |
57bda87a | 26 | #include <epaths.h> |
012c3e71 | 27 | |
837255fb | 28 | #include <stdio.h> |
d7306fe6 | 29 | #include <setjmp.h> |
837255fb | 30 | |
b4716021 PE |
31 | #include "lisp.h" |
32 | ||
33 | /* This may include sys/types.h, and that somehow loses | |
34 | if this is not done before the other system files. */ | |
35 | #include "xterm.h" | |
36 | ||
f3a0bf5c JB |
37 | #include <X11/Xlib.h> |
38 | #include <X11/Xatom.h> | |
f3a0bf5c JB |
39 | #include <X11/X.h> |
40 | #include <X11/Xutil.h> | |
41 | #include <X11/Xresource.h> | |
5b9c0a1d | 42 | #ifdef HAVE_PWD_H |
f3a0bf5c | 43 | #include <pwd.h> |
531ff254 | 44 | #endif |
f3a0bf5c JB |
45 | #include <sys/stat.h> |
46 | ||
dee186b6 J |
47 | #ifdef USE_MOTIF |
48 | /* For Vdouble_click_time. */ | |
49 | #include "keyboard.h" | |
50 | #endif | |
51 | ||
971de7fb | 52 | extern char *getenv (const char *); |
3d5d61ae | 53 | |
3e0be4d0 RS |
54 | extern struct passwd *getpwuid (uid_t); |
55 | extern struct passwd *getpwnam (const char *); | |
f3a0bf5c | 56 | |
eec47d6b DN |
57 | char *x_get_string_resource (XrmDatabase rdb, const char *name, |
58 | const char *class); | |
59 | static int file_p (const char *filename); | |
837255fb JB |
60 | |
61 | \f | |
62 | /* X file search path processing. */ | |
63 | ||
64 | ||
65 | /* The string which gets substituted for the %C escape in XFILESEARCHPATH | |
66 | and friends, or zero if none was specified. */ | |
ac64929e | 67 | static char *x_customization_string; |
837255fb JB |
68 | |
69 | ||
70 | /* Return the value of the emacs.customization (Emacs.Customization) | |
71 | resource, for later use in search path decoding. If we find no | |
72 | such resource, return zero. */ | |
2f7c71a1 AS |
73 | static char * |
74 | x_get_customization_string (XrmDatabase db, const char *name, | |
75 | 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 | ||
28154962 PE |
123 | ESCAPED_SUFFIX is postpended to STRING if it is non-zero. |
124 | %-escapes in ESCAPED_SUFFIX are expanded. | |
837255fb JB |
125 | |
126 | Return NULL otherwise. */ | |
127 | ||
128 | static char * | |
d311d28c | 129 | magic_file_p (const char *string, ptrdiff_t string_len, const char *class, |
28154962 | 130 | const char *escaped_suffix) |
837255fb JB |
131 | { |
132 | char *lang = getenv ("LANG"); | |
133 | ||
28154962 | 134 | ptrdiff_t path_size = 100; |
1b6d8cf0 | 135 | char *path = (char *) xmalloc (path_size); |
28154962 | 136 | ptrdiff_t path_len = 0; |
837255fb | 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; |
28154962 | 144 | ptrdiff_t next_len; |
837255fb JB |
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' ? */ | |
28154962 | 204 | if (path_size - path_len <= next_len) |
837255fb | 205 | { |
28154962 | 206 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len) |
0065d054 | 207 | memory_full (SIZE_MAX); |
837255fb | 208 | path_size = (path_len + next_len + 1) * 2; |
1b6d8cf0 | 209 | path = (char *) xrealloc (path, path_size); |
837255fb | 210 | } |
427ec082 | 211 | |
72af86bd | 212 | memcpy (path + path_len, next, next_len); |
837255fb JB |
213 | path_len += next_len; |
214 | ||
215 | p++; | |
216 | ||
217 | /* If we've reached the end of the string, append ESCAPED_SUFFIX. */ | |
218 | if (p >= string + string_len && escaped_suffix) | |
219 | { | |
220 | string = escaped_suffix; | |
221 | string_len = strlen (string); | |
222 | p = string; | |
223 | escaped_suffix = NULL; | |
224 | } | |
225 | } | |
226 | ||
837255fb JB |
227 | path[path_len] = '\0'; |
228 | ||
229 | if (! file_p (path)) | |
230 | { | |
1b6d8cf0 | 231 | xfree (path); |
837255fb JB |
232 | return NULL; |
233 | } | |
234 | ||
235 | return path; | |
236 | } | |
237 | ||
238 | ||
f3a0bf5c | 239 | static char * |
971de7fb | 240 | gethomedir (void) |
f3a0bf5c | 241 | { |
f3a0bf5c JB |
242 | struct passwd *pw; |
243 | char *ptr; | |
837255fb | 244 | char *copy; |
f3a0bf5c JB |
245 | |
246 | if ((ptr = getenv ("HOME")) == NULL) | |
247 | { | |
1cac1f6f KH |
248 | if ((ptr = getenv ("LOGNAME")) != NULL |
249 | || (ptr = getenv ("USER")) != NULL) | |
f3a0bf5c JB |
250 | pw = getpwnam (ptr); |
251 | else | |
1cac1f6f | 252 | pw = getpwuid (getuid ()); |
837255fb | 253 | |
f3a0bf5c JB |
254 | if (pw) |
255 | ptr = pw->pw_dir; | |
f3a0bf5c JB |
256 | } |
257 | ||
427ec082 | 258 | if (ptr == NULL) |
8fd0f424 | 259 | return xstrdup ("/"); |
f3a0bf5c | 260 | |
1b6d8cf0 | 261 | copy = (char *) xmalloc (strlen (ptr) + 2); |
837255fb JB |
262 | strcpy (copy, ptr); |
263 | strcat (copy, "/"); | |
f3a0bf5c | 264 | |
837255fb | 265 | return copy; |
f3a0bf5c JB |
266 | } |
267 | ||
837255fb | 268 | |
f3a0bf5c | 269 | static int |
eec47d6b | 270 | file_p (const char *filename) |
f3a0bf5c JB |
271 | { |
272 | struct stat status; | |
273 | ||
aa7e4660 RS |
274 | return (access (filename, 4) == 0 /* exists and is readable */ |
275 | && stat (filename, &status) == 0 /* get the status */ | |
0f2cd61f | 276 | && (S_ISDIR (status.st_mode)) == 0); /* not a directory */ |
f3a0bf5c JB |
277 | } |
278 | ||
f3a0bf5c | 279 | |
837255fb | 280 | /* Find the first element of SEARCH_PATH which exists and is readable, |
427ec082 | 281 | after expanding the %-escapes. Return 0 if we didn't find any, and |
837255fb | 282 | the path name of the one we found otherwise. */ |
f3a0bf5c | 283 | |
837255fb | 284 | static char * |
28154962 PE |
285 | search_magic_path (const char *search_path, const char *class, |
286 | const char *escaped_suffix) | |
f3a0bf5c | 287 | { |
eec47d6b | 288 | const char *s, *p; |
d4327fec | 289 | |
837255fb | 290 | for (s = search_path; *s; s = p) |
f3a0bf5c | 291 | { |
837255fb JB |
292 | for (p = s; *p && *p != ':'; p++) |
293 | ; | |
427ec082 | 294 | |
0f2cd61f | 295 | if (p > s) |
f3a0bf5c | 296 | { |
28154962 | 297 | char *path = magic_file_p (s, p - s, class, escaped_suffix); |
837255fb JB |
298 | if (path) |
299 | return path; | |
f3a0bf5c | 300 | } |
0f2cd61f | 301 | else if (*p == ':') |
f3a0bf5c | 302 | { |
0f2cd61f RS |
303 | char *path; |
304 | ||
305 | s = "%N%S"; | |
28154962 | 306 | path = magic_file_p (s, strlen (s), class, escaped_suffix); |
837255fb JB |
307 | if (path) |
308 | return path; | |
f3a0bf5c JB |
309 | } |
310 | ||
837255fb JB |
311 | if (*p == ':') |
312 | p++; | |
f3a0bf5c JB |
313 | } |
314 | ||
315 | return 0; | |
316 | } | |
317 | \f | |
837255fb JB |
318 | /* Producing databases for individual sources. */ |
319 | ||
f3a0bf5c | 320 | static XrmDatabase |
eec47d6b | 321 | get_system_app (const char *class) |
f3a0bf5c | 322 | { |
837255fb | 323 | XrmDatabase db = NULL; |
42ca4633 J |
324 | const char *path; |
325 | char *p; | |
f3a0bf5c | 326 | |
837255fb | 327 | path = getenv ("XFILESEARCHPATH"); |
58c7da0c | 328 | if (! path) path = PATH_X_DEFAULTS; |
f3a0bf5c | 329 | |
28154962 | 330 | p = search_magic_path (path, class, 0); |
42ca4633 | 331 | if (p) |
837255fb | 332 | { |
42ca4633 J |
333 | db = XrmGetFileDatabase (p); |
334 | xfree (p); | |
837255fb | 335 | } |
f3a0bf5c | 336 | |
f3a0bf5c JB |
337 | return db; |
338 | } | |
339 | ||
837255fb | 340 | |
f3a0bf5c | 341 | static XrmDatabase |
971de7fb | 342 | get_fallback (Display *display) |
f3a0bf5c | 343 | { |
f3a0bf5c JB |
344 | return NULL; |
345 | } | |
346 | ||
837255fb | 347 | |
f3a0bf5c | 348 | static XrmDatabase |
eec47d6b | 349 | get_user_app (const char *class) |
f3a0bf5c | 350 | { |
42ca4633 | 351 | const char *path; |
837255fb | 352 | char *file = 0; |
3fa18fb2 | 353 | char *free_it = 0; |
837255fb JB |
354 | |
355 | /* Check for XUSERFILESEARCHPATH. It is a path of complete file | |
356 | names, not directories. */ | |
357 | if (((path = getenv ("XUSERFILESEARCHPATH")) | |
28154962 | 358 | && (file = search_magic_path (path, class, 0))) |
837255fb JB |
359 | |
360 | /* Check for APPLRESDIR; it is a path of directories. In each, | |
361 | we have to search for LANG/CLASS and then CLASS. */ | |
362 | || ((path = getenv ("XAPPLRESDIR")) | |
28154962 PE |
363 | && ((file = search_magic_path (path, class, "/%L/%N")) |
364 | || (file = search_magic_path (path, class, "/%N")))) | |
427ec082 | 365 | |
837255fb JB |
366 | /* Check in the home directory. This is a bit of a hack; let's |
367 | hope one's home directory doesn't contain any %-escapes. */ | |
3fa18fb2 | 368 | || (free_it = gethomedir (), |
28154962 PE |
369 | ((file = search_magic_path (free_it, class, "%L/%N")) |
370 | || (file = search_magic_path (free_it, class, "%N"))))) | |
f3a0bf5c | 371 | { |
837255fb | 372 | XrmDatabase db = XrmGetFileDatabase (file); |
1b6d8cf0 DN |
373 | xfree (file); |
374 | xfree (free_it); | |
837255fb | 375 | return db; |
f3a0bf5c | 376 | } |
3fa18fb2 | 377 | |
1b6d8cf0 | 378 | xfree (free_it); |
3fa18fb2 | 379 | return NULL; |
f3a0bf5c JB |
380 | } |
381 | ||
837255fb | 382 | |
f3a0bf5c | 383 | static XrmDatabase |
971de7fb | 384 | get_user_db (Display *display) |
f3a0bf5c JB |
385 | { |
386 | XrmDatabase db; | |
387 | char *xdefs; | |
388 | ||
2c8d1900 | 389 | #ifdef PBaseSize /* Cheap way to test for X11R4 or later. */ |
b631f177 JB |
390 | xdefs = XResourceManagerString (display); |
391 | #else | |
a2a4d43e | 392 | xdefs = display->xdefaults; |
b631f177 JB |
393 | #endif |
394 | ||
f3a0bf5c JB |
395 | if (xdefs != NULL) |
396 | db = XrmGetStringDatabase (xdefs); | |
397 | else | |
398 | { | |
837255fb JB |
399 | char *home; |
400 | char *xdefault; | |
f3a0bf5c | 401 | |
837255fb | 402 | home = gethomedir (); |
1b6d8cf0 | 403 | xdefault = (char *) xmalloc (strlen (home) + sizeof (".Xdefaults")); |
837255fb | 404 | strcpy (xdefault, home); |
f3a0bf5c JB |
405 | strcat (xdefault, ".Xdefaults"); |
406 | db = XrmGetFileDatabase (xdefault); | |
1b6d8cf0 DN |
407 | xfree (home); |
408 | xfree (xdefault); | |
f3a0bf5c JB |
409 | } |
410 | ||
d8717d15 | 411 | #ifdef HAVE_XSCREENRESOURCESTRING |
9b37b1c2 JB |
412 | /* Get the screen-specific resources too. */ |
413 | xdefs = XScreenResourceString (DefaultScreenOfDisplay (display)); | |
414 | if (xdefs != NULL) | |
fdce0b39 JB |
415 | { |
416 | XrmMergeDatabases (XrmGetStringDatabase (xdefs), &db); | |
417 | XFree (xdefs); | |
418 | } | |
9b37b1c2 JB |
419 | #endif |
420 | ||
f3a0bf5c JB |
421 | return db; |
422 | } | |
423 | ||
424 | static XrmDatabase | |
971de7fb | 425 | get_environ_db (void) |
f3a0bf5c JB |
426 | { |
427 | XrmDatabase db; | |
428 | char *p; | |
a3d9c2a4 | 429 | char *path = 0; |
f3a0bf5c JB |
430 | |
431 | if ((p = getenv ("XENVIRONMENT")) == NULL) | |
432 | { | |
a3d9c2a4 PE |
433 | static char const xdefaults[] = ".Xdefaults-"; |
434 | char *home = gethomedir (); | |
435 | char const *host = get_system_name (); | |
436 | ptrdiff_t pathsize = strlen (home) + sizeof xdefaults + strlen (host); | |
437 | path = (char *) xrealloc (home, pathsize); | |
438 | strcat (strcat (path, xdefaults), host); | |
f3a0bf5c JB |
439 | p = path; |
440 | } | |
441 | ||
442 | db = XrmGetFileDatabase (p); | |
837255fb | 443 | |
1b6d8cf0 | 444 | xfree (path); |
837255fb | 445 | |
f3a0bf5c JB |
446 | return db; |
447 | } | |
448 | \f | |
837255fb JB |
449 | /* External interface. */ |
450 | ||
f3a0bf5c JB |
451 | /* Types of values that we can find in a database */ |
452 | ||
453 | #define XrmStringType "String" /* String representation */ | |
ac64929e | 454 | static XrmRepresentation x_rm_string; /* Quark representation */ |
f3a0bf5c JB |
455 | |
456 | /* Load X resources based on the display and a possible -xrm option. */ | |
457 | ||
458 | XrmDatabase | |
eec47d6b DN |
459 | x_load_resources (Display *display, const char *xrm_string, |
460 | const char *myname, const char *myclass) | |
f3a0bf5c | 461 | { |
837255fb | 462 | XrmDatabase user_database; |
f3a0bf5c JB |
463 | XrmDatabase rdb; |
464 | XrmDatabase db; | |
4da4f201 | 465 | char line[256]; |
6ca30ba4 | 466 | |
72391843 | 467 | #if defined USE_MOTIF || !defined HAVE_XFT || !defined USE_LUCID |
3565b346 | 468 | const char *helv = "-*-helvetica-medium-r-*--*-120-*-*-*-*-iso8859-1"; |
72391843 PE |
469 | #endif |
470 | ||
471 | #ifdef USE_MOTIF | |
eec47d6b | 472 | const char *courier = "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1"; |
8d56e206 | 473 | #endif |
f3a0bf5c JB |
474 | |
475 | x_rm_string = XrmStringToQuark (XrmStringType); | |
082dc211 RS |
476 | #ifndef USE_X_TOOLKIT |
477 | /* pmr@osf.org says this shouldn't be done if USE_X_TOOLKIT. | |
478 | I suspect it's because the toolkit version does this elsewhere. */ | |
f3a0bf5c | 479 | XrmInitialize (); |
082dc211 | 480 | #endif |
f3a0bf5c JB |
481 | rdb = XrmGetStringDatabase (""); |
482 | ||
4da4f201 GM |
483 | /* Add some font defaults. If the font `helv' doesn't exist, widgets |
484 | will use some other default font. */ | |
485 | #ifdef USE_MOTIF | |
427ec082 | 486 | |
cf9b4b0b | 487 | sprintf (line, "%s.pane.background: grey75", myclass); |
06bbf618 | 488 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 489 | sprintf (line, "%s*fontList: %s", myclass, helv); |
4da4f201 | 490 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 491 | sprintf (line, "%s*menu*background: grey75", myclass); |
4da4f201 | 492 | XrmPutLineResource (&rdb, line); |
b6a15240 | 493 | sprintf (line, "%s*menubar*background: grey75", myclass); |
4da4f201 | 494 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 495 | sprintf (line, "%s*verticalScrollBar.background: grey75", myclass); |
4da4f201 | 496 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 497 | sprintf (line, "%s*verticalScrollBar.troughColor: grey75", myclass); |
06bbf618 | 498 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 499 | sprintf (line, "%s.dialog*.background: grey75", myclass); |
4da4f201 | 500 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 501 | sprintf (line, "%s*fsb.Text.background: white", myclass); |
4da4f201 | 502 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 503 | sprintf (line, "%s*fsb.FilterText.background: white", myclass); |
4da4f201 | 504 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 505 | sprintf (line, "%s*fsb*DirList.background: white", myclass); |
4da4f201 | 506 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 507 | sprintf (line, "%s*fsb*ItemsList.background: white", myclass); |
4da4f201 | 508 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 509 | sprintf (line, "%s*fsb*background: grey75", myclass); |
4da4f201 | 510 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 511 | sprintf (line, "%s*fsb.Text.fontList: %s", myclass, courier); |
4da4f201 | 512 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 513 | sprintf (line, "%s*fsb.FilterText.fontList: %s", myclass, courier); |
4da4f201 | 514 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 515 | sprintf (line, "%s*fsb*ItemsList.fontList: %s", myclass, courier); |
4da4f201 | 516 | XrmPutLineResource (&rdb, line); |
cf9b4b0b | 517 | sprintf (line, "%s*fsb*DirList.fontList: %s", myclass, courier); |
4da4f201 GM |
518 | XrmPutLineResource (&rdb, line); |
519 | ||
520 | /* Set double click time of list boxes in the file selection | |
521 | dialog from `double-click-time'. */ | |
522 | if (INTEGERP (Vdouble_click_time) && XINT (Vdouble_click_time) > 0) | |
523 | { | |
c2982e87 | 524 | sprintf (line, "%s*fsb*DirList.doubleClickInterval: %"pI"d", |
cf9b4b0b | 525 | myclass, XFASTINT (Vdouble_click_time)); |
4da4f201 | 526 | XrmPutLineResource (&rdb, line); |
c2982e87 | 527 | sprintf (line, "%s*fsb*ItemsList.doubleClickInterval: %"pI"d", |
cf9b4b0b | 528 | myclass, XFASTINT (Vdouble_click_time)); |
4da4f201 GM |
529 | XrmPutLineResource (&rdb, line); |
530 | } | |
531 | ||
532 | #else /* not USE_MOTIF */ | |
427ec082 | 533 | |
fc6c5dfe | 534 | sprintf (line, "Emacs.dialog*.background: grey75"); |
4da4f201 | 535 | XrmPutLineResource (&rdb, line); |
3928f2b6 JD |
536 | #if !defined (HAVE_XFT) || !defined (USE_LUCID) |
537 | sprintf (line, "Emacs.dialog*.font: %s", helv); | |
538 | XrmPutLineResource (&rdb, line); | |
fc6c5dfe | 539 | sprintf (line, "*XlwMenu*font: %s", helv); |
4da4f201 | 540 | XrmPutLineResource (&rdb, line); |
3928f2b6 | 541 | #endif |
fc6c5dfe | 542 | sprintf (line, "*XlwMenu*background: grey75"); |
4da4f201 | 543 | XrmPutLineResource (&rdb, line); |
fc6c5dfe | 544 | sprintf (line, "Emacs*verticalScrollBar.background: grey75"); |
4da4f201 | 545 | XrmPutLineResource (&rdb, line); |
427ec082 | 546 | |
4da4f201 GM |
547 | #endif /* not USE_MOTIF */ |
548 | ||
837255fb JB |
549 | user_database = get_user_db (display); |
550 | ||
551 | /* Figure out what the "customization string" is, so we can use it | |
552 | to decode paths. */ | |
1b6d8cf0 | 553 | xfree (x_customization_string); |
837255fb JB |
554 | x_customization_string |
555 | = x_get_customization_string (user_database, myname, myclass); | |
556 | ||
f3a0bf5c JB |
557 | /* Get application system defaults */ |
558 | db = get_system_app (myclass); | |
559 | if (db != NULL) | |
560 | XrmMergeDatabases (db, &rdb); | |
561 | ||
562 | /* Get Fallback resources */ | |
563 | db = get_fallback (display); | |
564 | if (db != NULL) | |
565 | XrmMergeDatabases (db, &rdb); | |
566 | ||
567 | /* Get application user defaults */ | |
568 | db = get_user_app (myclass); | |
569 | if (db != NULL) | |
570 | XrmMergeDatabases (db, &rdb); | |
571 | ||
572 | /* get User defaults */ | |
837255fb JB |
573 | if (user_database != NULL) |
574 | XrmMergeDatabases (user_database, &rdb); | |
f3a0bf5c JB |
575 | |
576 | /* Get Environment defaults. */ | |
577 | db = get_environ_db (); | |
578 | if (db != NULL) | |
579 | XrmMergeDatabases (db, &rdb); | |
427ec082 | 580 | |
f3a0bf5c JB |
581 | /* Last, merge in any specification from the command line. */ |
582 | if (xrm_string != NULL) | |
583 | { | |
584 | db = XrmGetStringDatabase (xrm_string); | |
585 | if (db != NULL) | |
586 | XrmMergeDatabases (db, &rdb); | |
587 | } | |
588 | ||
589 | return rdb; | |
590 | } | |
591 | ||
837255fb | 592 | |
f3a0bf5c JB |
593 | /* Retrieve the value of the resource specified by NAME with class CLASS |
594 | and of type TYPE from database RDB. The value is returned in RET_VALUE. */ | |
595 | ||
2f7c71a1 AS |
596 | static int |
597 | x_get_resource (XrmDatabase rdb, const char *name, const char *class, | |
598 | XrmRepresentation expected_type, XrmValue *ret_value) | |
f3a0bf5c JB |
599 | { |
600 | XrmValue value; | |
601 | XrmName namelist[100]; | |
602 | XrmClass classlist[100]; | |
603 | XrmRepresentation type; | |
604 | ||
5e617bc2 JB |
605 | XrmStringToNameList (name, namelist); |
606 | XrmStringToClassList (class, classlist); | |
f3a0bf5c JB |
607 | |
608 | if (XrmQGetResource (rdb, namelist, classlist, &type, &value) == True | |
609 | && (type == expected_type)) | |
610 | { | |
611 | if (type == x_rm_string) | |
41ab0754 | 612 | ret_value->addr = (char *) value.addr; |
f3a0bf5c | 613 | else |
72af86bd | 614 | memcpy (ret_value->addr, value.addr, ret_value->size); |
f3a0bf5c JB |
615 | |
616 | return value.size; | |
617 | } | |
618 | ||
619 | return 0; | |
620 | } | |
621 | ||
622 | /* Retrieve the string resource specified by NAME with CLASS from | |
623 | database RDB. */ | |
624 | ||
625 | char * | |
eec47d6b | 626 | x_get_string_resource (XrmDatabase rdb, const char *name, const char *class) |
f3a0bf5c JB |
627 | { |
628 | XrmValue value; | |
629 | ||
8686ac71 JB |
630 | if (inhibit_x_resources) |
631 | /* --quick was passed, so this is a no-op. */ | |
632 | return NULL; | |
633 | ||
f3a0bf5c JB |
634 | if (x_get_resource (rdb, name, class, x_rm_string, &value)) |
635 | return (char *) value.addr; | |
636 | ||
637 | return (char *) 0; | |
638 | } | |
639 | \f | |
837255fb JB |
640 | /* Stand-alone test facilities. */ |
641 | ||
f3a0bf5c | 642 | #ifdef TESTRM |
837255fb JB |
643 | |
644 | typedef char **List; | |
645 | #define arg_listify(len, list) (list) | |
646 | #define car(list) (*(list)) | |
647 | #define cdr(list) (list + 1) | |
648 | #define NIL(list) (! *(list)) | |
649 | #define free_arglist(list) | |
650 | ||
651 | static List | |
1dae0f0a | 652 | member (char *elt, List list) |
837255fb JB |
653 | { |
654 | List p; | |
655 | ||
656 | for (p = list; ! NIL (p); p = cdr (p)) | |
657 | if (! strcmp (elt, car (p))) | |
658 | return p; | |
659 | ||
660 | return p; | |
661 | } | |
f3a0bf5c JB |
662 | |
663 | static void | |
1dae0f0a | 664 | fatal (char *msg, char *prog) |
f3a0bf5c | 665 | { |
1dae0f0a AS |
666 | if (errno) |
667 | perror (prog); | |
f3a0bf5c | 668 | |
1dae0f0a AS |
669 | (void) fprintf (stderr, msg, prog); |
670 | exit (1); | |
f3a0bf5c JB |
671 | } |
672 | ||
1dae0f0a AS |
673 | int |
674 | main (int argc, char **argv) | |
f3a0bf5c JB |
675 | { |
676 | Display *display; | |
837255fb | 677 | char *displayname, *resource_string, *class, *name; |
f3a0bf5c | 678 | XrmDatabase xdb; |
837255fb | 679 | List arg_list, lp; |
f3a0bf5c JB |
680 | |
681 | arg_list = arg_listify (argc, argv); | |
682 | ||
683 | lp = member ("-d", arg_list); | |
684 | if (!NIL (lp)) | |
685 | displayname = car (cdr (lp)); | |
686 | else | |
687 | displayname = "localhost:0.0"; | |
688 | ||
689 | lp = member ("-xrm", arg_list); | |
690 | if (! NIL (lp)) | |
691 | resource_string = car (cdr (lp)); | |
692 | else | |
693 | resource_string = (char *) 0; | |
694 | ||
695 | lp = member ("-c", arg_list); | |
696 | if (! NIL (lp)) | |
697 | class = car (cdr (lp)); | |
698 | else | |
699 | class = "Emacs"; | |
700 | ||
837255fb JB |
701 | lp = member ("-n", arg_list); |
702 | if (! NIL (lp)) | |
703 | name = car (cdr (lp)); | |
704 | else | |
705 | name = "emacs"; | |
f3a0bf5c | 706 | |
837255fb | 707 | free_arglist (arg_list); |
f3a0bf5c JB |
708 | |
709 | if (!(display = XOpenDisplay (displayname))) | |
710 | fatal ("Can't open display '%s'\n", XDisplayName (displayname)); | |
711 | ||
837255fb | 712 | xdb = x_load_resources (display, resource_string, name, class); |
f3a0bf5c | 713 | |
f3a0bf5c JB |
714 | /* In a real program, you'd want to also do this: */ |
715 | display->db = xdb; | |
f3a0bf5c JB |
716 | |
717 | while (1) | |
718 | { | |
837255fb JB |
719 | char query_name[90]; |
720 | char query_class[90]; | |
721 | ||
722 | printf ("Name: "); | |
723 | gets (query_name); | |
f3a0bf5c | 724 | |
837255fb | 725 | if (strlen (query_name)) |
f3a0bf5c | 726 | { |
837255fb JB |
727 | char *value; |
728 | ||
729 | printf ("Class: "); | |
730 | gets (query_class); | |
731 | ||
732 | value = x_get_string_resource (xdb, query_name, query_class); | |
f3a0bf5c JB |
733 | |
734 | if (value != NULL) | |
837255fb | 735 | printf ("\t%s(%s): %s\n\n", query_name, query_class, value); |
f3a0bf5c JB |
736 | else |
737 | printf ("\tNo Value.\n\n"); | |
738 | } | |
739 | else | |
740 | break; | |
741 | } | |
742 | printf ("\tExit.\n\n"); | |
743 | ||
744 | XCloseDisplay (display); | |
1dae0f0a AS |
745 | |
746 | return 0; | |
f3a0bf5c JB |
747 | } |
748 | #endif /* TESTRM */ |