1
/* $XFree86: xc/programs/Xserver/include/misc.h,v 3.28 2001/12/14 19:59:55 dawes Exp $ */
2
/***********************************************************
4
Copyright 1987, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
27
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Digital not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
Copyright 1992, 1993 Data General Corporation;
48
Copyright 1992, 1993 OMRON Corporation
50
Permission to use, copy, modify, distribute, and sell this software and its
51
documentation for any purpose is hereby granted without fee, provided that the
52
above copyright notice appear in all copies and that both that copyright
53
notice and this permission notice appear in supporting documentation, and that
54
neither the name OMRON or DATA GENERAL be used in advertising or publicity
55
pertaining to distribution of the software without specific, written prior
56
permission of the party whose name is to be used. Neither OMRON or
57
DATA GENERAL make any representation about the suitability of this software
58
for any purpose. It is provided "as is" without express or implied warranty.
60
OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
61
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
62
IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
63
OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
64
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
68
******************************************************************/
69
/* $Xorg: misc.h,v 1.5 2001/02/09 02:05:15 xorgcvs Exp $ */
73
* X internal definitions
77
extern unsigned long globalSerialNumber;
78
extern unsigned long serverGeneration;
80
#include <X11/Xosdefs.h>
81
#include <X11/Xfuncproto.h>
84
#include <X11/Xdefs.h>
95
#define MAXCLIENTS 256
97
#define MAXEXTENSIONS 128
99
#define MAXVISUALS_PER_SCREEN 50
101
typedef unsigned long PIXEL;
102
typedef unsigned long ATOM;
110
#ifndef _XTYPEDEF_CALLBACKLISTPTR
111
typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
112
#define _XTYPEDEF_CALLBACKLISTPTR
115
typedef struct _xReq *xReqPtr;
117
#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
119
#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
122
#define NullBox ((BoxPtr)0)
123
#define MILLI_PER_MIN (1000 * 60)
124
#define MILLI_PER_SECOND (1000)
126
/* this next is used with None and ParentRelative to tell
127
PaintWin() what to use to paint the background. Also used
128
in the macro IS_VALID_PIXMAP */
130
#define USE_BACKGROUND_PIXEL 3
131
#define USE_BORDER_PIXEL 3
134
/* byte swap a 32-bit literal */
135
#define lswapl(x) ((((x) & 0xff) << 24) |\
136
(((x) & 0xff00) << 8) |\
137
(((x) & 0xff0000) >> 8) |\
138
(((x) >> 24) & 0xff))
140
/* byte swap a short literal */
141
#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
146
#define min(a, b) (((a) < (b)) ? (a) : (b))
147
#define max(a, b) (((a) > (b)) ? (a) : (b))
149
/* abs() is a function, not a macro; include the file declaring
150
* it in case we haven't done that yet.
153
#endif /* IN_MODULE */
155
#define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
157
#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
158
/* this assumes b > 0 */
159
#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
161
* return the least significant bit in x which is set
163
* This works on 1's complement and 2's complement machines.
164
* If you care about the extra instruction on 2's complement
165
* machines, change to ((x) & (-(x)))
167
#define lowbit(x) ((x) & (~(x) + 1))
170
/* XXX Not for modules */
172
#if !defined(MAXSHORT) || !defined(MINSHORT) || \
173
!defined(MAXINT) || !defined(MININT)
175
* Some implementations #define these through <math.h>, so preclude
176
* #include'ing it later.
182
#define MAXSHORT SHRT_MAX
184
#define MINSHORT SHRT_MIN
186
#define MAXINT INT_MAX
188
#define MININT INT_MIN
192
#include <stdio.h> /* for fopen, etc... */
196
/* some macros to help swap requests, replies, and events */
198
#define LengthRestB(stuff) \
199
((client->req_len << 2) - sizeof(*stuff))
201
#define LengthRestS(stuff) \
202
((client->req_len << 1) - (sizeof(*stuff) >> 1))
204
#define LengthRestL(stuff) \
205
(client->req_len - (sizeof(*stuff) >> 2))
207
#define SwapRestS(stuff) \
208
SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
210
#define SwapRestL(stuff) \
211
SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
213
/* byte swap a 32-bit value */
214
#define swapl(x, n) { \
215
n = ((char *) (x))[0];\
216
((char *) (x))[0] = ((char *) (x))[3];\
217
((char *) (x))[3] = n;\
218
n = ((char *) (x))[1];\
219
((char *) (x))[1] = ((char *) (x))[2];\
220
((char *) (x))[2] = n; }
222
/* byte swap a short */
223
#define swaps(x, n) { \
224
n = ((char *) (x))[0];\
225
((char *) (x))[0] = ((char *) (x))[1];\
226
((char *) (x))[1] = n; }
228
/* copy 32-bit value from src to dst byteswapping on the way */
229
#define cpswapl(src, dst) { \
230
((char *)&(dst))[0] = ((char *) &(src))[3];\
231
((char *)&(dst))[1] = ((char *) &(src))[2];\
232
((char *)&(dst))[2] = ((char *) &(src))[1];\
233
((char *)&(dst))[3] = ((char *) &(src))[0]; }
235
/* copy short from src to dst byteswapping on the way */
236
#define cpswaps(src, dst) { \
237
((char *) &(dst))[0] = ((char *) &(src))[1];\
238
((char *) &(dst))[1] = ((char *) &(src))[0]; }
240
extern void SwapLongs(
241
#if NeedFunctionPrototypes
247
extern void SwapShorts(
248
#if NeedFunctionPrototypes
254
extern void MakePredeclaredAtoms(
255
#if NeedFunctionPrototypes
261
#if NeedFunctionPrototypes
262
unsigned long /*mask*/
266
typedef struct _xPoint *DDXPointPtr;
267
typedef struct _Box *BoxPtr;
268
typedef struct _xEvent *xEventPtr;
269
typedef struct _xRectangle *xRectanglePtr;
270
typedef struct _GrabRec *GrabPtr;
272
/* typedefs from other places - duplicated here to minimize the amount
273
* of unnecessary junk that one would normally have to include to get
274
* these symbols defined
277
#ifndef _XTYPEDEF_CHARINFOPTR
278
typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
279
#define _XTYPEDEF_CHARINFOPTR