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(seq_cur, cp)==0)
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)==0) {
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;
125 ** keep mp->curmsg and msgattrs[] of seq_cur in sync - see seq_list()
127 if (strcmp(seq_cur, cp)==0)
131 ** Get the number for this sequence
133 for (i = 0; mp->msgattrs[i]; i++) {
134 if (strcmp(mp->msgattrs[i], cp)==0) {
141 /* If this is a new sequence, add a slot for it */
143 advise(NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
146 if (!(mp->msgattrs[i] = strdup(cp))) {
147 advise(NULL, "strdup failed");
150 mp->msgattrs[i + 1] = NULL;
153 if (mp->nummsg>0 && (new_seq || zero)) {
154 /* Clear the bit for this sequence from all messages. */
155 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
156 clear_sequence(mp, i, j);
159 /* Set the bit for this sequence for this particular message. */
160 add_sequence(mp, i, msgnum);
162 /* Set the public/private bit for this sequence. */
164 make_seq_public(mp, i);
165 else if (public == 0)
166 make_seq_private(mp, i);
169 ** If public == -1, then only set the
170 ** public/private bit for new sequences.
173 make_seq_private(mp, i);
175 make_seq_public(mp, i);
178 mp->msgflags |= SEQMOD;