Use sysexits.h for better exit-codes
[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 }
103
104 void
105 set_unseen(struct msgs *mp, int msgnum)
106 {
107         assert_msg_range(mp, msgnum);
108         mp->msgstats[msgnum - mp->lowoff] |= SELECT_UNSEEN;
109 }
110
111 void
112 unset_exists(struct msgs *mp, int msgnum)
113 {
114         assert_msg_range(mp, msgnum);
115         mp->msgstats[msgnum - mp->lowoff] &= ~EXISTS;
116 }
117
118 void
119 unset_selected(struct msgs *mp, int msgnum)
120 {
121         assert_msg_range(mp, msgnum);
122         mp->msgstats[msgnum - mp->lowoff] &= ~SELECTED;
123 }
124
125 void
126 unset_unseen(struct msgs *mp, int msgnum)
127 {
128         assert_msg_range(mp, msgnum);
129         mp->msgstats[msgnum - mp->lowoff] &= ~SELECT_UNSEEN;
130 }
131
132
133 /*
134 **  private/public sequences
135 */
136
137 int
138 is_seq_private(struct msgs *mp, int seqnum)
139 {
140         return mp->attrstats & (1 << (FFATTRSLOT + seqnum));
141 }
142
143 void
144 make_seq_public(struct msgs *mp, int seqnum)
145 {
146         mp->attrstats &= ~(1 << (FFATTRSLOT + seqnum));
147 }
148 void
149 make_seq_private(struct msgs *mp, int seqnum)
150 {
151         mp->attrstats |= (1 << (FFATTRSLOT + seqnum));
152 }
153 void
154 make_all_public(struct msgs *mp)
155 {
156         mp->attrstats = 0;
157 }
158
159
160 /*
161 ** folder attributes
162 */
163
164 void
165 clear_folder_flags(struct msgs *mp)
166 {
167         mp->msgflags = 0;
168 }
169
170 int
171 is_readonly(struct msgs *mp)
172 {
173         return mp->msgflags & READONLY;
174 }
175 void
176 set_readonly(struct msgs *mp)
177 {
178         mp->msgflags |= READONLY;
179 }
180
181 int
182 other_files(struct msgs *mp)
183 {
184         return mp->msgflags & OTHERS;
185 }
186 void
187 set_other_files(struct msgs *mp)
188 {
189         mp->msgflags |= OTHERS;
190 }