First import
[xorg_rtime.git] / xorg-server-1.4 / include / misc.h
blobe6a5e9eb2c9534b56cb92ec15356edfdc3c8c03d
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 Copyright 1992, 1993 Data General Corporation;
47 Copyright 1992, 1993 OMRON Corporation
49 Permission to use, copy, modify, distribute, and sell this software and its
50 documentation for any purpose is hereby granted without fee, provided that the
51 above copyright notice appear in all copies and that both that copyright
52 notice and this permission notice appear in supporting documentation, and that
53 neither the name OMRON or DATA GENERAL be used in advertising or publicity
54 pertaining to distribution of the software without specific, written prior
55 permission of the party whose name is to be used. Neither OMRON or
56 DATA GENERAL make any representation about the suitability of this software
57 for any purpose. It is provided "as is" without express or implied warranty.
59 OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
60 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
61 IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
62 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
63 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
64 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
65 OF THIS SOFTWARE.
67 ******************************************************************/
68 #ifndef MISC_H
69 #define MISC_H 1
71 * X internal definitions
75 extern unsigned long globalSerialNumber;
76 extern unsigned long serverGeneration;
78 #include <X11/Xosdefs.h>
79 #include <X11/Xfuncproto.h>
80 #include <X11/Xmd.h>
81 #include <X11/X.h>
82 #include <X11/Xdefs.h>
84 #include <stddef.h>
86 #ifndef MAXSCREENS
87 #define MAXSCREENS 16
88 #endif
89 #define MAXCLIENTS 256
90 #define MAXDITS 1
91 #define MAXEXTENSIONS 128
92 #define MAXFORMATS 8
93 #define MAXVISUALS_PER_SCREEN 50
95 typedef unsigned long PIXEL;
96 typedef unsigned long ATOM;
99 #ifndef TRUE
100 #define TRUE 1
101 #define FALSE 0
102 #endif
104 #ifndef _XTYPEDEF_CALLBACKLISTPTR
105 typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
106 #define _XTYPEDEF_CALLBACKLISTPTR
107 #endif
109 typedef struct _xReq *xReqPtr;
111 #include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
112 #include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
114 #define NullBox ((BoxPtr)0)
115 #define MILLI_PER_MIN (1000 * 60)
116 #define MILLI_PER_SECOND (1000)
118 /* this next is used with None and ParentRelative to tell
119 PaintWin() what to use to paint the background. Also used
120 in the macro IS_VALID_PIXMAP */
122 #define USE_BACKGROUND_PIXEL 3
123 #define USE_BORDER_PIXEL 3
126 /* byte swap a 32-bit literal */
127 #define lswapl(x) ((((x) & 0xff) << 24) |\
128 (((x) & 0xff00) << 8) |\
129 (((x) & 0xff0000) >> 8) |\
130 (((x) >> 24) & 0xff))
132 /* byte swap a short literal */
133 #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
135 #undef min
136 #undef max
138 #define min(a, b) (((a) < (b)) ? (a) : (b))
139 #define max(a, b) (((a) > (b)) ? (a) : (b))
140 /* abs() is a function, not a macro; include the file declaring
141 * it in case we haven't done that yet.
143 #include <stdlib.h>
144 #ifndef Fabs
145 #define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
146 #endif
147 #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
148 /* this assumes b > 0 */
149 #define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
151 * return the least significant bit in x which is set
153 * This works on 1's complement and 2's complement machines.
154 * If you care about the extra instruction on 2's complement
155 * machines, change to ((x) & (-(x)))
157 #define lowbit(x) ((x) & (~(x) + 1))
159 /* XXX Not for modules */
160 #include <limits.h>
161 #if !defined(MAXSHORT) || !defined(MINSHORT) || \
162 !defined(MAXINT) || !defined(MININT)
164 * Some implementations #define these through <math.h>, so preclude
165 * #include'ing it later.
168 #include <math.h>
169 #undef MAXSHORT
170 #define MAXSHORT SHRT_MAX
171 #undef MINSHORT
172 #define MINSHORT SHRT_MIN
173 #undef MAXINT
174 #define MAXINT INT_MAX
175 #undef MININT
176 #define MININT INT_MIN
178 #include <assert.h>
179 #include <ctype.h>
180 #include <stdio.h> /* for fopen, etc... */
182 #endif
184 /* some macros to help swap requests, replies, and events */
186 #define LengthRestB(stuff) \
187 ((client->req_len << 2) - sizeof(*stuff))
189 #define LengthRestS(stuff) \
190 ((client->req_len << 1) - (sizeof(*stuff) >> 1))
192 #define LengthRestL(stuff) \
193 (client->req_len - (sizeof(*stuff) >> 2))
195 #define SwapRestS(stuff) \
196 SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
198 #define SwapRestL(stuff) \
199 SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
201 /* byte swap a 32-bit value */
202 #define swapl(x, n) { \
203 n = ((char *) (x))[0];\
204 ((char *) (x))[0] = ((char *) (x))[3];\
205 ((char *) (x))[3] = n;\
206 n = ((char *) (x))[1];\
207 ((char *) (x))[1] = ((char *) (x))[2];\
208 ((char *) (x))[2] = n; }
210 /* byte swap a short */
211 #define swaps(x, n) { \
212 n = ((char *) (x))[0];\
213 ((char *) (x))[0] = ((char *) (x))[1];\
214 ((char *) (x))[1] = n; }
216 /* copy 32-bit value from src to dst byteswapping on the way */
217 #define cpswapl(src, dst) { \
218 ((char *)&(dst))[0] = ((char *) &(src))[3];\
219 ((char *)&(dst))[1] = ((char *) &(src))[2];\
220 ((char *)&(dst))[2] = ((char *) &(src))[1];\
221 ((char *)&(dst))[3] = ((char *) &(src))[0]; }
223 /* copy short from src to dst byteswapping on the way */
224 #define cpswaps(src, dst) { \
225 ((char *) &(dst))[0] = ((char *) &(src))[1];\
226 ((char *) &(dst))[1] = ((char *) &(src))[0]; }
228 extern void SwapLongs(
229 CARD32 *list,
230 unsigned long count);
232 extern void SwapShorts(
233 short *list,
234 unsigned long count);
236 extern void MakePredeclaredAtoms(void);
238 extern int Ones(
239 unsigned long /*mask*/);
241 typedef struct _xPoint *DDXPointPtr;
242 typedef struct pixman_box16 *BoxPtr;
243 typedef struct _xEvent *xEventPtr;
244 typedef struct _xRectangle *xRectanglePtr;
245 typedef struct _GrabRec *GrabPtr;
247 /* typedefs from other places - duplicated here to minimize the amount
248 * of unnecessary junk that one would normally have to include to get
249 * these symbols defined
252 #ifndef _XTYPEDEF_CHARINFOPTR
253 typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
254 #define _XTYPEDEF_CHARINFOPTR
255 #endif
257 #endif /* MISC_H */