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