]> diplodocus.org Git - nmh/blob - sbr/seq_del.c
Fix invalid pointer arithmetic.
[nmh] / sbr / seq_del.c
1 /* seq_del.c -- delete message(s) from a sequence
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9
10
11 /*
12 * Delete all SELECTED messages from sequence
13 *
14 * If public == 1, make sequence public.
15 * If public == 0, make sequence private.
16 * If public == -1, leave the public/private bit alone for existing
17 * sequences. For new sequences, set this bit based
18 * on its readonly status.
19 *
20 * If error, return 0, else return 1.
21 */
22
23 int
24 seq_delsel (struct msgs *mp, char *cp, int public, int zero)
25 {
26 unsigned int i;
27 int 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; i < svector_size (mp->msgattrs); i++) {
36 if (!strcmp (svector_at (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 (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
52 inform("strdup failed");
53 return 0;
54 }
55 }
56 /*
57 * now add sequence bit to all existing messages
58 */
59 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
60 if (does_exist (mp, msgnum))
61 add_sequence (mp, i, msgnum);
62 else
63 clear_sequence (mp, i, msgnum);
64 }
65 } else {
66 if (new_seq) {
67 inform("no such sequence as %s", cp);
68 return 0;
69 }
70 }
71
72 /*
73 * Now clear the bit on all selected messages
74 */
75 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
76 if (is_selected (mp, msgnum))
77 clear_sequence (mp, i, msgnum);
78
79 if (! strcmp (cp, current) &&
80 mp->lowsel <= mp->curmsg && mp->curmsg <= mp->hghsel) {
81 /* Removed current message indication, so reset curmsg. */
82 mp->curmsg = 0;
83 }
84
85 /*
86 * Set the public/private bit for this sequence.
87 */
88 if (public == 1)
89 make_seq_public (mp, i);
90 else if (public == 0)
91 make_seq_private (mp, i);
92 else if (new_seq) {
93 /*
94 * If public == -1, then only set the
95 * public/private bit for new sequences.
96 */
97 if (is_readonly (mp))
98 make_seq_private (mp, i);
99 else
100 make_seq_public (mp, i);
101 }
102
103 mp->msgflags |= SEQMOD;
104 return 1;
105 }
106
107
108 /*
109 * Delete message from sequence.
110 *
111 * If error, return 0, else return 1.
112 */
113
114 int
115 seq_delmsg (struct msgs *mp, char *cp, int msgnum)
116 {
117 size_t i;
118
119 if (!seq_nameok (cp))
120 return 0;
121
122 for (i = 0; i < svector_size (mp->msgattrs); i++) {
123 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
124 clear_sequence (mp, i, msgnum);
125 mp->msgflags |= SEQMOD;
126 return 1;
127 }
128 }
129
130 inform("no such sequence as %s", cp);
131 return 0;
132 }