1 | /***********************************************************
|
---|
2 |
|
---|
3 | Copyright 1987, 1998 The Open Group
|
---|
4 |
|
---|
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.
|
---|
10 |
|
---|
11 | The above copyright notice and this permission notice shall be included in
|
---|
12 | all copies or substantial portions of the Software.
|
---|
13 |
|
---|
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.
|
---|
20 |
|
---|
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.
|
---|
24 |
|
---|
25 |
|
---|
26 | Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
---|
27 |
|
---|
28 | All Rights Reserved
|
---|
29 |
|
---|
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.
|
---|
37 |
|
---|
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.
|
---|
45 |
|
---|
46 | Copyright 1992, 1993 Data General Corporation;
|
---|
47 | Copyright 1992, 1993 OMRON Corporation
|
---|
48 |
|
---|
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.
|
---|
58 |
|
---|
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.
|
---|
66 |
|
---|
67 | ******************************************************************/
|
---|
68 | #ifndef MISC_H
|
---|
69 | #define MISC_H 1
|
---|
70 | /*
|
---|
71 | * X internal definitions
|
---|
72 | *
|
---|
73 | */
|
---|
74 |
|
---|
75 | #include <X11/Xosdefs.h>
|
---|
76 | #include <X11/Xfuncproto.h>
|
---|
77 | #include <X11/Xmd.h>
|
---|
78 | #include <X11/X.h>
|
---|
79 | #include <X11/Xdefs.h>
|
---|
80 |
|
---|
81 | #include <stddef.h>
|
---|
82 | #include <stdint.h>
|
---|
83 |
|
---|
84 | #ifndef MAXSCREENS
|
---|
85 | #define MAXSCREENS 16
|
---|
86 | #endif
|
---|
87 | #define MAXCLIENTS 256
|
---|
88 | #define MAXEXTENSIONS 128
|
---|
89 | #define MAXFORMATS 8
|
---|
90 | #define MAXDEVICES 40 /* input devices */
|
---|
91 |
|
---|
92 | #define EXTENSION_EVENT_BASE 64
|
---|
93 | #define EXTENSION_BASE 128
|
---|
94 |
|
---|
95 | typedef uint32_t ATOM;
|
---|
96 |
|
---|
97 | #ifndef TRUE
|
---|
98 | #define TRUE 1
|
---|
99 | #define FALSE 0
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | #ifndef _XTYPEDEF_CALLBACKLISTPTR
|
---|
103 | typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
|
---|
104 | #define _XTYPEDEF_CALLBACKLISTPTR
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | typedef struct _xReq *xReqPtr;
|
---|
108 |
|
---|
109 | #include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
|
---|
110 | #include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
|
---|
111 |
|
---|
112 | #define NullBox ((BoxPtr)0)
|
---|
113 | #define MILLI_PER_MIN (1000 * 60)
|
---|
114 | #define MILLI_PER_SECOND (1000)
|
---|
115 |
|
---|
116 | /* this next is used with None and ParentRelative to tell
|
---|
117 | PaintWin() what to use to paint the background. Also used
|
---|
118 | in the macro IS_VALID_PIXMAP */
|
---|
119 |
|
---|
120 | #define USE_BACKGROUND_PIXEL 3
|
---|
121 | #define USE_BORDER_PIXEL 3
|
---|
122 |
|
---|
123 |
|
---|
124 | /* byte swap a 32-bit literal */
|
---|
125 | #define lswapl(x) ((((x) & 0xff) << 24) |\
|
---|
126 | (((x) & 0xff00) << 8) |\
|
---|
127 | (((x) & 0xff0000) >> 8) |\
|
---|
128 | (((x) >> 24) & 0xff))
|
---|
129 |
|
---|
130 | /* byte swap a short literal */
|
---|
131 | #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
|
---|
132 |
|
---|
133 | #undef min
|
---|
134 | #undef max
|
---|
135 |
|
---|
136 | #define min(a, b) (((a) < (b)) ? (a) : (b))
|
---|
137 | #define max(a, b) (((a) > (b)) ? (a) : (b))
|
---|
138 | /* abs() is a function, not a macro; include the file declaring
|
---|
139 | * it in case we haven't done that yet.
|
---|
140 | */
|
---|
141 | #include <stdlib.h>
|
---|
142 | #ifndef Fabs
|
---|
143 | #define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
|
---|
144 | #endif
|
---|
145 | #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
|
---|
146 | /* this assumes b > 0 */
|
---|
147 | #define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
|
---|
148 | /*
|
---|
149 | * return the least significant bit in x which is set
|
---|
150 | *
|
---|
151 | * This works on 1's complement and 2's complement machines.
|
---|
152 | * If you care about the extra instruction on 2's complement
|
---|
153 | * machines, change to ((x) & (-(x)))
|
---|
154 | */
|
---|
155 | #define lowbit(x) ((x) & (~(x) + 1))
|
---|
156 |
|
---|
157 | /* XXX Not for modules */
|
---|
158 | #include <limits.h>
|
---|
159 | #if !defined(MAXSHORT) || !defined(MINSHORT) || \
|
---|
160 | !defined(MAXINT) || !defined(MININT)
|
---|
161 | /*
|
---|
162 | * Some implementations #define these through <math.h>, so preclude
|
---|
163 | * #include'ing it later.
|
---|
164 | */
|
---|
165 |
|
---|
166 | #include <math.h>
|
---|
167 | #undef MAXSHORT
|
---|
168 | #define MAXSHORT SHRT_MAX
|
---|
169 | #undef MINSHORT
|
---|
170 | #define MINSHORT SHRT_MIN
|
---|
171 | #undef MAXINT
|
---|
172 | #define MAXINT INT_MAX
|
---|
173 | #undef MININT
|
---|
174 | #define MININT INT_MIN
|
---|
175 |
|
---|
176 | #include <assert.h>
|
---|
177 | #include <ctype.h>
|
---|
178 | #include <stdio.h> /* for fopen, etc... */
|
---|
179 |
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | #ifndef PATH_MAX
|
---|
183 | #include <sys/param.h>
|
---|
184 | #ifndef PATH_MAX
|
---|
185 | #ifdef MAXPATHLEN
|
---|
186 | #define PATH_MAX MAXPATHLEN
|
---|
187 | #else
|
---|
188 | #define PATH_MAX 1024
|
---|
189 | #endif
|
---|
190 | #endif
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Calculate the number of bytes needed to hold bits.
|
---|
195 | * @param bits The minimum number of bits needed.
|
---|
196 | * @return The number of bytes needed to hold bits.
|
---|
197 | */
|
---|
198 | static inline int
|
---|
199 | bits_to_bytes(const int bits) {
|
---|
200 | return ((bits + 7) >> 3);
|
---|
201 | }
|
---|
202 | /**
|
---|
203 | * Calculate the number of 4-byte units needed to hold the given number of
|
---|
204 | * bytes.
|
---|
205 | * @param bytes The minimum number of bytes needed.
|
---|
206 | * @return The number of 4-byte units needed to hold bytes.
|
---|
207 | */
|
---|
208 | static inline int
|
---|
209 | bytes_to_int32(const int bytes) {
|
---|
210 | return (((bytes) + 3) >> 2);
|
---|
211 | }
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Calculate the number of bytes (in multiples of 4) needed to hold bytes.
|
---|
215 | * @param bytes The minimum number of bytes needed.
|
---|
216 | * @return The closest multiple of 4 that is equal or higher than bytes.
|
---|
217 | */
|
---|
218 | static inline int
|
---|
219 | pad_to_int32(const int bytes) {
|
---|
220 | return (((bytes) + 3) & ~3);
|
---|
221 | }
|
---|
222 |
|
---|
223 | extern char**
|
---|
224 | xstrtokenize(const char *str, const char* separators);
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Compare the two version numbers comprising of major.minor.
|
---|
228 | *
|
---|
229 | * @return A value less than 0 if a is less than b, 0 if a is equal to b,
|
---|
230 | * or a value greater than 0
|
---|
231 | */
|
---|
232 | static inline int
|
---|
233 | version_compare(uint16_t a_major, uint16_t a_minor,
|
---|
234 | uint16_t b_major, uint16_t b_minor)
|
---|
235 | {
|
---|
236 | int a, b;
|
---|
237 |
|
---|
238 | a = a_major << 16 | a_minor;
|
---|
239 | b = b_major << 16 | b_minor;
|
---|
240 |
|
---|
241 | return (a - b);
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* some macros to help swap requests, replies, and events */
|
---|
245 |
|
---|
246 | #define LengthRestB(stuff) \
|
---|
247 | ((client->req_len << 2) - sizeof(*stuff))
|
---|
248 |
|
---|
249 | #define LengthRestS(stuff) \
|
---|
250 | ((client->req_len << 1) - (sizeof(*stuff) >> 1))
|
---|
251 |
|
---|
252 | #define LengthRestL(stuff) \
|
---|
253 | (client->req_len - (sizeof(*stuff) >> 2))
|
---|
254 |
|
---|
255 | #define SwapRestS(stuff) \
|
---|
256 | SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
|
---|
257 |
|
---|
258 | #define SwapRestL(stuff) \
|
---|
259 | SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
|
---|
260 |
|
---|
261 | /* byte swap a 32-bit value */
|
---|
262 | #define swapl(x, n) { \
|
---|
263 | n = ((char *) (x))[0];\
|
---|
264 | ((char *) (x))[0] = ((char *) (x))[3];\
|
---|
265 | ((char *) (x))[3] = n;\
|
---|
266 | n = ((char *) (x))[1];\
|
---|
267 | ((char *) (x))[1] = ((char *) (x))[2];\
|
---|
268 | ((char *) (x))[2] = n; }
|
---|
269 |
|
---|
270 | /* byte swap a short */
|
---|
271 | #define swaps(x, n) { \
|
---|
272 | n = ((char *) (x))[0];\
|
---|
273 | ((char *) (x))[0] = ((char *) (x))[1];\
|
---|
274 | ((char *) (x))[1] = n; }
|
---|
275 |
|
---|
276 | /* copy 32-bit value from src to dst byteswapping on the way */
|
---|
277 | #define cpswapl(src, dst) { \
|
---|
278 | ((char *)&(dst))[0] = ((char *) &(src))[3];\
|
---|
279 | ((char *)&(dst))[1] = ((char *) &(src))[2];\
|
---|
280 | ((char *)&(dst))[2] = ((char *) &(src))[1];\
|
---|
281 | ((char *)&(dst))[3] = ((char *) &(src))[0]; }
|
---|
282 |
|
---|
283 | /* copy short from src to dst byteswapping on the way */
|
---|
284 | #define cpswaps(src, dst) { \
|
---|
285 | ((char *) &(dst))[0] = ((char *) &(src))[1];\
|
---|
286 | ((char *) &(dst))[1] = ((char *) &(src))[0]; }
|
---|
287 |
|
---|
288 | extern _X_EXPORT void SwapLongs(
|
---|
289 | CARD32 *list,
|
---|
290 | unsigned long count);
|
---|
291 |
|
---|
292 | extern _X_EXPORT void SwapShorts(
|
---|
293 | short *list,
|
---|
294 | unsigned long count);
|
---|
295 |
|
---|
296 | extern _X_EXPORT void MakePredeclaredAtoms(void);
|
---|
297 |
|
---|
298 | extern _X_EXPORT int Ones(
|
---|
299 | unsigned long /*mask*/);
|
---|
300 |
|
---|
301 | typedef struct _xPoint *DDXPointPtr;
|
---|
302 | typedef struct pixman_box16 *BoxPtr;
|
---|
303 | typedef struct _xEvent *xEventPtr;
|
---|
304 | typedef struct _xRectangle *xRectanglePtr;
|
---|
305 | typedef struct _GrabRec *GrabPtr;
|
---|
306 |
|
---|
307 | /* typedefs from other places - duplicated here to minimize the amount
|
---|
308 | * of unnecessary junk that one would normally have to include to get
|
---|
309 | * these symbols defined
|
---|
310 | */
|
---|
311 |
|
---|
312 | #ifndef _XTYPEDEF_CHARINFOPTR
|
---|
313 | typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
|
---|
314 | #define _XTYPEDEF_CHARINFOPTR
|
---|
315 | #endif
|
---|
316 |
|
---|
317 | extern _X_EXPORT unsigned long globalSerialNumber;
|
---|
318 | extern _X_EXPORT unsigned long serverGeneration;
|
---|
319 |
|
---|
320 | #endif /* MISC_H */
|
---|