2 * seq_add.c -- add message(s) to a sequence
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.
13 * Add all the SELECTED messages to a (possibly new) sequence.
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.
21 * If error, return 0, else return 1.
25 seq_addsel (struct msgs *mp, char *cp, int public, int zero)
27 int i, msgnum, new_seq = 1;
33 * We keep mp->curmsg and "cur" sequence in sync.
34 * See seq_list() and seq_init().
36 if (!strcmp (current,cp))
37 mp->curmsg = mp->hghsel;
40 * Get the number for this sequence
42 for (i = 0; mp->msgattrs[i]; i++) {
43 if (!strcmp (mp->msgattrs[i], cp)) {
50 * If this is a new sequence, add a slot for it
54 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
57 if (!(mp->msgattrs[i] = strdup (cp))) {
58 advise (NULL, "strdup failed");
61 mp->msgattrs[i + 1] = NULL;
65 * If sequence is new, or zero flag is set, then first
66 * clear the bit for this sequence from all messages.
68 if (new_seq || zero) {
69 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
70 clear_sequence (mp, i, msgnum);
74 * Now flip on the bit for this sequence
75 * for all selected messages.
77 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
78 if (is_selected (mp, msgnum))
79 add_sequence (mp, i, msgnum);
82 * Set the public/private bit for this sequence.
85 make_seq_public (mp, i);
87 make_seq_private (mp, i);
90 * If public == -1, then only set the
91 * public/private bit for new sequences.
94 make_seq_private (mp, i);
96 make_seq_public (mp, i);
99 mp->msgflags |= SEQMOD;
105 * Add a message to a (possibly new) sequence.
107 * If public == 1, make sequence public.
108 * If public == 0, make sequence private.
109 * If public == -1, leave the public/private bit alone for existing
110 * sequences. For new sequences, set this bit based
111 * on its readonly status.
113 * If error, return 0, else return 1.
117 seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
119 int i, j, new_seq = 1;
121 if (!seq_nameok (cp))
125 * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
127 if (!strcmp (current,cp))
131 * Get the number for this sequence
133 for (i = 0; mp->msgattrs[i]; i++) {
134 if (!strcmp (mp->msgattrs[i], cp)) {
141 * If this is a new sequence, add a slot for it
145 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
148 if (!(mp->msgattrs[i] = strdup (cp))) {
149 advise (NULL, "strdup failed");
152 mp->msgattrs[i + 1] = NULL;
156 * If sequence is new, or zero flag is set, then first
157 * clear the bit for this sequence from all messages.
159 if (new_seq || zero) {
160 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
161 clear_sequence (mp, i, j);
165 * Now flip on the bit for this sequence
166 * for this particular message.
168 add_sequence (mp, i, msgnum);
171 * Set the public/private bit for this sequence.
174 make_seq_public (mp, i);
175 else if (public == 0)
176 make_seq_private (mp, i);
179 * If public == -1, then only set the
180 * public/private bit for new sequences.
182 if (is_readonly (mp))
183 make_seq_private (mp, i);
185 make_seq_public (mp, i);
188 mp->msgflags |= SEQMOD;