source: trunk/minix/commands/elle/eebit.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1/* ELLE - Copyright 1985, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
5 */
6/*
7 * EEBIT Bit Array functions
8 */
9#include "sb.h"
10
11/* Char-bit array functions. All assume that there are at least 8 bits
12 * in a byte, and that the number of bytes per word is a power of 2.
13 */
14/* CHBBITS represents log 2 of the # of bits stored per chbit-array word.
15 * WDBITS already has log2 of the # of bytes per word, and we are
16 * assuming each byte has at least 8 bits, so log2(8) = 3.
17 */
18#define CHBSIZE (WDSIZE*8) /* # bits per word */
19#define CHBBITS (WDBITS+3) /* log2(CHBSIZE) */
20#define CHBMASK (CHBSIZE-1)
21#define CHBARYSIZ (128/CHBSIZE) /* # words per ASCII array */
22
23/* CHBALLOC(size) - Allocates a char-bit array */
24int *
25chballoc(size)
26int size;
27{ return((int *)calloc((size + CHBSIZE-1)/CHBSIZE, (sizeof(int))));
28}
29
30/* CHBIT(array, char) - Tests bit in char-bit array
31 */
32chbit(array,c)
33register int *array, c;
34{ return(array[c >> CHBBITS] & (1 << (c & CHBMASK)));
35}
36/* CHBIS (array, char) - Sets bit in char-bit array
37 */
38chbis(array,c)
39register int *array, c;
40{ array[c >> CHBBITS] |= (1 << (c & CHBMASK));
41}
42/* CHBIC (array, char) - Clears bit in char-bit array
43 */
44chbic(array,c)
45register int *array, c;
46{ array[c >> CHBBITS] &= ~(1 << (c & CHBMASK));
47}
Note: See TracBrowser for help on using the repository browser.