Rearranged whitespace (and comments) in all the code!
[mmh] / sbr / seq_setunseen.c
1 /*
2  * seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN
3  *                 -- bit set to/from the Unseen-Sequence
4  *
5  * This code is Copyright (c) 2002, by the authors of nmh.  See the
6  * COPYRIGHT file in the root directory of the nmh distribution for
7  * complete copyright information.
8  */
9
10 #include <h/mh.h>
11
12 /*
13  * We scan through the folder and act upon all messages
14  * that are marked with the SELECT_UNSEEN bit.
15  *
16  * If seen == 1, delete messages from unseen sequence.
17  * If seen == 0, add messages to unseen sequence.
18  */
19
20 void
21 seq_setunseen (struct msgs *mp, int seen)
22 {
23         int msgnum;
24         char **ap, *cp, *dp;
25
26         /*
27          * Get the list of sequences for Unseen-Sequence
28          * and split them.
29          */
30         if ((cp = context_find (usequence))) {
31                 dp = getcpy (cp);
32                 if (!(ap = brkstring (dp, " ", "\n")) || !*ap) {
33                         free (dp);
34                         return;
35                 }
36         } else {
37                 return;
38         }
39
40         /*
41          * Now add/delete each message which has the SELECT_UNSEEN
42          * bit set to/from each of these sequences.
43          */
44         for (; *ap; ap++) {
45                 if (seen) {
46                         /* make sure sequence exists first */
47                         if (seq_getnum(mp, *ap) != -1)
48                                 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
49                                         if (is_unseen (mp, msgnum))
50                                                 seq_delmsg (mp, *ap, msgnum);
51                 } else {
52                         for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
53                                 if (is_unseen (mp, msgnum))
54                                         seq_addmsg (mp, *ap, msgnum, -1, 0);
55                 }
56         }
57
58         free (dp);
59 }