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