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)
29 int msgnum, new_seq = 1;
35 * We keep mp->curmsg and "cur" sequence in sync.
36 * See seq_list() and seq_init().
38 if (!strcmp (current,cp))
39 mp->curmsg = mp->hghsel;
42 * Get the number for this sequence
44 for (i = 0; mp->msgattrs[i]; i++) {
45 if (!strcmp (mp->msgattrs[i], cp)) {
52 * If this is a new sequence, add a slot for it
56 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
59 if (!(mp->msgattrs[i] = strdup (cp))) {
60 advise (NULL, "strdup failed");
63 mp->msgattrs[i + 1] = NULL;
67 * If sequence is new, or zero flag is set, then first
68 * clear the bit for this sequence from all messages.
70 if ((new_seq || zero) && mp->nummsg > 0) {
71 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
72 clear_sequence (mp, i, msgnum);
76 * Now flip on the bit for this sequence
77 * for all selected messages.
79 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
80 if (is_selected (mp, msgnum))
81 add_sequence (mp, i, msgnum);
84 * Set the public/private bit for this sequence.
87 make_seq_public (mp, i);
89 make_seq_private (mp, i);
92 * If public == -1, then only set the
93 * public/private bit for new sequences.
96 make_seq_private (mp, i);
98 make_seq_public (mp, i);
101 mp->msgflags |= SEQMOD;
107 * Add a message to a (possibly new) sequence.
109 * If public == 1, make sequence public.
110 * If public == 0, make sequence private.
111 * If public == -1, leave the public/private bit alone for existing
112 * sequences. For new sequences, set this bit based
113 * on its readonly status.
115 * If error, return 0, else return 1.
119 seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
124 if (!seq_nameok (cp))
128 * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
130 if (!strcmp (current,cp))
134 * Get the number for this sequence
136 for (i = 0; mp->msgattrs[i]; i++) {
137 if (!strcmp (mp->msgattrs[i], cp)) {
144 * If this is a new sequence, add a slot for it
148 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
151 if (!(mp->msgattrs[i] = strdup (cp))) {
152 advise (NULL, "strdup failed");
155 mp->msgattrs[i + 1] = NULL;
159 * If sequence is new, or zero flag is set, then first
160 * clear the bit for this sequence from all messages.
162 if ((new_seq || zero) && mp->nummsg > 0) {
163 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
164 clear_sequence (mp, i, j);
168 * Now flip on the bit for this sequence
169 * for this particular message.
171 add_sequence (mp, i, msgnum);
174 * Set the public/private bit for this sequence.
177 make_seq_public (mp, i);
178 else if (public == 0)
179 make_seq_private (mp, i);
182 * If public == -1, then only set the
183 * public/private bit for new sequences.
185 if (is_readonly (mp))
186 make_seq_private (mp, i);
188 make_seq_public (mp, i);
191 mp->msgflags |= SEQMOD;