use memset to clear the msgstats in folder_realloc
[mmh] / sbr / seq_msgstats.c
1 /*
2 ** seq_msgstats -- message and sequence manipulation and folder attributes
3 **
4 ** (These functions had once been macros in h/mh.h)
5 */
6
7 #include <sysexits.h>
8 #include <h/mh.h>
9
10 static void
11 assert_msg_range(struct msgs *mp, int msgnum)
12 {
13         if (msgnum < mp->lowoff || msgnum > mp->hghoff) {
14                 adios(EX_SOFTWARE, NULL, "Bug: message out of bounds");
15         }
16 }
17
18
19 void
20 add_sequence(struct msgs *mp, int seqnum, int msgnum)
21 {
22         assert_msg_range(mp, msgnum);
23         mp->msgstats[msgnum - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum));
24 }
25
26 void
27 clear_msg_flags(struct msgs *mp, int msgnum)
28 {
29         assert_msg_range(mp, msgnum);
30         if (mp->msgstats[msgnum - mp->lowoff])
31                 mp->msgflags |= SEQMOD;
32         mp->msgstats[msgnum - mp->lowoff] = 0;
33 }
34
35 void
36 clear_sequence(struct msgs *mp, int seqnum, int msgnum)
37 {
38         assert_msg_range(mp, msgnum);
39         mp->msgstats[msgnum - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum));
40 }
41
42 void
43 copy_msg_flags(struct msgs *mp, int dstmsg, int srcmsg)
44 {
45         assert_msg_range(mp, srcmsg);
46         assert_msg_range(mp, dstmsg);
47         mp->msgstats[dstmsg - mp->lowoff] = mp->msgstats[srcmsg - mp->lowoff];
48 }
49
50 seqset_t
51 does_exist(struct msgs *mp, int msgnum)
52 {
53         assert_msg_range(mp, msgnum);
54         return mp->msgstats[msgnum - mp->lowoff] & EXISTS;
55 }
56
57 void
58 get_msg_flags(struct msgs *mp, seqset_t *dst, int msgnum)
59 {
60         assert_msg_range(mp, msgnum);
61         *dst = mp->msgstats[msgnum - mp->lowoff];
62 }
63
64 seqset_t
65 in_sequence(struct msgs *mp, int seqnum, int msgnum)
66 {
67         assert_msg_range(mp, msgnum);
68         return mp->msgstats[msgnum - mp->lowoff] & (1 << (FFATTRSLOT + seqnum));
69 }
70
71 seqset_t
72 is_selected(struct msgs *mp, int msgnum)
73 {
74         assert_msg_range(mp, msgnum);
75         return mp->msgstats[msgnum - mp->lowoff] & SELECTED;
76 }
77
78 seqset_t
79 is_unseen(struct msgs *mp, int msgnum)
80 {
81         assert_msg_range(mp, msgnum);
82         return mp->msgstats[msgnum - mp->lowoff] & SELECT_UNSEEN;
83 }
84
85 void
86 set_exists(struct msgs *mp, int msgnum)
87 {
88         assert_msg_range(mp, msgnum);
89         mp->msgstats[msgnum - mp->lowoff] |= EXISTS;
90 }
91
92 void
93 set_msg_flags(struct msgs *mp, seqset_t *src, int msgnum)
94 {
95         assert_msg_range(mp, msgnum);
96         mp->msgstats[msgnum - mp->lowoff] = *src;
97 }
98
99 void
100 set_selected(struct msgs *mp, int msgnum)
101 {
102         assert_msg_range(mp, msgnum);
103
104         if (is_selected(mp, msgnum)) {
105                 return;
106         }
107
108         mp->msgstats[msgnum - mp->lowoff] |= SELECTED;
109         if (mp->lowsel == 0 || msgnum < mp->lowsel) {
110                 mp->lowsel = msgnum;
111         }
112         if (msgnum > mp->hghsel) {
113                 mp->hghsel = msgnum;
114         }
115         mp->numsel++;
116 }
117
118 void
119 set_unseen(struct msgs *mp, int msgnum)
120 {
121         assert_msg_range(mp, msgnum);
122         mp->msgstats[msgnum - mp->lowoff] |= SELECT_UNSEEN;
123 }
124
125 void
126 unset_exists(struct msgs *mp, int msgnum)
127 {
128         assert_msg_range(mp, msgnum);
129         mp->msgstats[msgnum - mp->lowoff] &= ~EXISTS;
130 }
131
132 void
133 unset_selected(struct msgs *mp, int msgnum)
134 {
135         assert_msg_range(mp, msgnum);
136
137         if (!is_selected(mp, msgnum)) {
138                 return;
139         }
140
141         mp->msgstats[msgnum - mp->lowoff] &= ~SELECTED;
142         if (mp->numsel > 0) {
143                 mp->numsel--;
144         }
145 }
146
147
148 /*
149 **  private/public sequences
150 */
151
152 int
153 is_seq_private(struct msgs *mp, int seqnum)
154 {
155         return mp->attrstats & (1 << (FFATTRSLOT + seqnum));
156 }
157
158 void
159 make_seq_public(struct msgs *mp, int seqnum)
160 {
161         mp->attrstats &= ~(1 << (FFATTRSLOT + seqnum));
162 }
163 void
164 make_seq_private(struct msgs *mp, int seqnum)
165 {
166         mp->attrstats |= (1 << (FFATTRSLOT + seqnum));
167 }
168 void
169 make_all_public(struct msgs *mp)
170 {
171         mp->attrstats = 0;
172 }
173
174
175 /*
176 ** folder attributes
177 */
178
179 void
180 clear_folder_flags(struct msgs *mp)
181 {
182         mp->msgflags = 0;
183 }
184
185 int
186 is_readonly(struct msgs *mp)
187 {
188         return mp->msgflags & READONLY;
189 }
190 void
191 set_readonly(struct msgs *mp)
192 {
193         mp->msgflags |= READONLY;
194 }
195
196 int
197 other_files(struct msgs *mp)
198 {
199         return mp->msgflags & OTHERS;
200 }
201 void
202 set_other_files(struct msgs *mp)
203 {
204         mp->msgflags |= OTHERS;
205 }