]> diplodocus.org Git - nmh/blob - sbr/seq_add.c
sendsbr.c: Move interface to own file.
[nmh] / sbr / seq_add.c
1 /* seq_add.c -- add message(s) to 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 #include "seq_nameok.h"
10 #include "seq_add.h"
11 #include "error.h"
12
13
14 /*
15 * Add all the SELECTED messages to a (possibly new) sequence.
16 *
17 * If public == 1, make sequence public.
18 * If public == 0, make sequence private.
19 * If public == -1, leave the public/private bit alone for existing
20 * sequences. For new sequences, set this bit based
21 * on its readonly status.
22 *
23 * If error, return 0, else return 1.
24 */
25
26 int
27 seq_addsel (struct msgs *mp, char *cp, int public, int zero)
28 {
29 unsigned int i;
30 int msgnum;
31
32 if (!seq_nameok (cp))
33 return 0;
34
35 /*
36 * We keep mp->curmsg and "cur" sequence in sync.
37 * See seq_list() and seq_init().
38 */
39 if (!strcmp (current,cp))
40 mp->curmsg = mp->hghsel;
41
42 /*
43 * Get the number for this sequence
44 */
45 bool new_seq = true;
46 for (i = 0; i < svector_size (mp->msgattrs); i++) {
47 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
48 new_seq = false;
49 break;
50 }
51 }
52
53 /*
54 * If this is a new sequence, add a slot for it
55 */
56 if (new_seq) {
57 if (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
58 inform("strdup failed");
59 return 0;
60 }
61 }
62
63 /*
64 * If sequence is new, or zero flag is set, then first
65 * clear the bit for this sequence from all messages.
66 */
67 if ((new_seq || zero) && mp->nummsg > 0) {
68 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
69 clear_sequence (mp, i, msgnum);
70 }
71
72 /*
73 * Now flip on the bit for this sequence
74 * for all selected messages.
75 */
76 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
77 if (is_selected (mp, msgnum))
78 add_sequence (mp, i, msgnum);
79
80 /*
81 * Set the public/private bit for this sequence.
82 */
83 if (public == 1)
84 make_seq_public (mp, i);
85 else if (public == 0)
86 make_seq_private (mp, i);
87 else if (new_seq) {
88 /*
89 * If public == -1, then only set the
90 * public/private bit for new sequences.
91 */
92 if (is_readonly (mp))
93 make_seq_private (mp, i);
94 else
95 make_seq_public (mp, i);
96 }
97
98 mp->msgflags |= SEQMOD;
99 return 1;
100 }
101
102
103 /*
104 * Add a message to a (possibly new) sequence.
105 *
106 * If public == 1, make sequence public.
107 * If public == 0, make sequence private.
108 * If public == -1, leave the public/private bit alone for existing
109 * sequences. For new sequences, set this bit based
110 * on its readonly status.
111 *
112 * If error, return 0, else return 1.
113 */
114
115 int
116 seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
117 {
118 unsigned int i;
119 int j;
120
121 if (!seq_nameok (cp))
122 return 0;
123
124 /*
125 * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
126 */
127 if (!strcmp (current,cp))
128 mp->curmsg = msgnum;
129
130 /*
131 * Get the number for this sequence
132 */
133 bool new_seq = true;
134 for (i = 0; i < svector_size (mp->msgattrs); i++) {
135 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
136 new_seq = false;
137 break;
138 }
139 }
140
141 /*
142 * If this is a new sequence, add a slot for it
143 */
144 if (new_seq) {
145 if (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
146 inform("strdup failed");
147 return 0;
148 }
149 }
150
151 /*
152 * If sequence is new, or zero flag is set, then first
153 * clear the bit for this sequence from all messages.
154 */
155 if ((new_seq || zero) && mp->nummsg > 0) {
156 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
157 clear_sequence (mp, i, j);
158 }
159
160 /*
161 * Now flip on the bit for this sequence
162 * for this particular message.
163 */
164 add_sequence (mp, i, msgnum);
165
166 /*
167 * Set the public/private bit for this sequence.
168 */
169 if (public == 1)
170 make_seq_public (mp, i);
171 else if (public == 0)
172 make_seq_private (mp, i);
173 else if (new_seq) {
174 /*
175 * If public == -1, then only set the
176 * public/private bit for new sequences.
177 */
178 if (is_readonly (mp))
179 make_seq_private (mp, i);
180 else
181 make_seq_public (mp, i);
182 }
183
184 mp->msgflags |= SEQMOD;
185 return 1;
186 }