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