annotate src/xrdb.c @ 5754:1864e9a12261

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