handle hghsel lowsel and numsel in (un)set_selected
[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         mp->msgstats[msgnum - mp->lowoff] = 0;
31 }
32
33 void
34 clear_sequence(struct msgs *mp, int seqnum, int msgnum)
35 {
36         assert_msg_range(mp, msgnum);
37         mp->msgstats[msgnum - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum));
38 }
39
40 void
41 copy_msg_flags(struct msgs *mp, int dstmsg, int srcmsg)
42 {
43         assert_msg_range(mp, srcmsg);
44         assert_msg_range(mp, dstmsg);
45         mp->msgstats[dstmsg - mp->lowoff] = mp->msgstats[srcmsg - mp->lowoff];
46 }
47
48 seqset_t
49 does_exist(struct msgs *mp, int msgnum)
50 {
51         assert_msg_range(mp, msgnum);
52         return mp->msgstats[msgnum - mp->lowoff] & EXISTS;
53 }
54
55 void
56 get_msg_flags(struct msgs *mp, seqset_t *dst, int msgnum)
57 {
58         assert_msg_range(mp, msgnum);
59         *dst = mp->msgstats[msgnum - mp->lowoff];
60 }
61
62 seqset_t
63 in_sequence(struct msgs *mp, int seqnum, int msgnum)
64 {
65         assert_msg_range(mp, msgnum);
66         return mp->msgstats[msgnum - mp->lowoff] & (1 << (FFATTRSLOT + seqnum));
67 }
68
69 seqset_t
70 is_selected(struct msgs *mp, int msgnum)
71 {
72         assert_msg_range(mp, msgnum);
73         return mp->msgstats[msgnum - mp->lowoff] & SELECTED;
74 }
75
76 seqset_t
77 is_unseen(struct msgs *mp, int msgnum)
78 {
79         assert_msg_range(mp, msgnum);
80         return mp->msgstats[msgnum - mp->lowoff] & SELECT_UNSEEN;
81 }
82
83 void
84 set_exists(struct msgs *mp, int msgnum)
85 {
86         assert_msg_range(mp, msgnum);
87         mp->msgstats[msgnum - mp->lowoff] |= EXISTS;
88 }
89
90 void
91 set_msg_flags(struct msgs *mp, seqset_t *src, int msgnum)
92 {
93         assert_msg_range(mp, msgnum);
94         mp->msgstats[msgnum - mp->lowoff] = *src;
95 }
96
97 void
98 set_selected(struct msgs *mp, int msgnum)
99 {
100         assert_msg_range(mp, msgnum);
101         mp->msgstats[msgnum - mp->lowoff] |= SELECTED;
102         if (mp->lowsel == 0 || msgnum < mp->lowsel) {
103                 mp->lowsel = msgnum;
104         }
105         if (msgnum > mp->hghsel) {
106                 mp->hghsel = msgnum;
107         }
108         mp->numsel++;
109 }
110
111 void
112 set_unseen(struct msgs *mp, int msgnum)
113 {
114         assert_msg_range(mp, msgnum);
115         mp->msgstats[msgnum - mp->lowoff] |= SELECT_UNSEEN;
116 }
117
118 void
119 unset_exists(struct msgs *mp, int msgnum)
120 {
121         assert_msg_range(mp, msgnum);
122         mp->msgstats[msgnum - mp->lowoff] &= ~EXISTS;
123 }
124
125 void
126 unset_selected(struct msgs *mp, int msgnum)
127 {
128         assert_msg_range(mp, msgnum);
129         mp->msgstats[msgnum - mp->lowoff] &= ~SELECTED;
130         if (mp->numsel > 0) {
131                 mp->numsel--;
132         }
133 }
134
135 void
136 unset_unseen(struct msgs *mp, int msgnum)
137 {
138         assert_msg_range(mp, msgnum);
139         mp->msgstats[msgnum - mp->lowoff] &= ~SELECT_UNSEEN;
140 }
141
142
143 /*
144 **  private/public sequences
145 */
146
147 int
148 is_seq_private(struct msgs *mp, int seqnum)
149 {
150         return mp->attrstats & (1 << (FFATTRSLOT + seqnum));
151 }
152
153 void
154 make_seq_public(struct msgs *mp, int seqnum)
155 {
156         mp->attrstats &= ~(1 << (FFATTRSLOT + seqnum));
157 }
158 void
159 make_seq_private(struct msgs *mp, int seqnum)
160 {
161         mp->attrstats |= (1 << (FFATTRSLOT + seqnum));
162 }
163 void
164 make_all_public(struct msgs *mp)
165 {
166         mp->attrstats = 0;
167 }
168
169
170 /*
171 ** folder attributes
172 */
173
174 void
175 clear_folder_flags(struct msgs *mp)
176 {
177         mp->msgflags = 0;
178 }
179
180 int
181 is_readonly(struct msgs *mp)
182 {
183         return mp->msgflags & READONLY;
184 }
185 void
186 set_readonly(struct msgs *mp)
187 {
188         mp->msgflags |= READONLY;
189 }
190
191 int
192 other_files(struct msgs *mp)
193 {
194         return mp->msgflags & OTHERS;
195 }
196 void
197 set_other_files(struct msgs *mp)
198 {
199         mp->msgflags |= OTHERS;
200 }