(mh_msgset_parse): Sort the message set and remove any duplicates from it.
Showing
1 changed file
with
19 additions
and
0 deletions
... | @@ -163,6 +163,16 @@ msgset_preproc (mailbox_t mbox, char *arg) | ... | @@ -163,6 +163,16 @@ msgset_preproc (mailbox_t mbox, char *arg) |
163 | return strdup (arg); | 163 | return strdup (arg); |
164 | } | 164 | } |
165 | 165 | ||
166 | static int | ||
167 | comp_mesg (const void *a, const void *b) | ||
168 | { | ||
169 | if (*(size_t*)a > *(size_t*)b) | ||
170 | return 1; | ||
171 | else if (*(size_t*)a < *(size_t*)b) | ||
172 | return -1; | ||
173 | return 0; | ||
174 | } | ||
175 | |||
166 | int | 176 | int |
167 | mh_msgset_parse (mailbox_t mbox, mh_msgset_t *msgset, int argc, char **argv) | 177 | mh_msgset_parse (mailbox_t mbox, mh_msgset_t *msgset, int argc, char **argv) |
168 | { | 178 | { |
... | @@ -231,6 +241,15 @@ mh_msgset_parse (mailbox_t mbox, mh_msgset_t *msgset, int argc, char **argv) | ... | @@ -231,6 +241,15 @@ mh_msgset_parse (mailbox_t mbox, mh_msgset_t *msgset, int argc, char **argv) |
231 | free (arg); | 241 | free (arg); |
232 | } | 242 | } |
233 | 243 | ||
244 | /* Sort the resulting message set */ | ||
245 | qsort (msglist, msgcnt, sizeof (*msglist), comp_mesg); | ||
246 | |||
247 | /* Remove duplicates. */ | ||
248 | for (i = 0, msgno = 1; i < msgcnt; i++) | ||
249 | if (msglist[msgno-1] != msglist[i]) | ||
250 | msglist[msgno++] = msglist[i]; | ||
251 | msgcnt = msgno; | ||
252 | |||
234 | msgset->count = msgcnt; | 253 | msgset->count = msgcnt; |
235 | msgset->list = msglist; | 254 | msgset->list = msglist; |
236 | return 0; | 255 | return 0; | ... | ... |
-
Please register or sign in to post a comment