Git init
[pkgs/xorg/proto/x11proto-trap.git] / xtrapbits.h
1 /* $XFree86$ */
2 /*
3  * This include file is designed to be a portable way for systems to define
4  * bit field manipulation of arrays of bits.
5  */
6 #ifndef __XTRAPBITS__
7 #define __XTRAPBITS__ "@(#)xtrapbits.h  1.6 - 90/09/18  "
8
9 /*****************************************************************************
10 Copyright 1987, 1988, 1989, 1990, 1994 by Digital Equipment Corporation, 
11 Maynard, MA
12
13 Permission to use, copy, modify, and distribute this software and its 
14 documentation for any purpose and without fee is hereby granted, 
15 provided that the above copyright notice appear in all copies and that
16 both that copyright notice and this permission notice appear in 
17 supporting documentation, and that the name of Digital not be
18 used in advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.  
20
21 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
22 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
23 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
24 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
25 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
27 SOFTWARE.
28
29 *****************************************************************************/
30 /*
31  *
32  *  CONTRIBUTORS:
33  *
34  *      Dick Annicchiarico
35  *      Robert Chesler
36  *      Dan Coutu
37  *      Gene Durso
38  *      Marc Evans
39  *      Alan Jamison
40  *      Mark Henry
41  *      Ken Miller
42  *
43  */
44 typedef unsigned char *UByteP;  /* Pointer to an unsigned byte array */
45 #define BitsInByte    8L        /* The number of bits in a byte */
46
47 #define BitInByte(bit)          /* Returns the bit mask of a byte */ \
48     (1L << (((bit) % BitsInByte)))
49
50 #define BitInWord(bit)          /* Returns the bit mask of a word */ \
51     (1L << (((bit) % (BitsInByte * 2L))))
52
53 #define BitInLong(bit)          /* Returns the bit mask of a long */ \
54     (1L << (((bit) % (BitsInByte * 4L))))
55
56 #define ByteInArray(array,bit)  /* Returns the byte offset to get to a bit */ \
57     (((UByteP)(array))[(bit) / BitsInByte])
58
59 #define BitIsTrue(array,bit)    /* Test to see if a specific bit is True */ \
60     (ByteInArray(array,bit) & BitInByte(bit))
61
62 #define BitIsFalse(array,bit)   /* Test to see if a specific bit is False */ \
63     (!(BitIsTrue(array,bit)))
64
65 #define BitTrue(array,bit)      /* Set a specific bit to be True */ \
66     (ByteInArray(array,bit) |= BitInByte(bit))
67
68 #define BitFalse(array,bit)     /* Set a specific bit to be False */ \
69     (ByteInArray(array,bit) &= ~BitInByte(bit))
70
71 #define BitToggle(array,bit)    /* Toggle a specific bit */ \
72     (ByteInArray(array,bit) ^= BitInByte(bit))
73
74 #define BitCopy(dest,src,bit)   /* Copy a specific bit */ \
75     BitIsTrue((src),(bit)) ? BitTrue((dest),(bit)) : BitFalse((dest),(bit))
76
77 #define BitValue(array,bit)     /* Return True or False depending on bit */ \
78     (BitIsTrue((array),(bit)) ? True : False)
79
80 #define BitSet(array,bit,value) /* Set bit to given value in array */ \
81     (value) ? BitTrue((array),(bit)) : BitFalse((array),(bit))
82
83 #endif /* __XTRAPBITS__ */