1 /* $XConsortium: misc.h /main/7 1996/04/08 15:58:10 cde-fuj $ */
2 /***********************************************************
3 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
4 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
8 Permission to use, copy, modify, and distribute this software and its
9 documentation for any purpose and without fee is hereby granted,
10 provided that the above copyright notice appear in all copies and that
11 both that copyright notice and this permission notice appear in
12 supporting documentation, and that the names of Digital or MIT not be
13 used in advertising or publicity pertaining to distribution of the
14 software without specific, written prior permission.
16 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
18 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
19 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 (c) Copyright 1995 FUJITSU LIMITED
25 This is source code modified by FUJITSU LIMITED under the Joint
26 Development Agreement for the CDEnext PST.
27 This is unpublished proprietary source code of FUJITSU LIMITED
29 ******************************************************************/
33 * X internal definitions
38 extern unsigned long globalSerialNumber;
39 extern unsigned long serverGeneration;
42 #if __STDC__ && !NOSTDHDRS
54 #define MAXCLIENTS 128
56 #define MAXVISUALS_PER_SCREEN 50
58 typedef unsigned char *pointer;
60 typedef unsigned long PIXEL;
61 typedef unsigned long ATOM;
68 #include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
70 #define NullBox ((BoxPtr)0)
71 #define MILLI_PER_MIN (1000 * 60)
72 #define MILLI_PER_SECOND (1000)
74 /* this next is used with None and ParentRelative to tell
75 PaintWin() what to use to paint the background. Also used
76 in the macro IS_VALID_PIXMAP */
78 #define USE_BACKGROUND_PIXEL 3
79 #define USE_BORDER_PIXEL 3
82 /* byte swap a long literal */
83 #define lswapl(x) ((((x) & 0xff) << 24) |\
84 (((x) & 0xff00) << 8) |\
85 (((x) & 0xff0000) >> 8) |\
88 /* byte swap a short literal */
89 #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
91 #define min(a, b) (((a) < (b)) ? (a) : (b))
92 #define max(a, b) (((a) > (b)) ? (a) : (b))
94 #define abs(a) ((a) > 0 ? (a) : -(a))
97 #define fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
99 #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
100 /* this assumes b > 0 */
101 #define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
103 * return the least significant bit in x which is set
105 * This works on 1's complement and 2's complement machines.
106 * If you care about the extra instruction on 2's complement
107 * machines, change to ((x) & (-(x)))
109 #define lowbit(x) ((x) & (~(x) + 1))
111 #define MAXSHORT 32767
112 #define MINSHORT -MAXSHORT
115 /* some macros to help swap requests, replies, and events */
117 #define LengthRestB(stuff) \
118 (((unsigned long)stuff->length << 2) - sizeof(*stuff))
120 #define LengthRestS(stuff) \
121 (((unsigned long)stuff->length << 1) - (sizeof(*stuff) >> 1))
123 #define LengthRestL(stuff) \
124 ((unsigned long)stuff->length - (sizeof(*stuff) >> 2))
126 #define SwapRestS(stuff) \
127 SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
129 #define SwapRestL(stuff) \
130 SwapLongs((long *)(stuff + 1), LengthRestL(stuff))
132 /* byte swap a long */
133 #define swapl(x, n) n = ((char *) (x))[0];\
134 ((char *) (x))[0] = ((char *) (x))[3];\
135 ((char *) (x))[3] = n;\
136 n = ((char *) (x))[1];\
137 ((char *) (x))[1] = ((char *) (x))[2];\
138 ((char *) (x))[2] = n;
140 /* byte swap a short */
141 #define swaps(x, n) n = ((char *) (x))[0];\
142 ((char *) (x))[0] = ((char *) (x))[1];\
143 ((char *) (x))[1] = n
145 /* copy long from src to dst byteswapping on the way */
146 #define cpswapl(src, dst) \
147 ((char *)&(dst))[0] = ((char *) &(src))[3];\
148 ((char *)&(dst))[1] = ((char *) &(src))[2];\
149 ((char *)&(dst))[2] = ((char *) &(src))[1];\
150 ((char *)&(dst))[3] = ((char *) &(src))[0];
152 /* copy short from src to dst byteswapping on the way */
153 #define cpswaps(src, dst)\
154 ((char *) &(dst))[0] = ((char *) &(src))[1];\
155 ((char *) &(dst))[1] = ((char *) &(src))[0];
157 extern void SwapLongs();
158 extern void SwapShorts();
160 typedef struct _DDXPoint *DDXPointPtr;
161 typedef struct _Box *BoxPtr;