1/*********************************************************** 2 3Copyright 1987, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 27 28 All Rights Reserved 29 30Permission to use, copy, modify, and distribute this software and its 31documentation for any purpose and without fee is hereby granted, 32provided that the above copyright notice appear in all copies and that 33both that copyright notice and this permission notice appear in 34supporting documentation, and that the name of Digital not be 35used in advertising or publicity pertaining to distribution of the 36software without specific, written prior permission. 37 38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 44SOFTWARE. 45 46Copyright 1992, 1993 Data General Corporation; 47Copyright 1992, 1993 OMRON Corporation 48 49Permission to use, copy, modify, distribute, and sell this software and its 50documentation for any purpose is hereby granted without fee, provided that the 51above copyright notice appear in all copies and that both that copyright 52notice and this permission notice appear in supporting documentation, and that 53neither the name OMRON or DATA GENERAL be used in advertising or publicity 54pertaining to distribution of the software without specific, written prior 55permission of the party whose name is to be used. Neither OMRON or 56DATA GENERAL make any representation about the suitability of this software 57for any purpose. It is provided "as is" without express or implied warranty. 58 59OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 60SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 61IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT 62OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 63DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 64TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 65OF THIS SOFTWARE. 66 67******************************************************************/ 68#ifndef MISC_H 69#define MISC_H 1 70/* 71 * X internal definitions 72 * 73 */ 74 75#include <X11/Xosdefs.h> 76#include <X11/Xfuncproto.h> 77#include <X11/Xmd.h> 78#include <X11/X.h> 79#include <X11/Xdefs.h> 80 81#include <stddef.h> 82 83#ifndef MAXSCREENS 84#define MAXSCREENS 16 85#endif 86#define MAXCLIENTS 256 87#define MAXEXTENSIONS 128 88#define MAXFORMATS 8 89#define MAXDEVICES 40 /* input devices */ 90 91#define EXTENSION_EVENT_BASE 64 92#define EXTENSION_BASE 128 93 94typedef unsigned long PIXEL; 95typedef unsigned long ATOM; 96 97 98#ifndef TRUE 99#define TRUE 1 100#define FALSE 0 101#endif 102 103#ifndef _XTYPEDEF_CALLBACKLISTPTR 104typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ 105#define _XTYPEDEF_CALLBACKLISTPTR 106#endif 107 108typedef struct _xReq *xReqPtr; 109 110#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */ 111#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */ 112 113#define NullBox ((BoxPtr)0) 114#define MILLI_PER_MIN (1000 * 60) 115#define MILLI_PER_SECOND (1000) 116 117 /* this next is used with None and ParentRelative to tell 118 PaintWin() what to use to paint the background. Also used 119 in the macro IS_VALID_PIXMAP */ 120 121#define USE_BACKGROUND_PIXEL 3 122#define USE_BORDER_PIXEL 3 123 124 125/* byte swap a 32-bit literal */ 126#define lswapl(x) ((((x) & 0xff) << 24) |\ 127 (((x) & 0xff00) << 8) |\ 128 (((x) & 0xff0000) >> 8) |\ 129 (((x) >> 24) & 0xff)) 130 131/* byte swap a short literal */ 132#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)) 133 134#undef min 135#undef max 136 137#define min(a, b) (((a) < (b)) ? (a) : (b)) 138#define max(a, b) (((a) > (b)) ? (a) : (b)) 139/* abs() is a function, not a macro; include the file declaring 140 * it in case we haven't done that yet. 141 */ 142#include <stdlib.h> 143#ifndef Fabs 144#define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */ 145#endif 146#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) 147/* this assumes b > 0 */ 148#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b) 149/* 150 * return the least significant bit in x which is set 151 * 152 * This works on 1's complement and 2's complement machines. 153 * If you care about the extra instruction on 2's complement 154 * machines, change to ((x) & (-(x))) 155 */ 156#define lowbit(x) ((x) & (~(x) + 1)) 157 158/* XXX Not for modules */ 159#include <limits.h> 160#if !defined(MAXSHORT) || !defined(MINSHORT) || \ 161 !defined(MAXINT) || !defined(MININT) 162/* 163 * Some implementations #define these through <math.h>, so preclude 164 * #include'ing it later. 165 */ 166 167#include <math.h> 168#undef MAXSHORT 169#define MAXSHORT SHRT_MAX 170#undef MINSHORT 171#define MINSHORT SHRT_MIN 172#undef MAXINT 173#define MAXINT INT_MAX 174#undef MININT 175#define MININT INT_MIN 176 177#include <assert.h> 178#include <ctype.h> 179#include <stdio.h> /* for fopen, etc... */ 180 181#endif 182 183/** 184 * Calculate the number of bytes needed to hold bits. 185 * @param bits The minimum number of bits needed. 186 * @return The number of bytes needed to hold bits. 187 */ 188static inline int 189bits_to_bytes(const int bits) { 190 return ((bits + 7) >> 3); 191} 192/** 193 * Calculate the number of 4-byte units needed to hold the given number of 194 * bytes. 195 * @param bytes The minimum number of bytes needed. 196 * @return The number of 4-byte units needed to hold bytes. 197 */ 198static inline int 199bytes_to_int32(const int bytes) { 200 return (((bytes) + 3) >> 2); 201} 202 203/** 204 * Calculate the number of bytes (in multiples of 4) needed to hold bytes. 205 * @param bytes The minimum number of bytes needed. 206 * @return The closest multiple of 4 that is equal or higher than bytes. 207 */ 208static inline int 209pad_to_int32(const int bytes) { 210 return (((bytes) + 3) & ~3); 211} 212 213extern char** 214xstrtokenize(const char *str, const char* separators); 215 216/* some macros to help swap requests, replies, and events */ 217 218#define LengthRestB(stuff) \ 219 ((client->req_len << 2) - sizeof(*stuff)) 220 221#define LengthRestS(stuff) \ 222 ((client->req_len << 1) - (sizeof(*stuff) >> 1)) 223 224#define LengthRestL(stuff) \ 225 (client->req_len - (sizeof(*stuff) >> 2)) 226 227#define SwapRestS(stuff) \ 228 SwapShorts((short *)(stuff + 1), LengthRestS(stuff)) 229 230#define SwapRestL(stuff) \ 231 SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff)) 232 233#ifndef bswap_16 234#define bswap_16(value) \ 235 ((((value) & 0xff) << 8) | ((value) >> 8)) 236 237#define bswap_32(value) \ 238 (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \ 239 (uint32_t)bswap_16((uint16_t)((value) >> 16))) 240 241#define bswap_64(value) \ 242 (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \ 243 << 32) | \ 244 (uint64_t)bswap_32((uint32_t)((value) >> 32))) 245#endif 246 247/* byte swap a 32-bit value */ 248#define swapl(x, n) { \ 249 n = ((char *) (x))[0];\ 250 ((char *) (x))[0] = ((char *) (x))[3];\ 251 ((char *) (x))[3] = n;\ 252 n = ((char *) (x))[1];\ 253 ((char *) (x))[1] = ((char *) (x))[2];\ 254 ((char *) (x))[2] = n; } 255 256/* byte swap a short */ 257#define swaps(x, n) { \ 258 n = ((char *) (x))[0];\ 259 ((char *) (x))[0] = ((char *) (x))[1];\ 260 ((char *) (x))[1] = n; } 261 262/* copy 32-bit value from src to dst byteswapping on the way */ 263#define cpswapl(src, dst) { \ 264 ((char *)&(dst))[0] = ((char *) &(src))[3];\ 265 ((char *)&(dst))[1] = ((char *) &(src))[2];\ 266 ((char *)&(dst))[2] = ((char *) &(src))[1];\ 267 ((char *)&(dst))[3] = ((char *) &(src))[0]; } 268 269/* copy short from src to dst byteswapping on the way */ 270#define cpswaps(src, dst) { \ 271 ((char *) &(dst))[0] = ((char *) &(src))[1];\ 272 ((char *) &(dst))[1] = ((char *) &(src))[0]; } 273 274extern _X_EXPORT void SwapLongs( 275 CARD32 *list, 276 unsigned long count); 277 278extern _X_EXPORT void SwapShorts( 279 short *list, 280 unsigned long count); 281 282extern _X_EXPORT void MakePredeclaredAtoms(void); 283 284extern _X_EXPORT int Ones( 285 unsigned long /*mask*/); 286 287typedef struct _xPoint *DDXPointPtr; 288typedef struct pixman_box16 *BoxPtr; 289typedef struct _xEvent *xEventPtr; 290typedef struct _xRectangle *xRectanglePtr; 291typedef struct _GrabRec *GrabPtr; 292 293/* typedefs from other places - duplicated here to minimize the amount 294 * of unnecessary junk that one would normally have to include to get 295 * these symbols defined 296 */ 297 298#ifndef _XTYPEDEF_CHARINFOPTR 299typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */ 300#define _XTYPEDEF_CHARINFOPTR 301#endif 302 303extern _X_EXPORT unsigned long globalSerialNumber; 304extern _X_EXPORT unsigned long serverGeneration; 305 306#endif /* MISC_H */ 307