3 * seq_add.c -- add message(s) to a sequence
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.
14 * Add all the SELECTED messages to a (possibly new) sequence.
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.
22 * If error, return 0, else return 1.
26 seq_addsel (struct msgs *mp, char *cp, int public, int zero)
28 int i, msgnum, new_seq = 1;
34 * We keep mp->curmsg and "cur" sequence in sync.
35 * See seq_list() and seq_init().
37 if (!strcmp (current,cp))
38 mp->curmsg = mp->hghsel;
41 * Get the number for this sequence
43 for (i = 0; mp->msgattrs[i]; i++) {
44 if (!strcmp (mp->msgattrs[i], cp)) {
51 * If this is a new sequence, add a slot for it
55 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
58 if (!(mp->msgattrs[i] = strdup (cp))) {
59 advise (NULL, "strdup failed");
62 mp->msgattrs[i + 1] = NULL;
66 * If sequence is new, or zero flag is set, then first
67 * clear the bit for this sequence from all messages.
69 if (new_seq || zero) {
70 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
71 clear_sequence (mp, i, msgnum);
75 * Now flip on the bit for this sequence
76 * for all selected messages.
78 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
79 if (is_selected (mp, msgnum))
80 add_sequence (mp, i, msgnum);
83 * Set the public/private bit for this sequence.
86 make_seq_public (mp, i);
88 make_seq_private (mp, i);
91 * If public == -1, then only set the
92 * public/private bit for new sequences.
95 make_seq_private (mp, i);
97 make_seq_public (mp, i);
100 mp->msgflags |= SEQMOD;
106 * Add a message to a (possibly new) sequence.
108 * If public == 1, make sequence public.
109 * If public == 0, make sequence private.
110 * If public == -1, leave the public/private bit alone for existing
111 * sequences. For new sequences, set this bit based
112 * on its readonly status.
114 * If error, return 0, else return 1.
118 seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
120 int i, j, new_seq = 1;
122 if (!seq_nameok (cp))
126 * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
128 if (!strcmp (current,cp))
132 * Get the number for this sequence
134 for (i = 0; mp->msgattrs[i]; i++) {
135 if (!strcmp (mp->msgattrs[i], cp)) {
142 * If this is a new sequence, add a slot for it
146 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
149 if (!(mp->msgattrs[i] = strdup (cp))) {
150 advise (NULL, "strdup failed");
153 mp->msgattrs[i + 1] = NULL;
157 * If sequence is new, or zero flag is set, then first
158 * clear the bit for this sequence from all messages.
160 if (new_seq || zero) {
161 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
162 clear_sequence (mp, i, j);
166 * Now flip on the bit for this sequence
167 * for this particular message.
169 add_sequence (mp, i, msgnum);
172 * Set the public/private bit for this sequence.
175 make_seq_public (mp, i);
176 else if (public == 0)
177 make_seq_private (mp, i);
180 * If public == -1, then only set the
181 * public/private bit for new sequences.
183 if (is_readonly (mp))
184 make_seq_private (mp, i);
186 make_seq_public (mp, i);
189 mp->msgflags |= SEQMOD;