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