3 Copyright 1988, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * This file contains routines to handle common selection targets.
30 * Public entry points:
32 * XmuConvertStandardSelection() return a known selection
40 #include <interlan/il_types.h>
41 #define __TYPES__ /* prevent #include <sys/types.h> in Xlib.h */
42 #include <interlan/netdb.h>
43 #include <interlan/socket.h>
46 #include <X11/IntrinsicP.h>
47 #include <X11/Xatom.h>
48 #include <X11/ShellP.h>
50 #include <X11/Xthreads.h>
56 #include <X11/Xwinsock.h>
57 #define XOS_USE_MTSAFE_NETDBAPI
60 #include <sys/socket.h>
62 #include <sys/types.h>
65 #define XOS_USE_XT_LOCKING
67 #define X_INCLUDE_NETDB_H
68 #include <X11/Xos_r.h>
76 #include <X11/Xfuncs.h>
80 #ifdef SYSV /* keep separate until makedepend fixed */
94 #include <sys/utsname.h>
101 static char *get_os_name(void);
102 static Bool isApplicationShell(Widget);
111 return XtNewString(OS_NAME);
113 #if defined(X_OS_FILE) || defined(MOTD_FILE)
120 if (uname (&utss) >= 0) {
122 int len = strlen(utss.sysname) + 1;
123 #ifndef hpux /* because of hostname length crock */
124 len += 2 + strlen(utss.release);
126 os_name = XtMalloc (len);
127 strcpy (os_name, utss.sysname);
129 strcat (os_name, " ");
130 strcat (os_name, utss.release);
137 f = fopen(X_OS_FILE, "r");
141 f = fopen(MOTD_FILE, "r");
143 #if defined(X_OS_FILE) || defined(MOTD_FILE)
147 (void) fgets(motd, 511, f);
150 if (motd[0] != '\0') {
151 int len = strlen(motd);
152 if (motd[len - 1] == '\n')
153 motd[len - 1] = '\0';
154 return XtNewString(motd);
160 return XtNewString("SunOS");
162 # if !defined(SYSV) && (defined(CSRG_BASED) || defined(unix))
163 return XtNewString("BSD");
172 /* This is a trick/kludge. To make shared libraries happier (linking
173 * against Xmu but not linking against Xt, and apparently even work
174 * as we desire on SVR4, we need to avoid an explicit data reference
175 * to applicationShellWidgetClass. XtIsTopLevelShell is known
176 * (implementation dependent assumption!) to use a bit flag. So we
177 * go that far. Then, we test whether it is an applicationShellWidget
178 * class by looking for an explicit class name. Seems pretty safe.
181 isApplicationShell(Widget w)
183 register WidgetClass c;
185 if (!XtIsTopLevelShell(w))
187 for (c = XtClass(w); c; c = c->core_class.superclass) {
188 if (!strcmp(c->core_class.class_name, "ApplicationShell"))
195 XmuConvertStandardSelection(Widget w, Time time, Atom *selection, Atom *target,
196 Atom *type, XPointer *value,
197 unsigned long *length, int *format)
199 Display *d = XtDisplay(w);
200 if (*target == XA_TIMESTAMP(d)) {
201 *value = XtMalloc(4);
202 if (sizeof(long) == 4)
203 *(long*)*value = time;
206 (void) memmove((char*)*value, ((char*)&temp)+sizeof(long)-4, 4);
213 if (*target == XA_HOSTNAME(d)) {
216 *length = XmuGetHostname (hostname, sizeof hostname);
217 *value = XtNewString(hostname);
223 if (*target == XA_IP_ADDRESS(d)) {
225 #ifdef XTHREADS_NEEDS_BYNAMEPARAMS
226 _Xgethostbynameparams hparams;
228 struct hostent *hostp;
231 (void) XmuGetHostname (hostname, sizeof hostname);
233 if ((hostp = _XGethostbyname (hostname,hparams)) == NULL)
236 if (hostp->h_addrtype != AF_INET) return False;
237 *length = hostp->h_length;
238 *value = XtMalloc(*length);
239 (void) memmove (*value, hostp->h_addr, *length);
240 *type = XA_NET_ADDRESS(d);
246 if (*target == XA_DECNET_ADDRESS(d)) {
247 return False; /* XXX niy */
250 if (*target == XA_USER(d)) {
251 char *name = (char*)getenv("USER");
252 if (name == NULL) return False;
253 *value = XtNewString(name);
255 *length = strlen(name);
259 if (*target == XA_CLASS(d)) {
260 Widget parent = XtParent(w);
263 while (parent != NULL && !isApplicationShell(w)) {
265 parent = XtParent(w);
267 if (isApplicationShell(w))
268 class = ((ApplicationShellWidget) w)->application.class;
270 class = XtClass(w)->core_class.class_name;
271 *length = (len=strlen(w->core.name)) + strlen(class) + 2;
272 *value = XtMalloc(*length);
273 strcpy( (char*)*value, w->core.name );
274 strcpy( (char*)*value+len+1, class );
279 if (*target == XA_NAME(d)) {
280 Widget parent = XtParent(w);
282 while (parent != NULL && !XtIsWMShell(w)) {
284 parent = XtParent(w);
286 if (!XtIsWMShell(w)) return False;
287 *value = XtNewString( ((WMShellWidget) w)->wm.title );
288 *length = strlen(*value);
293 if (*target == XA_CLIENT_WINDOW(d)) {
294 Widget parent = XtParent(w);
295 while (parent != NULL) {
297 parent = XtParent(w);
299 *value = XtMalloc(sizeof(Window));
300 *(Window*)*value = w->core.window;
306 if (*target == XA_OWNER_OS(d)) {
307 *value = get_os_name();
308 if (*value == NULL) return False;
310 *length = strlen(*value);
314 if (*target == XA_TARGETS(d)) {
315 #if defined(unix) && defined(DNETCONN)
316 # define NUM_TARGETS 9
318 # if defined(unix) || defined(DNETCONN)
319 # define NUM_TARGETS 8
321 # define NUM_TARGETS 7
324 Atom* std_targets = (Atom*)XtMalloc(NUM_TARGETS*sizeof(Atom));
326 std_targets[i++] = XA_TIMESTAMP(d);
327 std_targets[i++] = XA_HOSTNAME(d);
328 std_targets[i++] = XA_IP_ADDRESS(d);
329 std_targets[i++] = XA_USER(d);
330 std_targets[i++] = XA_CLASS(d);
331 std_targets[i++] = XA_NAME(d);
332 std_targets[i++] = XA_CLIENT_WINDOW(d);
334 std_targets[i++] = XA_OWNER_OS(d);
337 std_targets[i++] = XA_DECNET_ADDRESS(d);
339 *value = (XPointer)std_targets;
341 *length = NUM_TARGETS;