a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/***********************************************************
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncCopyright 1987, 1998 The Open Group
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncPermission to use, copy, modify, distribute, and sell this software and its
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncdocumentation for any purpose is hereby granted without fee, provided that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncthe above copyright notice appear in all copies and that both that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynccopyright notice and this permission notice appear in supporting
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncdocumentation.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncThe above copyright notice and this permission notice shall be included in
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncall copies or substantial portions of the Software.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncExcept as contained in this notice, the name of The Open Group shall not be
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncused in advertising or otherwise to promote the sale, use or other dealings
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncin this Software without prior written authorization from The Open Group.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync All Rights Reserved
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncPermission to use, copy, modify, and distribute this software and its
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncdocumentation for any purpose and without fee is hereby granted,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncprovided that the above copyright notice appear in all copies and that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncboth that copyright notice and this permission notice appear in
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncsupporting documentation, and that the name of Digital not be
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncused in advertising or publicity pertaining to distribution of the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncsoftware without specific, written prior permission.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncSOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncCopyright 1992, 1993 Data General Corporation;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncCopyright 1992, 1993 OMRON Corporation
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncPermission to use, copy, modify, distribute, and sell this software and its
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncdocumentation for any purpose is hereby granted without fee, provided that the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncabove copyright notice appear in all copies and that both that copyright
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncnotice and this permission notice appear in supporting documentation, and that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncneither the name OMRON or DATA GENERAL be used in advertising or publicity
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncpertaining to distribution of the software without specific, written prior
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncpermission of the party whose name is to be used. Neither OMRON or
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncDATA GENERAL make any representation about the suitability of this software
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncfor any purpose. It is provided "as is" without express or implied warranty.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncIN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncDATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncTORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOF THIS SOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync******************************************************************/
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef MISC_H
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MISC_H 1
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * X internal definitions
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/Xosdefs.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/Xfuncproto.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/Xmd.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/X.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/Xdefs.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <stddef.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <stdint.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef MAXSCREENS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXSCREENS 16
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef MAXGPUSCREENS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXGPUSCREENS 16
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXCLIENTS 256
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXEXTENSIONS 128
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXFORMATS 8
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXDEVICES 40 /* input devices */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define GPU_SCREEN_OFFSET 256
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* 128 event opcodes for core + extension events, excluding GE */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXEVENTS 128
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define EXTENSION_EVENT_BASE 64
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define EXTENSION_BASE 128
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef uint32_t ATOM;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef TRUE
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define TRUE 1
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define FALSE 0
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef _XTYPEDEF_CALLBACKLISTPTR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define _XTYPEDEF_CALLBACKLISTPTR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _xReq *xReqPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define NullBox ((BoxPtr)0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MILLI_PER_MIN (1000 * 60)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MILLI_PER_SECOND (1000)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync /* this next is used with None and ParentRelative to tell
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync PaintWin() what to use to paint the background. Also used
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync in the macro IS_VALID_PIXMAP */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define USE_BACKGROUND_PIXEL 3
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define USE_BORDER_PIXEL 3
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* byte swap a 32-bit literal */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline uint32_t
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynclswapl(uint32_t x)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return ((x & 0xff) << 24) |
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | ((x >> 24) & 0xff);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* byte swap a 16-bit literal */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline uint16_t
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynclswaps(uint16_t x)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return (uint16_t)((x & 0xff) << 8) | ((x >> 8) & 0xff);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#undef min
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#undef max
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define min(a, b) (((a) < (b)) ? (a) : (b))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define max(a, b) (((a) > (b)) ? (a) : (b))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* abs() is a function, not a macro; include the file declaring
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * it in case we haven't done that yet.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <stdlib.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* this assumes b > 0 */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * return the least significant bit in x which is set
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * This works on 1's complement and 2's complement machines.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * If you care about the extra instruction on 2's complement
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * machines, change to ((x) & (-(x)))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define lowbit(x) ((x) & (~(x) + 1))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* XXX Not for modules */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <limits.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#if !defined(MAXSHORT) || !defined(MINSHORT) || \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync !defined(MAXINT) || !defined(MININT)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Some implementations #define these through <math.h>, so preclude
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * #include'ing it later.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <math.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#undef MAXSHORT
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXSHORT SHRT_MAX
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#undef MINSHORT
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MINSHORT SHRT_MIN
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#undef MAXINT
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MAXINT INT_MAX
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#undef MININT
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define MININT INT_MIN
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <assert.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <ctype.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <stdio.h> /* for fopen, etc... */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef PATH_MAX
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <sys/param.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef PATH_MAX
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifdef MAXPATHLEN
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define PATH_MAX MAXPATHLEN
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#else
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define PATH_MAX 1024
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/**
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Calculate the number of bytes needed to hold bits.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @param bits The minimum number of bits needed.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @return The number of bytes needed to hold bits.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncbits_to_bytes(const int bits)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return ((bits + 7) >> 3);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/**
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Calculate the number of 4-byte units needed to hold the given number of
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * bytes.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @param bytes The minimum number of bytes needed.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @return The number of 4-byte units needed to hold bytes.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncbytes_to_int32(const int bytes)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return (((bytes) + 3) >> 2);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/**
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Calculate the number of bytes (in multiples of 4) needed to hold bytes.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @param bytes The minimum number of bytes needed.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @return The closest multiple of 4 that is equal or higher than bytes.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncpad_to_int32(const int bytes)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return (((bytes) + 3) & ~3);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/**
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Calculate padding needed to bring the number of bytes to an even
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * multiple of 4.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @param bytes The minimum number of bytes needed.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @return The bytes of padding needed to arrive at the closest multiple of 4
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * that is equal or higher than bytes.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncpadding_for_int32(const int bytes)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return ((-bytes) & 3);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern char **xstrtokenize(const char *str, const char *separators);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern void FormatInt64(int64_t num, char *string);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern void FormatUInt64(uint64_t num, char *string);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern void FormatUInt64Hex(uint64_t num, char *string);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern void FormatDouble(double dbl, char *string);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/**
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Compare the two version numbers comprising of major.minor.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * @return A value less than 0 if a is less than b, 0 if a is equal to b,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * or a value greater than 0
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncversion_compare(uint32_t a_major, uint32_t a_minor,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync uint32_t b_major, uint32_t b_minor)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (a_major > b_major)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return 1;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (a_major < b_major)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return -1;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (a_minor > b_minor)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return 1;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (a_minor < b_minor)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return -1;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return 0;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* some macros to help swap requests, replies, and events */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define LengthRestB(stuff) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((client->req_len << 2) - sizeof(*stuff))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define LengthRestS(stuff) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((client->req_len << 1) - (sizeof(*stuff) >> 1))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define LengthRestL(stuff) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (client->req_len - (sizeof(*stuff) >> 2))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define SwapRestS(stuff) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define SwapRestL(stuff) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncvoid __attribute__ ((error("wrong sized variable passed to swap")))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncwrong_size(void);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#else
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline void
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncwrong_size(void)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)))
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync__builtin_constant_p(int x)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync return 0;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* byte swap a 64-bit value */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline void
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncswap_uint64(uint64_t *x)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync char n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync n = ((char *) x)[0];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[0] = ((char *) x)[7];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[7] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync n = ((char *) x)[1];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[1] = ((char *) x)[6];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[6] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync n = ((char *) x)[2];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[2] = ((char *) x)[5];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[5] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync n = ((char *) x)[3];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[3] = ((char *) x)[4];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[4] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define swapll(x) do { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (sizeof(*(x)) != 8) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync wrong_size(); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync swap_uint64((uint64_t *)(x)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } while (0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* byte swap a 32-bit value */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline void
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncswap_uint32(uint32_t * x)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync char n = ((char *) x)[0];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[0] = ((char *) x)[3];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[3] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync n = ((char *) x)[1];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[1] = ((char *) x)[2];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[2] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define swapl(x) do { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (sizeof(*(x)) != 4) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync wrong_size(); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *(x) = lswapl(*(x)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync else \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync swap_uint32((uint32_t *)(x)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } while (0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* byte swap a 16-bit value */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncstatic inline void
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncswap_uint16(uint16_t * x)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync{
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync char n = ((char *) x)[0];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[0] = ((char *) x)[1];
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ((char *) x)[1] = n;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define swaps(x) do { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (sizeof(*(x)) != 2) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync wrong_size(); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *(x) = lswaps(*(x)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync else \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync swap_uint16((uint16_t *)(x)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } while (0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* copy 32-bit value from src to dst byteswapping on the way */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define cpswapl(src, dst) do { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (sizeof((src)) != 4 || sizeof((dst)) != 4) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync wrong_size(); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (dst) = lswapl((src)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } while (0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* copy short from src to dst byteswapping on the way */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define cpswaps(src, dst) do { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (sizeof((src)) != 2 || sizeof((dst)) != 2) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync wrong_size(); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (dst) = lswaps((src)); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } while (0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT void SwapLongs(CARD32 *list, unsigned long count);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT void SwapShorts(short *list, unsigned long count);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT void MakePredeclaredAtoms(void);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int Ones(unsigned long /*mask */ );
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _xPoint *DDXPointPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct pixman_box16 *BoxPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _xEvent *xEventPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _xRectangle *xRectanglePtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _GrabRec *GrabPtr;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* typedefs from other places - duplicated here to minimize the amount
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * of unnecessary junk that one would normally have to include to get
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * these symbols defined
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef _XTYPEDEF_CHARINFOPTR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define _XTYPEDEF_CHARINFOPTR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT unsigned long globalSerialNumber;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT unsigned long serverGeneration;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define __BUG_WARN_MSG(cond, with_msg, ...) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync do { if (cond) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync ErrorFSigSafe("BUG: %s:%u in %s()\n", \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync __FILE__, __LINE__, __func__); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (with_msg) ErrorFSigSafe(__VA_ARGS__); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync xorg_backtrace(); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } } while(0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BUG_WARN_MSG(cond, ...) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync __BUG_WARN_MSG(cond, 1, __VA_ARGS__)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BUG_RETURN(cond) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BUG_RETURN_MSG(cond, ...) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BUG_RETURN_VAL(cond, val) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BUG_RETURN_VAL_MSG(cond, val, ...) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif /* MISC_H */