]>
diplodocus.org Git - nmh/blob - sbr/seq_add.c
3 * seq_add.c -- add message(s) to a sequence
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
16 * Add all the SELECTED messages to a (possibly new) sequence.
18 * If public == 1, make sequence public.
19 * If public == 0, make sequence private.
20 * If public == -1, leave the public/private bit alone for existing
21 * sequences. For new sequences, set this bit based
22 * on its readonly status.
24 * If error, return 0, else return 1.
28 seq_addsel (struct msgs
*mp
, char *cp
, int public, int zero
)
30 int i
, msgnum
, new_seq
= 1;
36 * We keep mp->curmsg and "cur" sequence in sync.
37 * See seq_list() and seq_init().
39 if (!strcmp (current
,cp
))
40 mp
->curmsg
= mp
->hghsel
;
43 * Get the number for this sequence
45 for (i
= 0; mp
->msgattrs
[i
]; i
++) {
46 if (!strcmp (mp
->msgattrs
[i
], cp
)) {
53 * If this is a new sequence, add a slot for it
57 advise (NULL
, "only %d sequences allowed (no room for %s)!", NUMATTRS
, cp
);
60 if (!(mp
->msgattrs
[i
] = strdup (cp
))) {
61 advise (NULL
, "strdup failed");
64 mp
->msgattrs
[i
+ 1] = NULL
;
68 * If sequence is new, or zero flag is set, then first
69 * clear the bit for this sequence from all messages.
71 if (new_seq
|| zero
) {
72 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++)
73 clear_sequence (mp
, i
, msgnum
);
77 * Now flip on the bit for this sequence
78 * for all selected messages.
80 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
81 if (is_selected (mp
, msgnum
))
82 add_sequence (mp
, i
, msgnum
);
85 * Set the public/private bit for this sequence.
88 make_seq_public (mp
, i
);
90 make_seq_private (mp
, i
);
93 * If public == -1, then only set the
94 * public/private bit for new sequences.
97 make_seq_private (mp
, i
);
99 make_seq_public (mp
, i
);
102 mp
->msgflags
|= SEQMOD
;
108 * Add a message to a (possibly new) sequence.
110 * If public == 1, make sequence public.
111 * If public == 0, make sequence private.
112 * If public == -1, leave the public/private bit alone for existing
113 * sequences. For new sequences, set this bit based
114 * on its readonly status.
116 * If error, return 0, else return 1.
120 seq_addmsg (struct msgs
*mp
, char *cp
, int msgnum
, int public, int zero
)
122 int i
, j
, new_seq
= 1;
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
) {
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
;