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