OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
misc.h
Go to the documentation of this file.
1 /***********************************************************
2 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
3 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
4 
5  All Rights Reserved
6 
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Digital or MIT not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
14 
15 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21 SOFTWARE.
22 
23  ******************************************************************/
24 /* $XConsortium: misc.h,v 1.58 91/04/10 08:53:39 rws Exp $ */
25 #ifndef MISC_H
26 #define MISC_H 1
27 
28 #include <stdint.h>
29 
30 /*
31  * X internal definitions
32  *
33  */
34 
35 
36 extern uint32_t globalSerialNumber;
37 extern uint32_t serverGeneration;
38 
39 #include "Xosdefs.h"
40 
41 #ifndef NULL
42 #ifndef X_NOT_STDC_ENV
43 #include <stddef.h>
44 #else
45 #define NULL 0
46 #endif
47 #endif
48 
49 #define MAXSCREENS 3
50 #define MAXCLIENTS 128
51 #define MAXFORMATS 8
52 #define MAXVISUALS_PER_SCREEN 50
53 
54 typedef unsigned char *pointer;
55 typedef int Bool;
56 typedef uint32_t PIXEL;
57 typedef uint32_t ATOM;
58 
59 
60 #ifndef TRUE
61 #define TRUE 1
62 #define FALSE 0
63 #endif
64 #include "Xfuncs.h" /* for bcopy, bzero, and bcmp */
65 
66 #define NullBox ((BoxPtr)0)
67 #define MILLI_PER_MIN (1000 * 60)
68 #define MILLI_PER_SECOND (1000)
69 
70 /* this next is used with None and ParentRelative to tell
71  PaintWin() what to use to paint the background. Also used
72  in the macro IS_VALID_PIXMAP */
73 
74 #define USE_BACKGROUND_PIXEL 3
75 #define USE_BORDER_PIXEL 3
76 
77 
78 /* byte swap a int32_t literal */
79 #define lswapl(x) ((((x) & 0xff) << 24) |\
80  (((x) & 0xff00) << 8) |\
81  (((x) & 0xff0000) >> 8) |\
82  (((x) >> 24) & 0xff))
83 
84 /* byte swap a short literal */
85 #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
86 
87 #define min(a, b) (((a) < (b)) ? (a) : (b))
88 #define max(a, b) (((a) > (b)) ? (a) : (b))
89 #ifndef abs
90 #define abs(a) ((a) > 0 ? (a) : -(a))
91 #endif
92 #ifndef fabs
93 #define fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
94 #endif
95 #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
96 /* this assumes b > 0 */
97 #define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
98 /*
99  * return the least significant bit in x which is set
100  *
101  * This works on 1's complement and 2's complement machines.
102  * If you care about the extra instruction on 2's complement
103  * machines, change to ((x) & (-(x)))
104  */
105 #define lowbit(x) ((x) & (~(x) + 1))
106 
107 #define MAXSHORT 32767
108 #define MINSHORT -MAXSHORT
109 
110 
111 /* some macros to help swap requests, replies, and events */
112 
113 #define LengthRestB(stuff) \
114  (((uint32_t)stuff->length << 2) - sizeof(*stuff))
115 
116 #define LengthRestS(stuff) \
117  (((uint32_t)stuff->length << 1) - (sizeof(*stuff) >> 1))
118 
119 #define LengthRestL(stuff) \
120  ((uint32_t)stuff->length - (sizeof(*stuff) >> 2))
121 
122 #define SwapRestS(stuff) \
123  SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
124 
125 #define SwapRestL(stuff) \
126  SwapLongs((int32_t *)(stuff + 1), LengthRestL(stuff))
127 
128 /* byte swap a int32_t */
129 #define swapl(x, n) n = ((char *) (x))[0];\
130  ((char *) (x))[0] = ((char *) (x))[3];\
131  ((char *) (x))[3] = n;\
132  n = ((char *) (x))[1];\
133  ((char *) (x))[1] = ((char *) (x))[2];\
134  ((char *) (x))[2] = n;
135 
136 /* byte swap a short */
137 #define swaps(x, n) n = ((char *) (x))[0];\
138  ((char *) (x))[0] = ((char *) (x))[1];\
139  ((char *) (x))[1] = n
140 
141 /* copy int32_t from src to dst byteswapping on the way */
142 #define cpswapl(src, dst) \
143  ((char *)&(dst))[0] = ((char *) &(src))[3];\
144  ((char *)&(dst))[1] = ((char *) &(src))[2];\
145  ((char *)&(dst))[2] = ((char *) &(src))[1];\
146  ((char *)&(dst))[3] = ((char *) &(src))[0];
147 
148 /* copy short from src to dst byteswapping on the way */
149 #define cpswaps(src, dst)\
150  ((char *) &(dst))[0] = ((char *) &(src))[1];\
151  ((char *) &(dst))[1] = ((char *) &(src))[0];
152 
153 extern void SwapLongs();
154 extern void SwapShorts();
155 
156 typedef struct _DDXPoint *DDXPointPtr;
157 typedef struct _Box *BoxPtr;
158 
159 #endif /* MISC_H */
unsigned char * pointer
Definition: misc.h:54
uint32_t PIXEL
Definition: misc.h:56
uint32_t ATOM
Definition: misc.h:57
void SwapShorts()
uint32_t serverGeneration
int Bool
Definition: misc.h:55
void SwapLongs()
uint32_t globalSerialNumber