117ca54c3Smrg/* $XFree86$ */
217ca54c3Smrg/*
317ca54c3Smrg * This include file is designed to be a portable way for systems to define
417ca54c3Smrg * bit field manipulation of arrays of bits.
517ca54c3Smrg */
617ca54c3Smrg#ifndef __XTRAPBITS__
717ca54c3Smrg#define __XTRAPBITS__ "@(#)xtrapbits.h	1.6 - 90/09/18  "
817ca54c3Smrg
917ca54c3Smrg/*****************************************************************************
10ea1d6981SmrgCopyright 1987, 1988, 1989, 1990, 1994 by Digital Equipment Corporation,
1117ca54c3SmrgMaynard, MA
1217ca54c3Smrg
13ea1d6981SmrgPermission to use, copy, modify, and distribute this software and its
14ea1d6981Smrgdocumentation for any purpose and without fee is hereby granted,
1517ca54c3Smrgprovided that the above copyright notice appear in all copies and that
16ea1d6981Smrgboth that copyright notice and this permission notice appear in
1717ca54c3Smrgsupporting documentation, and that the name of Digital not be
1817ca54c3Smrgused in advertising or publicity pertaining to distribution of the
19ea1d6981Smrgsoftware without specific, written prior permission.
2017ca54c3Smrg
2117ca54c3SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
2217ca54c3SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
2317ca54c3SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
2417ca54c3SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
2517ca54c3SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
2617ca54c3SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2717ca54c3SmrgSOFTWARE.
2817ca54c3Smrg
2917ca54c3Smrg*****************************************************************************/
3017ca54c3Smrg/*
3117ca54c3Smrg *
3217ca54c3Smrg *  CONTRIBUTORS:
3317ca54c3Smrg *
3417ca54c3Smrg *      Dick Annicchiarico
3517ca54c3Smrg *      Robert Chesler
3617ca54c3Smrg *      Dan Coutu
3717ca54c3Smrg *      Gene Durso
3817ca54c3Smrg *      Marc Evans
3917ca54c3Smrg *      Alan Jamison
4017ca54c3Smrg *      Mark Henry
4117ca54c3Smrg *      Ken Miller
4217ca54c3Smrg *
4317ca54c3Smrg */
4417ca54c3Smrgtypedef unsigned char *UByteP;  /* Pointer to an unsigned byte array */
4517ca54c3Smrg#define BitsInByte    8L        /* The number of bits in a byte */
4617ca54c3Smrg
4717ca54c3Smrg#define BitInByte(bit)	        /* Returns the bit mask of a byte */ \
4817ca54c3Smrg    (1L << (((bit) % BitsInByte)))
4917ca54c3Smrg
5017ca54c3Smrg#define BitInWord(bit)	        /* Returns the bit mask of a word */ \
5117ca54c3Smrg    (1L << (((bit) % (BitsInByte * 2L))))
5217ca54c3Smrg
5317ca54c3Smrg#define BitInLong(bit)	        /* Returns the bit mask of a long */ \
5417ca54c3Smrg    (1L << (((bit) % (BitsInByte * 4L))))
5517ca54c3Smrg
5617ca54c3Smrg#define ByteInArray(array,bit)	/* Returns the byte offset to get to a bit */ \
5717ca54c3Smrg    (((UByteP)(array))[(bit) / BitsInByte])
5817ca54c3Smrg
5917ca54c3Smrg#define BitIsTrue(array,bit)    /* Test to see if a specific bit is True */ \
6017ca54c3Smrg    (ByteInArray(array,bit) & BitInByte(bit))
6117ca54c3Smrg
6217ca54c3Smrg#define BitIsFalse(array,bit)   /* Test to see if a specific bit is False */ \
6317ca54c3Smrg    (!(BitIsTrue(array,bit)))
6417ca54c3Smrg
6517ca54c3Smrg#define BitTrue(array,bit)      /* Set a specific bit to be True */ \
6617ca54c3Smrg    (ByteInArray(array,bit) |= BitInByte(bit))
6717ca54c3Smrg
6817ca54c3Smrg#define BitFalse(array,bit)     /* Set a specific bit to be False */ \
6917ca54c3Smrg    (ByteInArray(array,bit) &= ~BitInByte(bit))
7017ca54c3Smrg
7117ca54c3Smrg#define BitToggle(array,bit)    /* Toggle a specific bit */ \
7217ca54c3Smrg    (ByteInArray(array,bit) ^= BitInByte(bit))
7317ca54c3Smrg
7417ca54c3Smrg#define BitCopy(dest,src,bit)   /* Copy a specific bit */ \
7517ca54c3Smrg    BitIsTrue((src),(bit)) ? BitTrue((dest),(bit)) : BitFalse((dest),(bit))
7617ca54c3Smrg
7717ca54c3Smrg#define BitValue(array,bit)     /* Return True or False depending on bit */ \
7817ca54c3Smrg    (BitIsTrue((array),(bit)) ? True : False)
7917ca54c3Smrg
8017ca54c3Smrg#define BitSet(array,bit,value) /* Set bit to given value in array */ \
8117ca54c3Smrg    (value) ? BitTrue((array),(bit)) : BitFalse((array),(bit))
8217ca54c3Smrg
8317ca54c3Smrg#endif /* __XTRAPBITS__ */
84