61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/***********************************************************
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncCopyright 1987, 1998 The Open Group
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncPermission to use, copy, modify, distribute, and sell this software and its
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncdocumentation for any purpose is hereby granted without fee, provided that
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncthe above copyright notice appear in all copies and that both that
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsynccopyright notice and this permission notice appear in supporting
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncdocumentation.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncThe above copyright notice and this permission notice shall be included in
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncall copies or substantial portions of the Software.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncExcept as contained in this notice, the name of The Open Group shall not be
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncused in advertising or otherwise to promote the sale, use or other dealings
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncin this Software without prior written authorization from The Open Group.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync All Rights Reserved
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncPermission to use, copy, modify, and distribute this software and its
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncdocumentation for any purpose and without fee is hereby granted,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncprovided that the above copyright notice appear in all copies and that
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncboth that copyright notice and this permission notice appear in
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncsupporting documentation, and that the name of Digital not be
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncused in advertising or publicity pertaining to distribution of the
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncsoftware without specific, written prior permission.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncCopyright 1992, 1993 Data General Corporation;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncCopyright 1992, 1993 OMRON Corporation
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncPermission to use, copy, modify, distribute, and sell this software and its
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncdocumentation for any purpose is hereby granted without fee, provided that the
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncabove copyright notice appear in all copies and that both that copyright
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncnotice and this permission notice appear in supporting documentation, and that
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncneither the name OMRON or DATA GENERAL be used in advertising or publicity
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncpertaining to distribution of the software without specific, written prior
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncpermission of the party whose name is to be used. Neither OMRON or
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncDATA GENERAL make any representation about the suitability of this software
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncfor any purpose. It is provided "as is" without express or implied warranty.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncOMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncIN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncDATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncTORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncOF THIS SOFTWARE.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync******************************************************************/
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * X internal definitions
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* 128 event opcodes for core + extension events, excluding GE */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsynctypedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync /* this next is used with None and ParentRelative to tell
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync PaintWin() what to use to paint the background. Also used
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync in the macro IS_VALID_PIXMAP */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* byte swap a 32-bit literal */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline uint32_t
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | ((x >> 24) & 0xff);
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* byte swap a 16-bit literal */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline uint16_t
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* abs() is a function, not a macro; include the file declaring
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * it in case we haven't done that yet.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* this assumes b > 0 */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * return the least significant bit in x which is set
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * This works on 1's complement and 2's complement machines.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * If you care about the extra instruction on 2's complement
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * machines, change to ((x) & (-(x)))
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* XXX Not for modules */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * Some implementations #define these through <math.h>, so preclude
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * #include'ing it later.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * Calculate the number of bytes needed to hold bits.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @param bits The minimum number of bits needed.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @return The number of bytes needed to hold bits.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline int
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * Calculate the number of 4-byte units needed to hold the given number of
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @param bytes The minimum number of bytes needed.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @return The number of 4-byte units needed to hold bytes.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline int
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * Calculate the number of bytes (in multiples of 4) needed to hold bytes.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @param bytes The minimum number of bytes needed.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @return The closest multiple of 4 that is equal or higher than bytes.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline int
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * Calculate padding needed to bring the number of bytes to an even
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * multiple of 4.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @param bytes The minimum number of bytes needed.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @return The bytes of padding needed to arrive at the closest multiple of 4
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * that is equal or higher than bytes.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline int
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncextern char **xstrtokenize(const char *str, const char *separators);
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncextern void FormatUInt64(uint64_t num, char *string);
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncextern void FormatUInt64Hex(uint64_t num, char *string);
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * Compare the two version numbers comprising of major.minor.
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * @return A value less than 0 if a is less than b, 0 if a is equal to b,
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * or a value greater than 0
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline int
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* some macros to help swap requests, replies, and events */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncvoid __attribute__ ((error("wrong sized variable passed to swap")))
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline void
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)))
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline int
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* byte swap a 64-bit value */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline void
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync n = ((char *) x)[0];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[0] = ((char *) x)[7];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[7] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync n = ((char *) x)[1];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[6] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync n = ((char *) x)[2];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[5] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync n = ((char *) x)[3];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[4] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync if (sizeof(*(x)) != 8) \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync } while (0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* byte swap a 32-bit value */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline void
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync char n = ((char *) x)[0];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[0] = ((char *) x)[3];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[3] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync n = ((char *) x)[1];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[2] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync if (sizeof(*(x)) != 4) \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync *(x) = lswapl(*(x)); \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync } while (0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* byte swap a 16-bit value */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncstatic inline void
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync char n = ((char *) x)[0];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[0] = ((char *) x)[1];
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ((char *) x)[1] = n;
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync if (sizeof(*(x)) != 2) \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync *(x) = lswaps(*(x)); \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync } while (0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* copy 32-bit value from src to dst byteswapping on the way */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync } while (0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* copy short from src to dst byteswapping on the way */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync } while (0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncextern _X_EXPORT void SwapLongs(CARD32 *list, unsigned long count);
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncextern _X_EXPORT void SwapShorts(short *list, unsigned long count);
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsyncextern _X_EXPORT int Ones(unsigned long /*mask */ );
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* typedefs from other places - duplicated here to minimize the amount
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * of unnecessary junk that one would normally have to include to get
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync * these symbols defined
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsynctypedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync do { if (cond) { \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync } } while(0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0)
61cb83a8ccd1dd7f671f31fa93c9d8b7be09b4ccvboxsync#endif /* MISC_H */