Commit | Line | Data |
---|---|---|
a8856877 WJ |
1 | .\" Copyright (c) 1989, 1991 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 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. All advertising materials mentioning features or use of this software | |
15 | .\" must display the following acknowledgement: | |
16 | .\" This product includes software developed by the University of | |
17 | .\" California, Berkeley and its contributors. | |
18 | .\" 4. Neither the name of the University nor the names of its contributors | |
19 | .\" may be used to endorse or promote products derived from this software | |
20 | .\" without specific prior written permission. | |
21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)bitstring.3 5.4 (Berkeley) 4/19/91 | |
35 | .\" | |
36 | .Dd April 19, 1991 | |
37 | .Dt BITSTRING 3 | |
38 | .Os BSD 4 | |
39 | .Sh NAME | |
40 | .Nm bit_alloc , | |
41 | .Nm bit_clear , | |
42 | .Nm bit_decl , | |
43 | .Nm bit_ffs , | |
44 | .Nm bit_nclear , | |
45 | .Nm bit_nset, | |
46 | .Nm bit_set , | |
47 | .Nm bitstr_size , | |
48 | .Nm bit_test | |
49 | .Nd bit-string manipulation macros | |
50 | .Sh SYNOPSIS | |
51 | .Fd #include <bitstring.h> | |
52 | .Ft bitstr_t * | |
53 | .Fn bit_alloc "int nbits" | |
54 | .Fn bit_decl "bit_str name" "int nbits" | |
55 | .Fn bit_clear "bit_str name" "int bit" | |
56 | .Fn bit_ffc "bit_str name" "int nbits" "int *value" | |
57 | .Fn bit_ffs "bit_str name" "int nbits" "int *value" | |
58 | .Fn bit_nclear "bit_str name" "int start" "int stop" | |
59 | .Fn bit_nset "bit_str name" "int start" "int stop" | |
60 | .Fn bit_set "bit_str name" "int bit" | |
61 | .Fn bitstr_size "int nbits" | |
62 | .Fn bit_test "bit_str name" "int bit" | |
63 | .Sh DESCRIPTION | |
64 | These macros operate on strings of bits. | |
65 | .Pp | |
66 | The macro | |
67 | .Fn bit_alloc | |
68 | returns a pointer of type | |
69 | .Dq Fa "bitstr_t *" | |
70 | to sufficient space to store | |
71 | .Fa nbits | |
72 | bits, or | |
73 | .Dv NULL | |
74 | if no space is available. | |
75 | .Pp | |
76 | The macro | |
77 | .Fn bit_decl | |
78 | allocates sufficient space to store | |
79 | .Fa nbits | |
80 | bits on the stack. | |
81 | .Pp | |
82 | The macro | |
83 | .Fn bitstr_size | |
84 | returns the number of elements of type | |
85 | .Fa bitstr_t | |
86 | necessary to store | |
87 | .Fa nbits | |
88 | bits. | |
89 | This is useful for copying bit strings. | |
90 | .Pp | |
91 | The macros | |
92 | .Fn bit_clear | |
93 | and | |
94 | .Fn bit_set | |
95 | clear or set the zero-based numbered bit | |
96 | .Fa bit , | |
97 | in the bit string | |
98 | .Ar name . | |
99 | .Pp | |
100 | The | |
101 | .Fn bit_nset | |
102 | and | |
103 | .Fn bit_nclear | |
104 | macros | |
105 | set or clear the zero-based numbered bits from | |
106 | .Fa start | |
107 | to | |
108 | .Fa stop | |
109 | in the bit string | |
110 | .Ar name . | |
111 | .Pp | |
112 | The | |
113 | .Fn bit_test | |
114 | macro | |
115 | evaluates to zero if the zero-based numbered bit | |
116 | .Fa bit | |
117 | of bit string | |
118 | .Fa name | |
119 | is set, and non-zero otherwise. | |
120 | .Pp | |
121 | The | |
122 | .Fn bit_ffs | |
123 | macro | |
124 | stores in the location referenced by | |
125 | .Fa value | |
126 | the zero-based number of the first bit set in the array of | |
127 | .Fa nbits | |
128 | bits referenced by | |
129 | .Fa name . | |
130 | If no bits are set, the location referenced by | |
131 | .Fa value | |
132 | is set to \-1. | |
133 | .Pp | |
134 | The macro | |
135 | .Fn bit_ffc | |
136 | stores in the location referenced by | |
137 | .Fa value | |
138 | the zero-based number of the first bit not set in the array of | |
139 | .Fa nbits | |
140 | bits referenced by | |
141 | .Fa name . | |
142 | If all bits are set, the location referenced by | |
143 | .Fa value | |
144 | is set to \-1. | |
145 | .Pp | |
146 | The arguments to these macros are evaluated only once and may safely | |
147 | have side effects. | |
148 | .Sh EXAMPLE | |
149 | .Bd -literal -offset indent | |
150 | #include <limits.h> | |
151 | #include <bitstring.h> | |
152 | ||
153 | ... | |
154 | #define LPR_BUSY_BIT 0 | |
155 | #define LPR_FORMAT_BIT 1 | |
156 | #define LPR_DOWNLOAD_BIT 2 | |
157 | ... | |
158 | #define LPR_AVAILABLE_BIT 9 | |
159 | #define LPR_MAX_BITS 10 | |
160 | ||
161 | make_lpr_available() | |
162 | { | |
163 | bitstr_t bit_decl(bitlist, LPR_MAX_BITS); | |
164 | ... | |
165 | bit_nclear(bitlist, 0, LPR_MAX_BITS - 1); | |
166 | ... | |
167 | if (!bit_test(bitlist, LPR_BUSY_BIT)) { | |
168 | bit_clear(bitlist, LPR_FORMAT_BIT); | |
169 | bit_clear(bitlist, LPR_DOWNLOAD_BIT); | |
170 | bit_set(bitlist, LPR_AVAILABLE_BIT); | |
171 | } | |
172 | } | |
173 | .Ed | |
174 | .Sh SEE ALSO | |
175 | .Xr malloc 3 | |
176 | .Sh HISTORY | |
177 | The | |
178 | .Nm | |
179 | functions are | |
180 | .Ud . |