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