"Fossies" - the Fresh Open Source Software Archive
Member "tin-2.4.3/include/newsrc.h" (23 Nov 2018, 6333 Bytes) of package /linux/misc/tin-2.4.3.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard
) with prefixed line numbers and code folding
Alternatively you can here view
the uninterpreted source code file.
For more information about "newsrc.h" see the Fossies "Dox" file reference
documentation and the latest Fossies "Diffs"
side-by-side code changes report: 2.4.2_vs_2.4.3
2 * Project : tin - a Usenet reader
3 * Module : newsrc.h
4 * Author : I. Lea & R. Skrenta
5 * Created : 1991-04-01
6 * Updated : 2003-11-18
7 * Notes : newsrc bit handling
9 * Copyright (c) 1997-2019 Iain Lea <firstname.lastname@example.org>, Rich Skrenta <email@example.com>
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote
21 * products derived from this software without specific prior written
22 * permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #ifndef NEWSRC_H
38 #define NEWSRC_H 1
41 * The following macros are used to simplify and speed up the
42 * manipulation of the bitmaps in memory which record which articles
43 * are read or unread in each news group.
45 * Data representation:
47 * Each bitmap is handled as an array of bytes; the least-significant
48 * bit of the 0th byte is the 0th bit; the most significant bit of
49 * the 0th byte is the 7th bit. Thus, the most-significant bit of the
50 * 128th byte is the 1023rd bit, and in general the mth bit of the nth
51 * byte is considered to be bit (n*8)+m of the map as a whole. Conversely,
52 * the position of bit q in the map is the bit (q & 7) of byte (q >> 3).
53 * A bitmap of b bits will be allocated as ((b+7) >> 3) bytes.
55 * The routines could be changed to operate on a word-oriented bitmap by
56 * changing the constants used from 8 to 16, 3 to 4, 7 to 15, etc. and
57 * changing the allocate/deallocate routines.
59 * In the newsrc context, a 0 bit represents an article which is read
60 * or expired; a 1 represents an unread article. The 0th bit corresponds
61 * to the minimum article number for this group, and (max-min+7)/8 bytes
62 * are allocated to the bitmap.
64 * Constants:
66 * NBITS = total number of bits per byte;
67 * NMAXBIT = number of bits per byte or word;
68 * NBITPOS = number of bit in NMAXBIT;
69 * NBITSON = byte/word used to set all bits in byte/word to 1;
70 * NBITNEG1 = binary negation of 1, used in constructing masks.
72 * Macro naming and use:
74 * The NOFFSET and NBITIDX macro construct the byte and bit indexes in
75 * the map, given a bit number.
77 * The NSET0 macro sets a bit to binary 0
78 * The NSET1 macro sets a bit to binary 1
79 * The NSETBLK0 macro sets the same bit or bits to binary 0
80 * The NSETBLK1 macro sets the same bit or bits to binary 1
81 * The NTEST macro tests a single bit.
82 * These are used frequently to access the group bitmap.
84 * NSETBLK0 and NSETBLK1 operate on whole numbers of bytes, and are
85 * mainly useful for initializing complete bitmaps to one state or
86 * another. Both use the memset function, which is assumed to be
87 * optimized for the target architecture. NSETBLK is currently used to
88 * initialize the group bitmap to 1s (unread).
90 * NSETRNG0 and NSETRNG1 operate on ranges of bits, from a low bit number
91 * to a high bit number (inclusive), and are especially useful for
92 * efficiently setting a contiguous range of bits to one state or another.
93 * NSETRNG0 is currently used on the group bitmap to mark the ranges the
94 * newsrc file says are read or expired.
96 * The algorithm is this. If the high number is less than the low, then
97 * do nothing (error); if both fall within the same byte, construct a
98 * single mask expressing the range and AND or OR it into the byte; else:
99 * construct a mask for the byte containing the low bit, AND or OR it in;
100 * use memset to fill in the intervening bytes efficiently; then construct
101 * a mask for the byte containing the high bit, and AND or OR this mask
102 * in. Masks are constructed by left-shift of 0xff (to set high-order bits
103 * to 1), negating a left-shift of 0xfe (to set low-order bits to 1), and
104 * the various negations and combinations of the same. This procedure is
105 * complex, but 1 to 2 orders of magnitude faster than a shift inside a
106 * loop for each bit inside a loop for each individual byte.
109 #define NBITS 8
110 #define NMAXBIT 7
111 #define NBITPOS 3
112 #define NBITSON 0xff
113 #define NBITNEG1 0xfe
114 #define NOFFSET(b) ((b) >> NBITPOS)
115 #define NBITIDX(b) ((b) & NMAXBIT)
117 #define NBITMASK(beg,end) (unsigned char) ~(((1 << (((NMAXBIT - beg) - (NMAXBIT - end)) + 1)) - 1) << (NMAXBIT - end))
119 #define NTEST(n,b) (n[NOFFSET(b)] & (1 << NBITIDX(b)))
121 #define NSETBLK1(n,i) (memset(n, NBITSON, (size_t) NOFFSET(i) + 1))
122 #define NSETBLK0(n,i) (memset(n, 0, (size_t) NOFFSET(i) + 1))
124 /* dbmalloc checks memset() parameters, so we'll use it to check the assignments */
125 #ifdef USE_DBMALLOC
126 # define NSET1(n,b) memset(n + NOFFSET(b), n[NOFFSET(b)] | NTEST(n,b), 1)
127 # define NSET0(n,b) memset(n + NOFFSET(b), n[NOFFSET(b)] & ~NTEST(n,b), 1)
128 # define BIT_OR(n, b, mask) memset(n + NOFFSET(b), n[NOFFSET(b)] | (mask), 1)
129 # define BIT_AND(n, b, mask) memset(n + NOFFSET(b), n[NOFFSET(b)] & (mask), 1)
130 # include <dbmalloc.h> /* dbmalloc 1.4 */
132 # define NSET1(n,b) (n[NOFFSET(b)] |= (1 << NBITIDX(b)))
133 # define NSET0(n,b) (n[NOFFSET(b)] &= ~(1 << NBITIDX(b)))
134 # define BIT_OR(n, b, mask) n[NOFFSET(b)] |= mask
135 # define BIT_AND(n, b, mask) n[NOFFSET(b)] &= mask
136 #endif /* USE_DBMALLOC */
138 #define BITS_TO_BYTES(n) ((size_t) ((n + NBITS - 1) / NBITS))
140 #endif /* !NEWSRC_H */