annotate src/xrdb.c @ 974:4f88a1b78a46

* xfns.c (x_get_arg): Return Qunbound for an unspecified resource, not nil. That way, we can tell the difference between a false resource and an unspecified resource. (x_default_error): Use DEFLT if x_get_arg returns Qunbound, not Qnil. (x_figure_window_size, x_icon, Fx_create_frame): Deal with Qunbound and Qnil properly. * xfns.c (Fx_create_frame): Pass the correct number of arguments to x_set_font. * xfns.c [not HAVE_X11] (Fx_create_frame): Delete section that's only included if we *do* have X11. Blind patching. * xfns.c (x_icon): Rewritten to call x_wm_set_icon_position and x_wm_set_window_state instead of calling XSetWMHints directly. (x_wm_set_window_state, x_wm_set_icon_pixmap, x_wm_set_icon_position): Use x_wm_hints. (x_term_init): Set the `input' field of x_wm_hints, and its flag. * xfns.c (x_default_parameter): Don't call store_frame_param here; it's already taken care of by x_set_frame_parameters. * xfns.c (Fx_create_frame): Check for the `icon-type', `auto-raise', and `auto-lower' parameters. Have `icon-type' default to t, indicating that we want the nifty gnu in our icons. (Qauto_lower): New symbol. * xfns.c (x_set_icon_type): UNBLOCK_INPUT before reporting the error, not after. error doesn't return, sklitch-brain. * xfns.c (x_set_frame_parameters): Properly recognize changes to the height of the frame. Recognize changes of the frame's position. * xfns.c (x_set_frame_parameters): Iterate over ALIST while the current element is cons, not while it's non-nil. (syms_of_xfns): Call init_x_parm_symbols after interning all the other atoms; init_x_parm_symbols expects Qx_frame_parameter to be initialized. * xfns.c (Qbackground_color, Qborder_color, Qborder_width, Qcursor_color, Qfont, Qforeground_color, Qgeometry, Qhorizontal_scroll_bar, Qicon_left, Qicon_top, Qiconic_startup, Qinternal_border_width, Qleft, Qmouse_color, Qparent_id, Qsuppress_icon, Qsuppress_initial_map, Qtop, Qundefined_color, Qvertical_scroll_bar, Qwindow_id, Qx_frame_parameter): New symbols, with lisp code to rebuild syms_of_xfns. (syms_of_xfns): Initialize and staticpro them. (Qheight, Qminibuffer, Qname, Qnone, Qonly, Qwidth, Qunsplittable): Add extern declaration for these. (x_init_parm_symbols): Don't initialize Qx_frame_parameter here; it's done in syms_of_xfns. (x_default_parameter): Change the argument char *PROPNAME into a Lisp_Object PROP; let the caller take care of interning the atom. (Fx_geometry, x_figure_window_size, x_icon, Fx_create_frame): Use the new Q... variables, instead of interning things. * xfns.c (x_set_frame_param): Replaced by x_set_frame_parameters. (x_set_frame_parameters): Process the alist of parameters here. Notice `width', `height', `top', and `left' parameters. Hold off changing the frame size and position until the end, so we can do both parameters at once when they are both specified. (x_default_parameter): Call x_set_frame_parameters, not x_set_frame_param. * xfns.c (x_figure_window_size): Indicate that this function returns an int, rather than just leaving it unstated. * xfns.c (Fx_create_frame): Call change_frame_size with a DELAY of 0.
author Jim Blandy <jimb@redhat.com>
date Wed, 12 Aug 1992 14:33:03 +0000
parents 88a29c720fa7
children aaa628aaf808
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.
620
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
2 Copyright (C) 1990, 1992 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
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 #include <X11/Xlib.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include <X11/Xatom.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include <X11/Xos.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include <X11/X.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include <X11/Xutil.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include <X11/Xresource.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #include <sys/param.h>
556
af0eae450bc9 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
27 #ifdef VMS
af0eae450bc9 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
28 #include "vms-pwd.h"
af0eae450bc9 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
29 #else
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include <pwd.h>
556
af0eae450bc9 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
31 #endif
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #include <sys/stat.h>
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 159
diff changeset
33 #include <sys/types.h>
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 #ifdef emacs
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 #include "config.h"
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #endif
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 extern char *getenv ();
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 159
diff changeset
40 extern uid_t getuid ();
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 extern struct passwd *getpwuid ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 extern struct passwd *getpwnam ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 static char *
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 gethomedir (dirname)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 char *dirname;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 int uid;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 struct passwd *pw;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 char *ptr;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 if ((ptr = getenv ("HOME")) == NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 if ((ptr = getenv ("USER")) != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 pw = getpwnam (ptr);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 uid = getuid ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 pw = getpwuid (uid);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 if (pw)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 ptr = pw->pw_dir;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 ptr = NULL;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 *dirname = '\0';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 if (ptr != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 strcpy (dirname, ptr);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 dirname += strlen (dirname);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 *dirname = '/';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 dirname++;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 *dirname = '\0';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 return dirname;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 static int
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 file_p (path)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 char *path;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 struct stat status;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 return (access (path, R_OK) == 0 /* exists and is readable */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 && stat (path, &status) == 0 /* get the status */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 && (status.st_mode & S_IFDIR) == 0); /* not a directory */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 #if 0
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 #define X_DEFAULT_SEARCH_PATH "/usr/lib/X11/"
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 #endif
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 /* Isn't this just disgusting? */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 #define X_DEFAULT_SEARCH_PATH "/usr/lib/X11/%L/%T/%N%S:/usr/lib/X11/%l/%T/%N%S:/usr/lib/X11/%T/%N%S"
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 static int
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 decode_magic (string, file, return_path)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 char *string, *file, *return_path;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 char *p = string;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 char *t = return_path;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 while (*p)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 if (*p == '%')
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 switch (*++p)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 case '%':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 *t++ = '%';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 p++;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 break;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 case 'N':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 case 'T':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 case 'S':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 case 'L':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 case 'l':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 case 't':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 case 'c':
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 default:
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 p++;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 if (*t == '/' && *p == '/')
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 p++;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 break;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 *t++ = *p++;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 *t = '\0';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 strcat (return_path, file);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 if (file_p (return_path))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 return 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 return_path[0] = '\0';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 return 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 static int
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 magic_searchpath_decoder (incantation_string, file, return_path)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 char *incantation_string, *return_path, *file;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 register char *s = incantation_string;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 register char *p;
620
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
149
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
150 /* Must be big enough for "%N%S". */
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
151 register int string_size = MAXPATHLEN;
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
152 register char *string = (char *) alloca (string_size * sizeof (*string));
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 while (*s)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 p = s;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 while (*p && *p != ':')
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 p++;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 if (*p == ':' && *(p + 1) == ':')
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 {
620
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
163 /* We know string is big enough for this. */
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 bcopy ("%N%S", string, 5);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 if (decode_magic (string, file, return_path))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 return 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 s = p + 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 continue;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 if (p > s)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 int len = p - s;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175
620
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
176 if (string_size < len+1)
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
177 {
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
178 string_size = 2 * len;
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
179 string = (char *) alloca (string_size * sizeof (*string));
88a29c720fa7 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 556
diff changeset
180 }
159
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 bcopy (s, string, len);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 string[len + 1] = '\0';
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 if (decode_magic (string, file, return_path))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 return 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 if (p)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 s = p + 1;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 return 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 return 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 static XrmDatabase
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 get_system_app (class)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 char *class;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 XrmDatabase db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 char path[MAXPATHLEN];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 char *p;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 if ((p = getenv ("XFILESEARCHPATH")) == NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 p = X_DEFAULT_SEARCH_PATH;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 if (! magic_searchpath_decoder (p, class, path))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 return NULL;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 db = XrmGetFileDatabase (path);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 return db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 static XrmDatabase
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 get_fallback (display)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 Display *display;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 XrmDatabase db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 return NULL;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 static XrmDatabase
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 get_user_app (class)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 char *class;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 XrmDatabase db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 char *magic_path;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 char path[MAXPATHLEN];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 if ((magic_path = getenv ("XUSERFILESEARCHPATH")) == NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 char homedir[MAXPATHLEN];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 char *default_magic;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 char *p;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 gethomedir (homedir);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 if ((p = getenv ("XAPPLRESDIR")) == NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 default_magic = "%s/%%L/%%N:%s/%%l/%%N:%s/%%N";
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 magic_path = (char *) alloca ((3 * strlen (homedir))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 + strlen (default_magic));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 sprintf (magic_path, default_magic, homedir, homedir, homedir);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 default_magic = "%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N";
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 magic_path = (char *) alloca ((3 * strlen (p))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 + strlen (default_magic)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 + strlen (homedir));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 sprintf (magic_path, default_magic, p, p, p, homedir);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 if (! magic_searchpath_decoder (magic_path, class, path))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 return NULL;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 db = XrmGetFileDatabase (path);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 return db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 static XrmDatabase
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 get_user_db (display)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 Display *display;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 XrmDatabase db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 char *xdefs;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 xdefs = XResourceManagerString (display);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 if (xdefs != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 db = XrmGetStringDatabase (xdefs);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 char xdefault[MAXPATHLEN];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 gethomedir (xdefault);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 strcat (xdefault, ".Xdefaults");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 db = XrmGetFileDatabase (xdefault);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 return db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 static XrmDatabase
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 get_environ_db ()
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 XrmDatabase db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 char *p;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 char path[MAXPATHLEN];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 if ((p = getenv ("XENVIRONMENT")) == NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 gethomedir (path);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 strcat (path, ".Xdefaults-");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 gethostname (path + strlen (path), MAXPATHLEN - strlen (path));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 p = path;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 db = XrmGetFileDatabase (p);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 return db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 /* Types of values that we can find in a database */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 #define XrmStringType "String" /* String representation */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 XrmRepresentation x_rm_string; /* Quark representation */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 /* Load X resources based on the display and a possible -xrm option. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 XrmDatabase
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 x_load_resources (display, xrm_string, myclass)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 Display *display;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 char *xrm_string, *myclass;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 char *xdefs;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 XrmDatabase rdb;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 XrmDatabase db;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 x_rm_string = XrmStringToQuark (XrmStringType);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 XrmInitialize ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 rdb = XrmGetStringDatabase ("");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 /* Get application system defaults */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 db = get_system_app (myclass);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 if (db != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 XrmMergeDatabases (db, &rdb);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 /* Get Fallback resources */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 db = get_fallback (display);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 if (db != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 XrmMergeDatabases (db, &rdb);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 /* Get application user defaults */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 db = get_user_app (myclass);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 if (db != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 XrmMergeDatabases (db, &rdb);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 /* get User defaults */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 db = get_user_db (display);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 if (db != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 XrmMergeDatabases (db, &rdb);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 /* Get Environment defaults. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 db = get_environ_db ();
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 if (db != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 XrmMergeDatabases (db, &rdb);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 /* Last, merge in any specification from the command line. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 if (xrm_string != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 db = XrmGetStringDatabase (xrm_string);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 if (db != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 XrmMergeDatabases (db, &rdb);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 return rdb;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 /* Retrieve the value of the resource specified by NAME with class CLASS
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 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
362
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 int
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 x_get_resource (rdb, name, class, expected_type, ret_value)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 XrmDatabase rdb;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 char *name, *class;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 XrmRepresentation expected_type;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 XrmValue *ret_value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 XrmValue value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 XrmName namelist[100];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 XrmClass classlist[100];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 XrmRepresentation type;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 XrmStringToNameList(name, namelist);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 XrmStringToClassList(class, classlist);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 if (XrmQGetResource (rdb, namelist, classlist, &type, &value) == True
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 && (type == expected_type))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 if (type == x_rm_string)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 (char *) ret_value->addr = value.addr;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 bcopy (value.addr, ret_value->addr, ret_value->size);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 return value.size;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 return 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 /* Retrieve the string resource specified by NAME with CLASS from
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 database RDB. */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 char *
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 x_get_string_resource (rdb, name, class)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 XrmDatabase rdb;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 char *name, *class;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 XrmValue value;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 if (x_get_resource (rdb, name, class, x_rm_string, &value))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 return (char *) value.addr;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 return (char *) 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 #ifdef TESTRM
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 #include <stdio.h>
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 #include "arg-list.h"
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 static void
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 fatal (msg, prog, x1, x2, x3, x4, x5)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 char *msg, *prog;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 int x1, x2, x3, x4, x5;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 extern int errno;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 if (errno)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 perror (prog);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 (void) fprintf (stderr, msg, prog, x1, x2, x3, x4, x5);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 exit (1);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 main (argc, argv)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 int argc;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 char **argv;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 Display *display;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 char *displayname, *resource_string, *class;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 XrmDatabase xdb;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 List *arg_list, *lp;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 arg_list = arg_listify (argc, argv);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 lp = member ("-d", arg_list);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 if (!NIL (lp))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 displayname = car (cdr (lp));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 displayname = "localhost:0.0";
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 lp = member ("-xrm", arg_list);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 if (! NIL (lp))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 resource_string = car (cdr (lp));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 resource_string = (char *) 0;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 lp = member ("-c", arg_list);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 if (! NIL (lp))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 class = car (cdr (lp));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 class = "Emacs";
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 free_arglist (arg_list);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 if (!(display = XOpenDisplay (displayname)))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 fatal ("Can't open display '%s'\n", XDisplayName (displayname));
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 xdb = x_load_resources (display, resource_string, class);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 #if 0
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 /* In a real program, you'd want to also do this: */
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 display->db = xdb;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 #endif
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 while (1)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 char line[90];
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 printf ("String: ");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 gets (line);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 if (strlen (line))
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 {
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 char *value = x_get_string_resource (xdb, line, class);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 if (value != NULL)
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 printf ("\t%s: %s\n\n", line, value);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 printf ("\tNo Value.\n\n");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 else
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 break;
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 printf ("\tExit.\n\n");
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 XCloseDisplay (display);
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 }
e7abb99c2a38 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 #endif /* TESTRM */