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)
28 int msgnum, new_seq = 1;
34 ** We keep mp->curmsg and cur sequence in sync.
35 ** See seq_list() and seq_init().
37 if (strcmp(seq_cur, cp)==0)
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)==0) {
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)
127 ** keep mp->curmsg and msgattrs[] of seq_cur in sync - see seq_list()
129 if (strcmp(seq_cur, cp)==0)
133 ** Get the number for this sequence
135 for (i = 0; mp->msgattrs[i]; i++) {
136 if (strcmp(mp->msgattrs[i], cp)==0) {
143 /* 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;
155 if (mp->nummsg>0 && (new_seq || zero)) {
156 /* Clear the bit for this sequence from all messages. */
157 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
158 clear_sequence(mp, i, j);
161 /* Set the bit for this sequence for this particular message. */
162 add_sequence(mp, i, msgnum);
164 /* Set the public/private bit for this sequence. */
166 make_seq_public(mp, i);
167 else if (public == 0)
168 make_seq_private(mp, i);
171 ** If public == -1, then only set the
172 ** public/private bit for new sequences.
175 make_seq_private(mp, i);
177 make_seq_public(mp, i);
180 mp->msgflags |= SEQMOD;