|
|
1.1 ! root 1: #include <X11/copyright.h> ! 2: ! 3: /* $XConsortium: Xlibint.h,v 11.61 88/09/06 16:09:16 jim Exp $ */ ! 4: /* Copyright 1984, 1985, 1987 Massachusetts Institute of Technology */ ! 5: ! 6: /* ! 7: * XlibInternal.h - Header definition and support file for the internal ! 8: * support routines (XlibInternal) used by the C subroutine interface ! 9: * library (Xlib) to the X Window System. ! 10: * ! 11: * Warning, there be dragons here.... ! 12: */ ! 13: #ifndef NEED_EVENTS ! 14: #define _XEVENT_ ! 15: #endif ! 16: ! 17: #ifdef CRAY ! 18: #ifndef __TYPES__ ! 19: #define __TYPES__ ! 20: #include <sys/types.h> /* forgot to protect it... */ ! 21: #endif /* __TYPES__ */ ! 22: #else ! 23: #include <sys/types.h> ! 24: #endif /* CRAY */ ! 25: ! 26: /* ! 27: * define the following if you want the Data macro to be a procedure instead ! 28: */ ! 29: #if defined(CRAY) ! 30: #define DataRoutineIsProcedure ! 31: #endif /* CRAY */ ! 32: ! 33: #include "Xlib.h" ! 34: #include <X11/Xproto.h> ! 35: #include "Xlibos.h" ! 36: #include <errno.h> ! 37: ! 38: #ifndef NULL ! 39: #define NULL 0 ! 40: #endif ! 41: #define LOCKED 1 ! 42: #define UNLOCKED 0 ! 43: ! 44: extern int errno; /* Internal system error number. */ ! 45: extern void bcopy(); ! 46: ! 47: extern (*_XIOErrorFunction)(); /* X system error reporting routine. */ ! 48: extern (*_XErrorFunction)(); /* X_Error event reporting routine. */ ! 49: extern char *_XAllocScratch(); /* fast memory allocator */ ! 50: extern Visual *_XVIDtoVisual(); /* given visual id, find structure */ ! 51: ! 52: #ifndef BUFSIZE ! 53: #define BUFSIZE 2048 /* X output buffer size. */ ! 54: #endif ! 55: #ifndef EPERBATCH ! 56: #define EPERBATCH 8 /* when batching, how many elements */ ! 57: #endif ! 58: #ifndef CURSORFONT ! 59: #define CURSORFONT "cursor" /* standard cursor fonts */ ! 60: #endif ! 61: ! 62: /* ! 63: * X Protocol packetizing macros. ! 64: */ ! 65: ! 66: /* Need to start requests on 64 bit word boundries ! 67: * on a CRAY computer so add a NoOp (127) if needed. ! 68: * A character pointer on a CRAY computer will be non-zero ! 69: * after shifting right 61 bits of it is not pointing to ! 70: * a word boundary. ! 71: */ ! 72: #ifdef WORD64 ! 73: #define WORD64ALIGN if ((long)dpy->bufptr >> 61) {\ ! 74: dpy->last_req = dpy->bufptr;\ ! 75: *(dpy->bufptr) = X_NoOperation;\ ! 76: *(dpy->bufptr+1) = 0;\ ! 77: *(dpy->bufptr+2) = 0;\ ! 78: *(dpy->bufptr+3) = 1;\ ! 79: dpy->request += 1;\ ! 80: dpy->bufptr += 4;\ ! 81: } ! 82: #else /* else does not require alignment on 64-bit boundaries */ ! 83: #define WORD64ALIGN ! 84: #endif /* WORD64 */ ! 85: ! 86: ! 87: /* ! 88: * GetReq - Get the next avilable X request packet in the buffer and ! 89: * return it. ! 90: * ! 91: * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc. ! 92: * "req" is the name of the request pointer. ! 93: * ! 94: */ ! 95: ! 96: #if defined(__STDC__) && !defined(UNIXCPP) ! 97: #define GetReq(name, req) \ ! 98: WORD64ALIGN\ ! 99: if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\ ! 100: _XFlush(dpy);\ ! 101: req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ ! 102: req->reqType = X_##name;\ ! 103: req->length = (SIZEOF(x##name##Req))>>2;\ ! 104: dpy->bufptr += SIZEOF(x##name##Req);\ ! 105: dpy->request++ ! 106: ! 107: #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ ! 108: #define GetReq(name, req) \ ! 109: WORD64ALIGN\ ! 110: if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\ ! 111: _XFlush(dpy);\ ! 112: req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ ! 113: req->reqType = X_/**/name;\ ! 114: req->length = (SIZEOF(x/**/name/**/Req))>>2;\ ! 115: dpy->bufptr += SIZEOF(x/**/name/**/Req);\ ! 116: dpy->request++ ! 117: #endif ! 118: ! 119: /* GetReqExtra is the same as GetReq, but allocates "n" additional ! 120: bytes after the request. "n" must be a multiple of 4! */ ! 121: ! 122: #if defined(__STDC__) && !defined(UNIXCPP) ! 123: #define GetReqExtra(name, n, req) \ ! 124: WORD64ALIGN\ ! 125: if ((dpy->bufptr + SIZEOF(*req) + n) > dpy->bufmax)\ ! 126: _XFlush(dpy);\ ! 127: req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ ! 128: req->reqType = X_##name;\ ! 129: req->length = (SIZEOF(*req) + n)>>2;\ ! 130: dpy->bufptr += SIZEOF(*req) + n;\ ! 131: dpy->request++ ! 132: #else ! 133: #define GetReqExtra(name, n, req) \ ! 134: WORD64ALIGN\ ! 135: if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\ ! 136: _XFlush(dpy);\ ! 137: req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ ! 138: req->reqType = X_/**/name;\ ! 139: req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\ ! 140: dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\ ! 141: dpy->request++ ! 142: #endif ! 143: ! 144: ! 145: /* ! 146: * GetResReq is for those requests that have a resource ID ! 147: * (Window, Pixmap, GContext, etc.) as their single argument. ! 148: * "rid" is the name of the resource. ! 149: */ ! 150: ! 151: #if defined(__STDC__) && !defined(UNIXCPP) ! 152: #define GetResReq(name, rid, req) \ ! 153: WORD64ALIGN\ ! 154: if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\ ! 155: _XFlush(dpy);\ ! 156: req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\ ! 157: req->reqType = X_##name;\ ! 158: req->length = 2;\ ! 159: req->id = (rid);\ ! 160: dpy->bufptr += SIZEOF(xResourceReq);\ ! 161: dpy->request++ ! 162: #else ! 163: #define GetResReq(name, rid, req) \ ! 164: WORD64ALIGN\ ! 165: if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\ ! 166: _XFlush(dpy);\ ! 167: req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\ ! 168: req->reqType = X_/**/name;\ ! 169: req->length = 2;\ ! 170: req->id = (rid);\ ! 171: dpy->bufptr += SIZEOF(xResourceReq);\ ! 172: dpy->request++ ! 173: #endif ! 174: ! 175: /* ! 176: * GetEmptyReq is for those requests that have no arguments ! 177: * at all. ! 178: */ ! 179: #if defined(__STDC__) && !defined(UNIXCPP) ! 180: #define GetEmptyReq(name, req) \ ! 181: WORD64ALIGN\ ! 182: if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ ! 183: _XFlush(dpy);\ ! 184: req = (xReq *) (dpy->last_req = dpy->bufptr);\ ! 185: req->reqType = X_##name;\ ! 186: req->length = 1;\ ! 187: dpy->bufptr += SIZEOF(xReq);\ ! 188: dpy->request++ ! 189: #else ! 190: #define GetEmptyReq(name, req) \ ! 191: WORD64ALIGN\ ! 192: if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ ! 193: _XFlush(dpy);\ ! 194: req = (xReq *) (dpy->last_req = dpy->bufptr);\ ! 195: req->reqType = X_/**/name;\ ! 196: req->length = 1;\ ! 197: dpy->bufptr += SIZEOF(xReq);\ ! 198: dpy->request++ ! 199: #endif ! 200: ! 201: ! 202: #define SyncHandle() \ ! 203: if (dpy->synchandler) (*dpy->synchandler)(dpy) ! 204: ! 205: #define FlushGC(dpy, gc) \ ! 206: if ((gc)->dirty) _XFlushGCCache((dpy), (gc)) ! 207: /* ! 208: * Data - Place data in the buffer and pad the end to provide ! 209: * 32 bit word alignment. Transmit if the buffer fills. ! 210: * ! 211: * "dpy" is a pointer to a Display. ! 212: * "data" is a pinter to a data buffer. ! 213: * "len" is the length of the data buffer. ! 214: * we can presume buffer less than 2^16 bytes, so bcopy can be used safely. ! 215: */ ! 216: #ifdef DataRoutineIsProcedure ! 217: extern void Data(); ! 218: #else ! 219: #define Data(dpy, data, len) \ ! 220: if (dpy->bufptr + (len) <= dpy->bufmax) {\ ! 221: bcopy(data, dpy->bufptr, (int)len);\ ! 222: dpy->bufptr += ((len) + 3) & ~3;\ ! 223: } else\ ! 224: _XSend(dpy, data, len) ! 225: #endif /* DataRoutineIsProcedure */ ! 226: ! 227: ! 228: /* Allocate bytes from the buffer. No padding is done, so if ! 229: * the length is not a multiple of 4, the caller must be ! 230: * careful to leave the buffer aligned after sending the ! 231: * current request. ! 232: * ! 233: * "type" is the type of the pointer being assigned to. ! 234: * "ptr" is the pointer being assigned to. ! 235: * "n" is the number of bytes to allocate. ! 236: * ! 237: * Example: ! 238: * xTextElt *elt; ! 239: * BufAlloc (xTextElt *, elt, nbytes) ! 240: */ ! 241: ! 242: #define BufAlloc(type, ptr, n) \ ! 243: if (dpy->bufptr + (n) > dpy->bufmax) \ ! 244: _XFlush (dpy); \ ! 245: ptr = (type) dpy->bufptr; \ ! 246: dpy->bufptr += (n); ! 247: ! 248: /* ! 249: * provide emulation routines for smaller architectures ! 250: */ ! 251: #ifndef WORD64 ! 252: #define Data16(dpy, data, len) Data((dpy), (char *)(data), (len)) ! 253: #define Data32(dpy, data, len) Data((dpy), (char *)(data), (len)) ! 254: #define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len)) ! 255: #define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len)) ! 256: #define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len)) ! 257: #endif /* not WORD64 */ ! 258: ! 259: #define PackData16(dpy,data,len) Data16 (dpy, data, len) ! 260: #define PackData32(dpy,data,len) Data32 (dpy, data, len) ! 261: ! 262: /* Xlib manual is bogus */ ! 263: #define PackData(dpy,data,len) PackData16 (dpy, data, len) ! 264: ! 265: #define min(a,b) (((a) < (b)) ? (a) : (b)) ! 266: #define max(a,b) (((a) > (b)) ? (a) : (b)) ! 267: ! 268: #define CI_NONEXISTCHAR 0x4000 /* required because QueryFont represents ! 269: a non-existant character with zero-value ! 270: metrics, but requires drivers to output ! 271: the default char in their place. */ ! 272: ! 273: ! 274: #ifdef MUSTCOPY ! 275: ! 276: /* a little bit of magic */ ! 277: #define OneDataCard32(dpy,dstaddr,srcvar) \ ! 278: { dpy->bufptr -= 4; Data32 (dpy, (char *) &(srcvar), 4); } ! 279: ! 280: #define STARTITERATE(tpvar,type,start,endcond,decr) \ ! 281: { register char *cpvar; \ ! 282: for (cpvar = (char *) start; endcond; cpvar = NEXTPTR(cpvar,type), decr) { \ ! 283: type dummy; bcopy (cpvar, (char *) &dummy, SIZEOF(type)); \ ! 284: tpvar = (type *) cpvar; ! 285: #define ENDITERATE }} ! 286: ! 287: #else ! 288: ! 289: /* srcvar must be a variable for large architecture version */ ! 290: #define OneDataCard32(dpy,dstaddr,srcvar) \ ! 291: { *(unsigned long *)(dstaddr) = (srcvar); } ! 292: ! 293: #define STARTITERATE(tpvar,type,start,endcond,decr) \ ! 294: for (tpvar = (type *) start; endcond; tpvar++, decr) { ! 295: #define ENDITERATE } ! 296: ! 297: #endif /* MUSTCOPY - used machines whose C structs don't line up with proto */ ! 298: ! 299: #ifdef ISOCONN ! 300: extern int fd2family[MAXSOCKS]; ! 301: ! 302: extern int (*readfn[])(); ! 303: extern int (*writefn[])(); ! 304: extern int (*readvfn[])(); ! 305: extern int (*writevfn[])(); ! 306: extern int (*ioctlfn[])(); ! 307: extern int (*closefn[])(); ! 308: #endif /* ISOCONN */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.