#include <X11/IntrinsicP.h>#include <X11/Xatom.h>#include <X11/ShellP.h>#include <stdio.h>#include <sys/socket.h>#include <X11/Xos_r.h>#include <X11/Xos.h>#include <stdlib.h>#include "Atoms.h"#include "StdSel.h"#include "SysUtil.h"#include <X11/Xfuncs.h>Include dependency graph for CvtStdSel.c:

Go to the source code of this file.
Defines | |
| #define | XOS_USE_XT_LOCKING |
| #define | X_INCLUDE_NETDB_H |
| #define | NUM_TARGETS 7 |
Functions | |
| static char * | get_os_name (void) |
| static Bool | isApplicationShell (Widget) |
| Boolean | XmuConvertStandardSelection (Widget w, Time time, Atom *selection, Atom *target, Atom *type, XPointer *value, unsigned long *length, int *format) |
| #define NUM_TARGETS 7 |
Referenced by XmuConvertStandardSelection().
| #define X_INCLUDE_NETDB_H |
Definition at line 66 of file CvtStdSel.c.
| #define XOS_USE_XT_LOCKING |
Definition at line 64 of file CvtStdSel.c.
| static char * get_os_name | ( | void | ) | [static] |
Definition at line 107 of file CvtStdSel.c.
References f(), len, NULL, and void().
Referenced by XmuConvertStandardSelection().
00108 { 00109 #ifdef OS_NAME 00110 return XtNewString(OS_NAME); 00111 #else 00112 FILE *f = NULL; 00113 00114 #ifdef USE_UNAME 00115 struct utsname utss; 00116 00117 if (uname (&utss) == 0) { 00118 char *os_name; 00119 int len = strlen(utss.sysname) + 1; 00120 #ifndef hpux /* because of hostname length crock */ 00121 len += 2 + strlen(utss.release); 00122 #endif 00123 os_name = XtMalloc (len); 00124 strcpy (os_name, utss.sysname); 00125 #ifndef hpux 00126 strcat (os_name, " "); 00127 strcat (os_name, utss.release); 00128 #endif 00129 return os_name; 00130 } 00131 #endif 00132 00133 #ifdef X_OS_FILE 00134 f = fopen(X_OS_FILE, "r"); 00135 if (!f) 00136 #endif 00137 #ifdef MOTD_FILE 00138 f = fopen(MOTD_FILE, "r"); 00139 #endif 00140 if (f) { 00141 char motd[512]; 00142 motd[0] = '\0'; 00143 (void) fgets(motd, 511, f); 00144 fclose(f); 00145 motd[511] = '\0'; 00146 if (motd[0] != '\0') { 00147 int len = strlen(motd); 00148 if (motd[len - 1] == '\n') 00149 motd[len - 1] = '\0'; 00150 return XtNewString(motd); 00151 } 00152 } 00153 00154 #ifdef sun 00155 return XtNewString("SunOS"); 00156 #else 00157 # if !defined(SYSV) && (defined(CSRG_BASED) || defined(unix)) 00158 return XtNewString("BSD"); 00159 # else 00160 return NULL; 00161 # endif 00162 #endif 00163 00164 #endif /*OS_NAME*/ 00165 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static Bool isApplicationShell | ( | Widget | ) | [static] |
Definition at line 176 of file CvtStdSel.c.
Referenced by DumpChildren(), and XmuConvertStandardSelection().
00177 { 00178 register WidgetClass c; 00179 00180 if (!XtIsTopLevelShell(w)) 00181 return False; 00182 for (c = XtClass(w); c; c = c->core_class.superclass) { 00183 if (!strcmp(c->core_class.class_name, "ApplicationShell")) 00184 return True; 00185 } 00186 return False; 00187 }
Here is the caller graph for this function:

| Boolean XmuConvertStandardSelection | ( | Widget | w, | |
| Time | time, | |||
| Atom * | selection, | |||
| Atom * | target, | |||
| Atom * | type, | |||
| XPointer * | value, | |||
| unsigned long * | length, | |||
| int * | format | |||
| ) |
Definition at line 190 of file CvtStdSel.c.
References get_os_name(), getenv(), i, isApplicationShell(), len, name, NULL, NUM_TARGETS, void(), XA_CLASS, XA_CLIENT_WINDOW, XA_DECNET_ADDRESS, XA_HOSTNAME, XA_IP_ADDRESS, XA_NAME, XA_NET_ADDRESS, XA_OWNER_OS, XA_TARGETS, XA_TIMESTAMP, XA_USER, and XmuGetHostname().
Referenced by ConvertSelection().
00193 { 00194 Display *d = XtDisplay(w); 00195 if (*target == XA_TIMESTAMP(d)) { 00196 *value = XtMalloc(4); 00197 if (sizeof(long) == 4) 00198 *(long*)*value = time; 00199 else { 00200 long temp = time; 00201 (void) memmove((char*)*value, ((char*)&temp)+sizeof(long)-4, 4); 00202 } 00203 *type = XA_INTEGER; 00204 *length = 1; 00205 *format = 32; 00206 return True; 00207 } 00208 if (*target == XA_HOSTNAME(d)) { 00209 char hostname[1024]; 00210 hostname[0] = '\0'; 00211 *length = XmuGetHostname (hostname, sizeof hostname); 00212 *value = XtNewString(hostname); 00213 *type = XA_STRING; 00214 *format = 8; 00215 return True; 00216 } 00217 #if defined(TCPCONN) 00218 if (*target == XA_IP_ADDRESS(d)) { 00219 char hostname[1024]; 00220 #ifdef XTHREADS_NEEDS_BYNAMEPARAMS 00221 _Xgethostbynameparams hparams; 00222 #endif 00223 struct hostent *hostp; 00224 00225 hostname[0] = '\0'; 00226 (void) XmuGetHostname (hostname, sizeof hostname); 00227 00228 if ((hostp = _XGethostbyname (hostname,hparams)) == NULL) 00229 return False; 00230 00231 if (hostp->h_addrtype != AF_INET) return False; 00232 *length = hostp->h_length; 00233 *value = XtMalloc(*length); 00234 (void) memmove (*value, hostp->h_addr, *length); 00235 *type = XA_NET_ADDRESS(d); 00236 *format = 8; 00237 return True; 00238 } 00239 #endif 00240 #ifdef DNETCONN 00241 if (*target == XA_DECNET_ADDRESS(d)) { 00242 return False; /* XXX niy */ 00243 } 00244 #endif 00245 if (*target == XA_USER(d)) { 00246 char *name = (char*)getenv("USER"); 00247 if (name == NULL) return False; 00248 *value = XtNewString(name); 00249 *type = XA_STRING; 00250 *length = strlen(name); 00251 *format = 8; 00252 return True; 00253 } 00254 if (*target == XA_CLASS(d)) { 00255 Widget parent = XtParent(w); 00256 char *class; 00257 int len; 00258 while (parent != NULL && !isApplicationShell(w)) { 00259 w = parent; 00260 parent = XtParent(w); 00261 } 00262 if (isApplicationShell(w)) 00263 class = ((ApplicationShellWidget) w)->application.class; 00264 else 00265 class = XtClass(w)->core_class.class_name; 00266 *length = (len=strlen(w->core.name)) + strlen(class) + 2; 00267 *value = XtMalloc(*length); 00268 strcpy( (char*)*value, w->core.name ); 00269 strcpy( (char*)*value+len+1, class ); 00270 *type = XA_STRING; 00271 *format = 8; 00272 return True; 00273 } 00274 if (*target == XA_NAME(d)) { 00275 Widget parent = XtParent(w); 00276 00277 while (parent != NULL && !XtIsWMShell(w)) { 00278 w = parent; 00279 parent = XtParent(w); 00280 } 00281 if (!XtIsWMShell(w)) return False; 00282 *value = XtNewString( ((WMShellWidget) w)->wm.title ); 00283 *length = strlen(*value); 00284 *type = XA_STRING; 00285 *format = 8; 00286 return True; 00287 } 00288 if (*target == XA_CLIENT_WINDOW(d)) { 00289 Widget parent = XtParent(w); 00290 while (parent != NULL) { 00291 w = parent; 00292 parent = XtParent(w); 00293 } 00294 *value = XtMalloc(sizeof(Window)); 00295 *(Window*)*value = w->core.window; 00296 *type = XA_WINDOW; 00297 *length = 1; 00298 *format = 32; 00299 return True; 00300 } 00301 if (*target == XA_OWNER_OS(d)) { 00302 *value = get_os_name(); 00303 if (*value == NULL) return False; 00304 *type = XA_STRING; 00305 *length = strlen(*value); 00306 *format = 8; 00307 return True; 00308 } 00309 if (*target == XA_TARGETS(d)) { 00310 #if defined(unix) && defined(DNETCONN) 00311 # define NUM_TARGETS 9 00312 #else 00313 # if defined(unix) || defined(DNETCONN) 00314 # define NUM_TARGETS 8 00315 # else 00316 # define NUM_TARGETS 7 00317 # endif 00318 #endif 00319 Atom* std_targets = (Atom*)XtMalloc(NUM_TARGETS*sizeof(Atom)); 00320 int i = 0; 00321 std_targets[i++] = XA_TIMESTAMP(d); 00322 std_targets[i++] = XA_HOSTNAME(d); 00323 std_targets[i++] = XA_IP_ADDRESS(d); 00324 std_targets[i++] = XA_USER(d); 00325 std_targets[i++] = XA_CLASS(d); 00326 std_targets[i++] = XA_NAME(d); 00327 std_targets[i++] = XA_CLIENT_WINDOW(d); 00328 #ifdef unix 00329 std_targets[i++] = XA_OWNER_OS(d); 00330 #endif 00331 #ifdef DNETCONN 00332 std_targets[i++] = XA_DECNET_ADDRESS(d); 00333 #endif 00334 *value = (XPointer)std_targets; 00335 *type = XA_ATOM; 00336 *length = NUM_TARGETS; 00337 *format = 32; 00338 return True; 00339 } 00340 /* else */ 00341 return False; 00342 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.5.1