Use py_resource module
[python/dscho.git] / Parser / bitset.c
blobdd32d0e111ebdcfd9066827c8b252c4ef117ac85
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
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 Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Bitset primitives used by the parser generator */
27 #include "pgenheaders.h"
28 #include "bitset.h"
30 bitset
31 newbitset(nbits)
32 int nbits;
34 int nbytes = NBYTES(nbits);
35 bitset ss = NEW(BYTE, nbytes);
37 if (ss == NULL)
38 fatal("no mem for bitset");
40 ss += nbytes;
41 while (--nbytes >= 0)
42 *--ss = 0;
43 return ss;
46 void
47 delbitset(ss)
48 bitset ss;
50 DEL(ss);
53 int
54 addbit(ss, ibit)
55 bitset ss;
56 int ibit;
58 int ibyte = BIT2BYTE(ibit);
59 BYTE mask = BIT2MASK(ibit);
61 if (ss[ibyte] & mask)
62 return 0; /* Bit already set */
63 ss[ibyte] |= mask;
64 return 1;
67 #if 0 /* Now a macro */
68 int
69 testbit(ss, ibit)
70 bitset ss;
71 int ibit;
73 return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
75 #endif
77 int
78 samebitset(ss1, ss2, nbits)
79 bitset ss1, ss2;
80 int nbits;
82 int i;
84 for (i = NBYTES(nbits); --i >= 0; )
85 if (*ss1++ != *ss2++)
86 return 0;
87 return 1;
90 void
91 mergebitset(ss1, ss2, nbits)
92 bitset ss1, ss2;
93 int nbits;
95 int i;
97 for (i = NBYTES(nbits); --i >= 0; )
98 *ss1++ |= *ss2++;