|
|
1.1 ! root 1: .\" Copyright (c) 1989 The Regents of the University of California. ! 2: .\" All rights reserved. ! 3: .\" ! 4: .\" This code is derived from software contributed to Berkeley by ! 5: .\" Paul Vixie. ! 6: .\" ! 7: .\" Redistribution and use in source and binary forms are permitted provided ! 8: .\" that: (1) source distributions retain this entire copyright notice and ! 9: .\" comment, and (2) distributions including binaries display the following ! 10: .\" acknowledgement: ``This product includes software developed by the ! 11: .\" University of California, Berkeley and its contributors'' in the ! 12: .\" documentation or other materials provided with the distribution and in ! 13: .\" all advertising materials mentioning features or use of this software. ! 14: .\" Neither the name of the University nor the names of its contributors may ! 15: .\" be used to endorse or promote products derived from this software without ! 16: .\" specific prior written permission. ! 17: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 18: .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 19: .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 20: .\" ! 21: .\" @(#)bitstring.3 5.3 (Berkeley) 6/23/90 ! 22: .\" ! 23: .TH BITSTRING 3 "June 23, 1990" ! 24: .UC 4 ! 25: .SH NAME ! 26: bit_alloc, bit_clear, bit_decl, bit_ffs, bit_nclear, bit_nset, ! 27: bit_set, bitstr_size, bit_test \- bit-string manipulation macros ! 28: .SH SYNOPSIS ! 29: .ft B ! 30: .nf ! 31: #include <bitstring.h> ! 32: ! 33: name = bit_alloc(nbits) ! 34: bitstr_t *name; ! 35: int nbits; ! 36: ! 37: bit_decl(name, nbits) ! 38: bitstr_t name; ! 39: int nbits; ! 40: ! 41: bit_clear(name, bit) ! 42: bitstr_t name; ! 43: int bit; ! 44: ! 45: bit_ffc(name, nbits, value) ! 46: bitstr_t name; ! 47: int nbits, *value; ! 48: ! 49: bit_ffs(name, nbits, value) ! 50: bitstr_t name; ! 51: int nbits, *value; ! 52: ! 53: bit_nclear(name, start, stop) ! 54: bitstr_t name; ! 55: int start, stop; ! 56: ! 57: bit_nset(name, start, stop) ! 58: bitstr_t name; ! 59: int start, stop; ! 60: ! 61: bit_set(name, bit) ! 62: bitstr_t name; ! 63: int bit; ! 64: ! 65: bitstr_size(nbits) ! 66: int nbits; ! 67: ! 68: bit_test(name, bit) ! 69: bitstr_t name; ! 70: int bit; ! 71: .fi ! 72: .ft R ! 73: .SH DESCRIPTION ! 74: These macros operate on strings of bits. ! 75: .PP ! 76: .I Bit_alloc ! 77: returns a pointer of type ! 78: .I bitstr_t\ * ! 79: to sufficient space to store ! 80: .I nbits ! 81: bits, or NULL if no space is available. ! 82: .PP ! 83: .I Bit_decl ! 84: is a macro for allocating sufficient space to store ! 85: .I nbits ! 86: bits on the stack. ! 87: .PP ! 88: .I Bitstr_size ! 89: returns the number of elements of type ! 90: .I bitstr_t ! 91: necessary to store ! 92: .I nbits ! 93: bits. ! 94: This is useful for copying bit strings. ! 95: .PP ! 96: .I Bit_clear ! 97: and ! 98: .I bit_set ! 99: clear or set the zero-based numbered bit ! 100: .IR bit , ! 101: in the bit string ! 102: .IR name . ! 103: .PP ! 104: .I Bit_nset ! 105: and ! 106: .I bit_nclear ! 107: set or clear the zero-based numbered bits from ! 108: .I start ! 109: to ! 110: .I stop ! 111: in the bit string ! 112: .IR name . ! 113: .PP ! 114: .I Bit_test ! 115: evaluates to zero if the zero-based numbered bit ! 116: .I bit ! 117: of bit string ! 118: .I name ! 119: is set, and non-zero otherwise. ! 120: .PP ! 121: .I Bit_ffs ! 122: stores in the location referenced by ! 123: .I value ! 124: the zero-based number of the first bit set in the array of ! 125: .I nbits ! 126: bits referenced by ! 127: .IR name . ! 128: If no bits are set, the location referenced by ! 129: .I value ! 130: is set to -1. ! 131: .PP ! 132: .I Bit_ffc ! 133: stores in the location referenced by ! 134: .I value ! 135: the zero-based number of the first bit not set in the array of ! 136: .I nbits ! 137: bits referenced by ! 138: .IR name . ! 139: If all bits are set, the location referenced by ! 140: .I value ! 141: is set to -1. ! 142: .PP ! 143: The arguments to these macros are evaluated only once and may safely ! 144: have side effects. ! 145: .SH EXAMPLE ! 146: .nf ! 147: .in +5 ! 148: #include <limits.h> ! 149: #include <bitstring.h> ! 150: ! 151: ... ! 152: #define LPR_BUSY_BIT 0 ! 153: #define LPR_FORMAT_BIT 1 ! 154: #define LPR_DOWNLOAD_BIT 2 ! 155: ... ! 156: #define LPR_AVAILABLE_BIT 9 ! 157: #define LPR_MAX_BITS 10 ! 158: ! 159: make_lpr_available() ! 160: { ! 161: bitstr_t bit_decl(bitlist, LPR_MAX_BITS); ! 162: ... ! 163: bit_nclear(bitlist, 0, LPR_MAX_BITS - 1); ! 164: ... ! 165: if (!bit_test(bitlist, LPR_BUSY_BIT)) { ! 166: bit_clear(bitlist, LPR_FORMAT_BIT); ! 167: bit_clear(bitlist, LPR_DOWNLOAD_BIT); ! 168: bit_set(bitlist, LPR_AVAILABLE_BIT); ! 169: } ! 170: } ! 171: .fi ! 172: .SH "SEE ALSO" ! 173: malloc(3)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.