Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtudcfonted / libfal / include / misc.h
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.
5
6                         All Rights Reserved
7
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.  
15
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
22 SOFTWARE.
23
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
28
29 ******************************************************************/
30 #ifndef MISC_H
31 #define MISC_H 1
32 /*
33  *  X internal definitions 
34  *
35  */
36
37
38 extern unsigned long globalSerialNumber;
39 extern unsigned long serverGeneration;
40
41 #ifndef NULL
42 #if __STDC__ && !NOSTDHDRS
43 #include <stddef.h>
44 #else
45 #define NULL            0
46 #endif
47 #endif
48
49 #ifdef __uxp__
50 #define MAXSCREENS      5
51 #else /* !__uxp__ */
52 #define MAXSCREENS      3
53 #endif /* !__uxp__ */
54 #define MAXCLIENTS      128
55 #define MAXFORMATS      8
56 #define MAXVISUALS_PER_SCREEN 50
57
58 typedef unsigned char *pointer;
59 typedef int Bool;
60 typedef unsigned long PIXEL;
61 typedef unsigned long ATOM;
62
63
64 #ifndef TRUE
65 #define TRUE 1
66 #define FALSE 0
67 #endif
68 #include "os.h"         /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
69
70 #define NullBox ((BoxPtr)0)
71 #define MILLI_PER_MIN (1000 * 60)
72 #define MILLI_PER_SECOND (1000)
73
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 */
77
78 #define USE_BACKGROUND_PIXEL 3
79 #define USE_BORDER_PIXEL 3
80
81
82 /* byte swap a long literal */
83 #define lswapl(x) ((((x) & 0xff) << 24) |\
84                    (((x) & 0xff00) << 8) |\
85                    (((x) & 0xff0000) >> 8) |\
86                    (((x) >> 24) & 0xff))
87
88 /* byte swap a short literal */
89 #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
90
91 #define min(a, b) (((a) < (b)) ? (a) : (b))
92 #define max(a, b) (((a) > (b)) ? (a) : (b))
93 #ifndef abs
94 #define abs(a) ((a) > 0 ? (a) : -(a))
95 #endif
96 #ifndef fabs
97 #define fabs(a) ((a) > 0.0 ? (a) : -(a))        /* floating absolute value */
98 #endif
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)
102 /*
103  * return the least significant bit in x which is set
104  *
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)))
108  */
109 #define lowbit(x) ((x) & (~(x) + 1))
110
111 #define MAXSHORT 32767
112 #define MINSHORT -MAXSHORT 
113
114
115 /* some macros to help swap requests, replies, and events */
116
117 #define LengthRestB(stuff) \
118     (((unsigned long)stuff->length << 2) - sizeof(*stuff))
119
120 #define LengthRestS(stuff) \
121     (((unsigned long)stuff->length << 1) - (sizeof(*stuff) >> 1))
122
123 #define LengthRestL(stuff) \
124     ((unsigned long)stuff->length - (sizeof(*stuff) >> 2))
125
126 #define SwapRestS(stuff) \
127     SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
128
129 #define SwapRestL(stuff) \
130     SwapLongs((long *)(stuff + 1), LengthRestL(stuff))
131
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;
139
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
144
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];
151
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];
156
157 extern void SwapLongs();
158 extern void SwapShorts();
159
160 typedef struct _DDXPoint *DDXPointPtr;
161 typedef struct _Box *BoxPtr;
162
163 #endif /* MISC_H */