Rearranged whitespace (and comments) in all the code!
[mmh] / sbr / seq_del.c
1 /*
2  * seq_del.c -- delete message(s) from a sequence
3  *
4  * This code is Copyright (c) 2002, by the authors of nmh.  See the
5  * COPYRIGHT file in the root directory of the nmh distribution for
6  * complete copyright information.
7  */
8
9 #include <h/mh.h>
10
11
12 /*
13  * Delete all SELECTED messages from sequence
14  *
15  * If public ==  1, make sequence public.
16  * If public ==  0, make sequence private.
17  * If public == -1, leave the public/private bit alone for existing
18  *                  sequences.  For new sequences, set this bit based
19  *                  on its readonly status.
20  *
21  * If error, return 0, else return 1.
22  */
23
24 int
25 seq_delsel (struct msgs *mp, char *cp, int public, int zero)
26 {
27         int i, msgnum, new_seq = 1;
28
29         if (!seq_nameok (cp))
30                 return 0;
31
32         /*
33          * Get the number for this sequence
34          */
35         for (i = 0; mp->msgattrs[i]; i++) {
36                 if (!strcmp (mp->msgattrs[i], cp)) {
37                         new_seq = 0;
38                         break;
39                 }
40         }
41
42         /*
43          * If the zero flag is set, first add all existing
44          * messages in this folder to the sequence.
45          */
46         if (zero) {
47                 /*
48                  * create the sequence, if necessary
49                  */
50                 if (new_seq) {
51                         if (i >= NUMATTRS) {
52                                 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
53                                 return 0;
54                         }
55                         if (!(mp->msgattrs[i] = strdup (cp))) {
56                                 advise (NULL, "strdup failed");
57                                 return 0;
58                         }
59                         mp->msgattrs[i + 1] = NULL;
60                 }
61                 /*
62                  * now add sequence bit to all existing messages
63                  */
64                 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
65                         if (does_exist (mp, msgnum))
66                                 add_sequence (mp, i, msgnum);
67                         else
68                                 clear_sequence (mp, i, msgnum);
69                 }
70         } else {
71                 if (new_seq) {
72                         advise (NULL, "no such sequence as %s", cp);
73                         return 0;
74                 }
75         }
76
77         /*
78          * Now clear the bit on all selected messages
79          */
80         for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
81                 if (is_selected (mp, msgnum))
82                         clear_sequence (mp, i, msgnum);
83
84         /*
85          * Set the public/private bit for this sequence.
86          */
87         if (public == 1)
88                 make_seq_public (mp, i);
89         else if (public == 0)
90                 make_seq_private (mp, i);
91         else if (new_seq) {
92                 /*
93                  * If public == -1, then only set the
94                  * public/private bit for new sequences.
95                  */
96                 if (is_readonly (mp))
97                         make_seq_private (mp, i);
98                 else
99                         make_seq_public (mp, i);
100         }
101
102         mp->msgflags |= SEQMOD;
103         return 1;
104 }
105
106
107 /*
108  * Delete message from sequence.
109  *
110  * If error, return 0, else return 1.
111  */
112
113 int
114 seq_delmsg (struct msgs *mp, char *cp, int msgnum)
115 {
116         int i;
117
118         if (!seq_nameok (cp))
119                 return 0;
120
121         for (i = 0; mp->msgattrs[i]; i++) {
122                 if (!strcmp (mp->msgattrs[i], cp)) {
123                         clear_sequence (mp, i, msgnum);
124                         mp->msgflags |= SEQMOD;
125                         return 1;
126                 }
127         }
128
129         advise (NULL, "no such sequence as %s", cp);
130         return 0;
131 }