📄 xlibint.c
字号:
sp = &dpy->screens[i]; for (j = 0; j < sp->ndepths; j++) { dp = &sp->depths[j]; /* if nvisuals == 0 then visuals will be NULL */ for (k = 0; k < dp->nvisuals; k++) { vp = &dp->visuals[k]; if (vp->visualid == id) return (vp); } } } return (NULL);}#if NeedFunctionPrototypesXFree (void *data)#elseXFree (data) char *data;#endif{ Xfree (data);}#ifdef _XNEEDBCOPYFUNCvoid _Xbcopy(b1, b2, length) register char *b1, *b2; register length;{ if (b1 < b2) { b2 += length; b1 += length; while (length--) *--b2 = *--b1; } else { while (length--) *b2++ = *b1++; }}#endif#ifdef DataRoutineIsProcedurevoid Data (dpy, data, len) Display *dpy; char *data; long len;{ if (dpy->bufptr + (len) <= dpy->bufmax) { bcopy(data, dpy->bufptr, (int)len); dpy->bufptr += ((len) + 3) & ~3; } else { _XSend(dpy, data, len); }}#endif /* DataRoutineIsProcedure */#ifdef WORD64/* * XXX This is a *really* stupid way of doing this. It should just use * dpy->bufptr directly, taking into account where in the word it is. *//* * Data16 - Place 16 bit data in the buffer. * * "dpy" is a pointer to a Display. * "data" is a pointer to the data. * "len" is the length in bytes of the data. */static doData16(dpy, data, len, packbuffer) register Display *dpy; short *data; unsigned len; char *packbuffer;{ long *lp,*lpack; long i, nwords,bits; long mask16 = 0x000000000000ffff; lp = (long *)data; lpack = (long *)packbuffer;/* nwords is the number of 16 bit values to be packed, * the low order 16 bits of each word will be packed * into 64 bit words */ nwords = len >> 1; bits = 48; for(i=0;i<nwords;i++){ if (bits == 48) *lpack = 0; *lpack ^= (*lp & mask16) << bits; bits -= 16 ; lp++; if(bits < 0){ lpack++; bits = 48; } } Data(dpy, packbuffer, len);}Data16 (dpy, data, len) Display *dpy; short *data; unsigned len;{ char packbuffer[PACKBUFFERSIZE]; unsigned nunits = PACKBUFFERSIZE >> 1; for (; len > PACKBUFFERSIZE; len -= PACKBUFFERSIZE, data += nunits) { doData16 (dpy, data, PACKBUFFERSIZE, packbuffer); } if (len) doData16 (dpy, data, len, packbuffer);}/* * Data32 - Place 32 bit data in the buffer. * * "dpy" is a pointer to a Display. * "data" is a pointer to the data. * "len" is the length in bytes of the data. */static doData32 (dpy, data, len, packbuffer) register Display *dpy; long *data; unsigned len; char *packbuffer;{ long *lp,*lpack; long i,bits,nwords; long mask32 = 0x00000000ffffffff; lpack = (long *) packbuffer; lp = data;/* nwords is the number of 32 bit values to be packed * the low order 32 bits of each word will be packed * into 64 bit words */ nwords = len >> 2; bits = 32; for(i=0;i<nwords;i++){ if (bits == 32) *lpack = 0; *lpack ^= (*lp & mask32) << bits; bits = bits ^32; lp++; if(bits) lpack++; } Data(dpy, packbuffer, len);}Data32 (dpy, data, len) Display *dpy; long *data; unsigned len;{ char packbuffer[PACKBUFFERSIZE]; unsigned nunits = PACKBUFFERSIZE >> 2; for (; len > PACKBUFFERSIZE; len -= PACKBUFFERSIZE, data += nunits) { doData32 (dpy, data, PACKBUFFERSIZE, packbuffer); } if (len) doData32 (dpy, data, len, packbuffer);}#endif /* WORD64 *//* * _XFreeQ - free the queue of events, called by XCloseDisplay */void _XFreeQ (){ register _XQEvent *qelt = _qfree; while (qelt) { register _XQEvent *qnxt = qelt->next; Xfree ((char *) qelt); qelt = qnxt; } _qfree = NULL; return;}/* Make sure this produces the same string as DefineLocal/DefineSelf in xdm. * Otherwise, Xau will not be able to find your cookies in the Xauthority file. * * Note: POSIX says that the ``nodename'' member of utsname does _not_ have * to have sufficient information for interfacing to the network, * and so, you may be better off using gethostname (if it exists). */#if (defined(_POSIX_SOURCE) && !defined(AIXV3)) || defined(hpux) || defined(USG) || defined(SVR4)#define NEED_UTSNAME#include <sys/utsname.h>#endif/* * _XGetHostname - similar to gethostname but allows special processing. */int _XGetHostname (buf, maxlen) char *buf; int maxlen;{ int len;#ifdef NEED_UTSNAME struct utsname name; uname (&name); len = strlen (name.nodename); if (len >= maxlen) len = maxlen - 1; strncpy (buf, name.nodename, len); buf[len] = '\0';#else buf[0] = '\0'; (void) gethostname (buf, maxlen); buf [maxlen - 1] = '\0'; len = strlen(buf);#endif /* NEED_UTSNAME */ return len;}/* * _XScreenOfWindow - get the Screen of a given window */Screen *_XScreenOfWindow (dpy, w) Display *dpy; Window w;{ register int i; Window root; int x, y; /* dummy variables */ unsigned int width, height, bw, depth; /* dummy variables */ if (XGetGeometry (dpy, w, &root, &x, &y, &width, &height, &bw, &depth) == False) { return None; } for (i = 0; i < ScreenCount (dpy); i++) { /* find root from list */ if (root == RootWindow (dpy, i)) { return ScreenOfDisplay (dpy, i); } } return NULL;}#if (MSKCNT > 4)/* * This is a macro if MSKCNT <= 4 */_XANYSET(src) long *src;{ int i; for (i=0; i<MSKCNT; i++) if (src[ i ]) return (1); return (0);}#endif#ifdef CRAY/* * Cray UniCOS does not have readv and writev so we emulate */#include <sys/socket.h>int _XReadV (fd, iov, iovcnt)int fd;struct iovec *iov;int iovcnt;{ struct msghdr hdr; hdr.msg_iov = iov; hdr.msg_iovlen = iovcnt; hdr.msg_accrights = 0; hdr.msg_accrightslen = 0; hdr.msg_name = 0; hdr.msg_namelen = 0; return (recvmsg (fd, &hdr, 0));}int _XWriteV (fd, iov, iovcnt)int fd;struct iovec *iov;int iovcnt;{ struct msghdr hdr; hdr.msg_iov = iov; hdr.msg_iovlen = iovcnt; hdr.msg_accrights = 0; hdr.msg_accrightslen = 0; hdr.msg_name = 0; hdr.msg_namelen = 0; return (sendmsg (fd, &hdr, 0));}#endif /* CRAY */#if defined(SYSV) && defined(SYSV386) && !defined(STREAMSCONN)/* * SYSV/386 does not have readv so we emulate */#include <sys/uio.h>int _XReadV (fd, iov, iovcnt)int fd;struct iovec *iov;int iovcnt;{ int i, len, total; char *base; errno = 0; for (i=0, total=0; i<iovcnt; i++, iov++) { len = iov->iov_len; base = iov->iov_base; while (len > 0) { register int nbytes; nbytes = read(fd, base, len); if (nbytes < 0 && total == 0) return -1; if (nbytes <= 0) return total; errno = 0; len -= nbytes; total += nbytes; base += nbytes; } } return total;}#endif /* SYSV && SYSV386 && !STREAMSCONN */#ifdef STREAMSCONN/* * Copyright 1988, 1989 AT&T, Inc. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of AT&T not be used in advertising * or publicity pertaining to distribution of the software without specific, * written prior permission. AT&T makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * AT&T DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL AT&T * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * *//* iovec.c (C source file) Acc: 575557389 Mon Mar 28 08:03:09 1988 Mod: 575557397 Mon Mar 28 08:03:17 1988 Sta: 575557397 Mon Mar 28 08:03:17 1988 Owner: 2011 Group: 1985 Permissions: 664*//* START USER STAMP AREA*//* END USER STAMP AREA*/extern char _XsTypeofStream[];extern Xstream _XsStream[];#define MAX_WORKAREA 4096static char workarea[MAX_WORKAREA];int_XReadV (fd, v, n) int fd; struct iovec v[]; int n;{ int i, rc, len, size = 0; char * buf = workarea; char * p; if (n <= 0 || n > 16) { errno = EINVAL; return (-1); } for (i = 0; i < n; ++i) { if ((len = v[i].iov_len) < 0 || v[i].iov_base == NULL) { errno = EINVAL; return (-1); } size += len; } if ((size > MAX_WORKAREA) && ((buf = malloc (size)) == NULL)) { errno = EINVAL; return (-1); } if((rc = (*_XsStream[_XsTypeOfStream[fd]].ReadFromStream)(fd, buf, size, BUFFERING))> 0) { for (i = 0, p = buf; i < n; ++i) { memcpy (v[i].iov_base, p, len = v[i].iov_len); p += len; } } if (size > MAX_WORKAREA) free (buf); return (rc);}int_XWriteV (fd, v, n) int fd; struct iovec v[]; int n;{ int i, rc, len, size = 0; char * buf = workarea; char * p; if (n <= 0 || n > 16) { errno = EINVAL; return (-1); } for (i = 0; i < n; ++i) { if ((len = v[i].iov_len) < 0 || v[i].iov_base == NULL) { errno = EINVAL; return (-1); } size += len; } if ((size > MAX_WORKAREA) && ((buf = malloc (size)) == NULL)) { errno = EINVAL; return (-1); } for (i = 0, p = buf; i < n; ++i) { memcpy (p, v[i].iov_base, len = v[i].iov_len); p += len; } rc = (*_XsStream[_XsTypeOfStream[fd]].WriteToStream)(fd, buf, size); if (size > MAX_WORKAREA) free (buf); return (rc);}#endif /* STREAMSCONN */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -