misc.h revision 4642e01f
105b261ecSmrg/*********************************************************** 205b261ecSmrg 305b261ecSmrgCopyright 1987, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrg 2605b261ecSmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 2705b261ecSmrg 2805b261ecSmrg All Rights Reserved 2905b261ecSmrg 3005b261ecSmrgPermission to use, copy, modify, and distribute this software and its 3105b261ecSmrgdocumentation for any purpose and without fee is hereby granted, 3205b261ecSmrgprovided that the above copyright notice appear in all copies and that 3305b261ecSmrgboth that copyright notice and this permission notice appear in 3405b261ecSmrgsupporting documentation, and that the name of Digital not be 3505b261ecSmrgused in advertising or publicity pertaining to distribution of the 3605b261ecSmrgsoftware without specific, written prior permission. 3705b261ecSmrg 3805b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3905b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 4005b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4105b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4205b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4305b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4405b261ecSmrgSOFTWARE. 4505b261ecSmrg 4605b261ecSmrgCopyright 1992, 1993 Data General Corporation; 4705b261ecSmrgCopyright 1992, 1993 OMRON Corporation 4805b261ecSmrg 4905b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 5005b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that the 5105b261ecSmrgabove copyright notice appear in all copies and that both that copyright 5205b261ecSmrgnotice and this permission notice appear in supporting documentation, and that 5305b261ecSmrgneither the name OMRON or DATA GENERAL be used in advertising or publicity 5405b261ecSmrgpertaining to distribution of the software without specific, written prior 5505b261ecSmrgpermission of the party whose name is to be used. Neither OMRON or 5605b261ecSmrgDATA GENERAL make any representation about the suitability of this software 5705b261ecSmrgfor any purpose. It is provided "as is" without express or implied warranty. 5805b261ecSmrg 5905b261ecSmrgOMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 6005b261ecSmrgSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 6105b261ecSmrgIN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT 6205b261ecSmrgOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 6305b261ecSmrgDATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 6405b261ecSmrgTORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 6505b261ecSmrgOF THIS SOFTWARE. 6605b261ecSmrg 6705b261ecSmrg******************************************************************/ 6805b261ecSmrg#ifndef MISC_H 6905b261ecSmrg#define MISC_H 1 7005b261ecSmrg/* 7105b261ecSmrg * X internal definitions 7205b261ecSmrg * 7305b261ecSmrg */ 7405b261ecSmrg 7505b261ecSmrgextern unsigned long globalSerialNumber; 7605b261ecSmrgextern unsigned long serverGeneration; 7705b261ecSmrg 7805b261ecSmrg#include <X11/Xosdefs.h> 7905b261ecSmrg#include <X11/Xfuncproto.h> 8005b261ecSmrg#include <X11/Xmd.h> 8105b261ecSmrg#include <X11/X.h> 8205b261ecSmrg#include <X11/Xdefs.h> 8305b261ecSmrg 8405b261ecSmrg#include <stddef.h> 8505b261ecSmrg 8605b261ecSmrg#ifndef MAXSCREENS 8705b261ecSmrg#define MAXSCREENS 16 8805b261ecSmrg#endif 8905b261ecSmrg#define MAXCLIENTS 256 904642e01fSmrg#define MAXEXTENSIONS 128 9105b261ecSmrg#define MAXFORMATS 8 924642e01fSmrg#define MAXDEVICES 20 /* input devices */ 934642e01fSmrg 944642e01fSmrg#define EXTENSION_EVENT_BASE 64 954642e01fSmrg#define EXTENSION_BASE 128 9605b261ecSmrg 9705b261ecSmrgtypedef unsigned long PIXEL; 9805b261ecSmrgtypedef unsigned long ATOM; 9905b261ecSmrg 10005b261ecSmrg 10105b261ecSmrg#ifndef TRUE 10205b261ecSmrg#define TRUE 1 10305b261ecSmrg#define FALSE 0 10405b261ecSmrg#endif 10505b261ecSmrg 10605b261ecSmrg#ifndef _XTYPEDEF_CALLBACKLISTPTR 10705b261ecSmrgtypedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ 10805b261ecSmrg#define _XTYPEDEF_CALLBACKLISTPTR 10905b261ecSmrg#endif 11005b261ecSmrg 11105b261ecSmrgtypedef struct _xReq *xReqPtr; 11205b261ecSmrg 11305b261ecSmrg#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */ 11405b261ecSmrg#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */ 11505b261ecSmrg 11605b261ecSmrg#define NullBox ((BoxPtr)0) 11705b261ecSmrg#define MILLI_PER_MIN (1000 * 60) 11805b261ecSmrg#define MILLI_PER_SECOND (1000) 11905b261ecSmrg 12005b261ecSmrg /* this next is used with None and ParentRelative to tell 12105b261ecSmrg PaintWin() what to use to paint the background. Also used 12205b261ecSmrg in the macro IS_VALID_PIXMAP */ 12305b261ecSmrg 12405b261ecSmrg#define USE_BACKGROUND_PIXEL 3 12505b261ecSmrg#define USE_BORDER_PIXEL 3 12605b261ecSmrg 12705b261ecSmrg 12805b261ecSmrg/* byte swap a 32-bit literal */ 12905b261ecSmrg#define lswapl(x) ((((x) & 0xff) << 24) |\ 13005b261ecSmrg (((x) & 0xff00) << 8) |\ 13105b261ecSmrg (((x) & 0xff0000) >> 8) |\ 13205b261ecSmrg (((x) >> 24) & 0xff)) 13305b261ecSmrg 13405b261ecSmrg/* byte swap a short literal */ 13505b261ecSmrg#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)) 13605b261ecSmrg 13705b261ecSmrg#undef min 13805b261ecSmrg#undef max 13905b261ecSmrg 14005b261ecSmrg#define min(a, b) (((a) < (b)) ? (a) : (b)) 14105b261ecSmrg#define max(a, b) (((a) > (b)) ? (a) : (b)) 14205b261ecSmrg/* abs() is a function, not a macro; include the file declaring 14305b261ecSmrg * it in case we haven't done that yet. 14405b261ecSmrg */ 14505b261ecSmrg#include <stdlib.h> 14605b261ecSmrg#ifndef Fabs 14705b261ecSmrg#define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */ 14805b261ecSmrg#endif 14905b261ecSmrg#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) 15005b261ecSmrg/* this assumes b > 0 */ 15105b261ecSmrg#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b) 15205b261ecSmrg/* 15305b261ecSmrg * return the least significant bit in x which is set 15405b261ecSmrg * 15505b261ecSmrg * This works on 1's complement and 2's complement machines. 15605b261ecSmrg * If you care about the extra instruction on 2's complement 15705b261ecSmrg * machines, change to ((x) & (-(x))) 15805b261ecSmrg */ 15905b261ecSmrg#define lowbit(x) ((x) & (~(x) + 1)) 16005b261ecSmrg 16105b261ecSmrg/* XXX Not for modules */ 16205b261ecSmrg#include <limits.h> 16305b261ecSmrg#if !defined(MAXSHORT) || !defined(MINSHORT) || \ 16405b261ecSmrg !defined(MAXINT) || !defined(MININT) 16505b261ecSmrg/* 16605b261ecSmrg * Some implementations #define these through <math.h>, so preclude 16705b261ecSmrg * #include'ing it later. 16805b261ecSmrg */ 16905b261ecSmrg 17005b261ecSmrg#include <math.h> 17105b261ecSmrg#undef MAXSHORT 17205b261ecSmrg#define MAXSHORT SHRT_MAX 17305b261ecSmrg#undef MINSHORT 17405b261ecSmrg#define MINSHORT SHRT_MIN 17505b261ecSmrg#undef MAXINT 17605b261ecSmrg#define MAXINT INT_MAX 17705b261ecSmrg#undef MININT 17805b261ecSmrg#define MININT INT_MIN 17905b261ecSmrg 18005b261ecSmrg#include <assert.h> 18105b261ecSmrg#include <ctype.h> 18205b261ecSmrg#include <stdio.h> /* for fopen, etc... */ 18305b261ecSmrg 18405b261ecSmrg#endif 18505b261ecSmrg 18605b261ecSmrg/* some macros to help swap requests, replies, and events */ 18705b261ecSmrg 18805b261ecSmrg#define LengthRestB(stuff) \ 18905b261ecSmrg ((client->req_len << 2) - sizeof(*stuff)) 19005b261ecSmrg 19105b261ecSmrg#define LengthRestS(stuff) \ 19205b261ecSmrg ((client->req_len << 1) - (sizeof(*stuff) >> 1)) 19305b261ecSmrg 19405b261ecSmrg#define LengthRestL(stuff) \ 19505b261ecSmrg (client->req_len - (sizeof(*stuff) >> 2)) 19605b261ecSmrg 19705b261ecSmrg#define SwapRestS(stuff) \ 19805b261ecSmrg SwapShorts((short *)(stuff + 1), LengthRestS(stuff)) 19905b261ecSmrg 20005b261ecSmrg#define SwapRestL(stuff) \ 20105b261ecSmrg SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff)) 20205b261ecSmrg 20305b261ecSmrg/* byte swap a 32-bit value */ 20405b261ecSmrg#define swapl(x, n) { \ 20505b261ecSmrg n = ((char *) (x))[0];\ 20605b261ecSmrg ((char *) (x))[0] = ((char *) (x))[3];\ 20705b261ecSmrg ((char *) (x))[3] = n;\ 20805b261ecSmrg n = ((char *) (x))[1];\ 20905b261ecSmrg ((char *) (x))[1] = ((char *) (x))[2];\ 21005b261ecSmrg ((char *) (x))[2] = n; } 21105b261ecSmrg 21205b261ecSmrg/* byte swap a short */ 21305b261ecSmrg#define swaps(x, n) { \ 21405b261ecSmrg n = ((char *) (x))[0];\ 21505b261ecSmrg ((char *) (x))[0] = ((char *) (x))[1];\ 21605b261ecSmrg ((char *) (x))[1] = n; } 21705b261ecSmrg 21805b261ecSmrg/* copy 32-bit value from src to dst byteswapping on the way */ 21905b261ecSmrg#define cpswapl(src, dst) { \ 22005b261ecSmrg ((char *)&(dst))[0] = ((char *) &(src))[3];\ 22105b261ecSmrg ((char *)&(dst))[1] = ((char *) &(src))[2];\ 22205b261ecSmrg ((char *)&(dst))[2] = ((char *) &(src))[1];\ 22305b261ecSmrg ((char *)&(dst))[3] = ((char *) &(src))[0]; } 22405b261ecSmrg 22505b261ecSmrg/* copy short from src to dst byteswapping on the way */ 22605b261ecSmrg#define cpswaps(src, dst) { \ 22705b261ecSmrg ((char *) &(dst))[0] = ((char *) &(src))[1];\ 22805b261ecSmrg ((char *) &(dst))[1] = ((char *) &(src))[0]; } 22905b261ecSmrg 23005b261ecSmrgextern void SwapLongs( 23105b261ecSmrg CARD32 *list, 23205b261ecSmrg unsigned long count); 23305b261ecSmrg 23405b261ecSmrgextern void SwapShorts( 23505b261ecSmrg short *list, 23605b261ecSmrg unsigned long count); 23705b261ecSmrg 23805b261ecSmrgextern void MakePredeclaredAtoms(void); 23905b261ecSmrg 24005b261ecSmrgextern int Ones( 24105b261ecSmrg unsigned long /*mask*/); 24205b261ecSmrg 24305b261ecSmrgtypedef struct _xPoint *DDXPointPtr; 24405b261ecSmrgtypedef struct pixman_box16 *BoxPtr; 24505b261ecSmrgtypedef struct _xEvent *xEventPtr; 24605b261ecSmrgtypedef struct _xRectangle *xRectanglePtr; 24705b261ecSmrgtypedef struct _GrabRec *GrabPtr; 24805b261ecSmrg 24905b261ecSmrg/* typedefs from other places - duplicated here to minimize the amount 25005b261ecSmrg * of unnecessary junk that one would normally have to include to get 25105b261ecSmrg * these symbols defined 25205b261ecSmrg */ 25305b261ecSmrg 25405b261ecSmrg#ifndef _XTYPEDEF_CHARINFOPTR 25505b261ecSmrgtypedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */ 25605b261ecSmrg#define _XTYPEDEF_CHARINFOPTR 25705b261ecSmrg#endif 25805b261ecSmrg 25905b261ecSmrg#endif /* MISC_H */ 260