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