]> diplodocus.org Git - nmh/blob - sbr/seq_add.c
new.c: Order two return statements to match comment.
[nmh] / sbr / seq_add.c
1 /* seq_add.c -- add message(s) to a sequence
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9
10
11 /*
12 * Add all the SELECTED messages to a (possibly new) sequence.
13 *
14 * If public == 1, make sequence public.
15 * If public == 0, make sequence private.
16 * If public == -1, leave the public/private bit alone for existing
17 * sequences. For new sequences, set this bit based
18 * on its readonly status.
19 *
20 * If error, return 0, else return 1.
21 */
22
23 int
24 seq_addsel (struct msgs *mp, char *cp, int public, int zero)
25 {
26 unsigned int i;
27 int msgnum, new_seq = 1;
28
29 if (!seq_nameok (cp))
30 return 0;
31
32 /*
33 * We keep mp->curmsg and "cur" sequence in sync.
34 * See seq_list() and seq_init().
35 */
36 if (!strcmp (current,cp))
37 mp->curmsg = mp->hghsel;
38
39 /*
40 * Get the number for this sequence
41 */
42 for (i = 0; i < svector_size (mp->msgattrs); i++) {
43 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
44 new_seq = 0;
45 break;
46 }
47 }
48
49 /*
50 * If this is a new sequence, add a slot for it
51 */
52 if (new_seq) {
53 if (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
54 inform("strdup failed");
55 return 0;
56 }
57 }
58
59 /*
60 * If sequence is new, or zero flag is set, then first
61 * clear the bit for this sequence from all messages.
62 */
63 if ((new_seq || zero) && mp->nummsg > 0) {
64 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
65 clear_sequence (mp, i, msgnum);
66 }
67
68 /*
69 * Now flip on the bit for this sequence
70 * for all selected messages.
71 */
72 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
73 if (is_selected (mp, msgnum))
74 add_sequence (mp, i, msgnum);
75
76 /*
77 * Set the public/private bit for this sequence.
78 */
79 if (public == 1)
80 make_seq_public (mp, i);
81 else if (public == 0)
82 make_seq_private (mp, i);
83 else if (new_seq) {
84 /*
85 * If public == -1, then only set the
86 * public/private bit for new sequences.
87 */
88 if (is_readonly (mp))
89 make_seq_private (mp, i);
90 else
91 make_seq_public (mp, i);
92 }
93
94 mp->msgflags |= SEQMOD;
95 return 1;
96 }
97
98
99 /*
100 * Add a message to a (possibly new) sequence.
101 *
102 * If public == 1, make sequence public.
103 * If public == 0, make sequence private.
104 * If public == -1, leave the public/private bit alone for existing
105 * sequences. For new sequences, set this bit based
106 * on its readonly status.
107 *
108 * If error, return 0, else return 1.
109 */
110
111 int
112 seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
113 {
114 unsigned int i;
115 int j, new_seq = 1;
116
117 if (!seq_nameok (cp))
118 return 0;
119
120 /*
121 * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
122 */
123 if (!strcmp (current,cp))
124 mp->curmsg = msgnum;
125
126 /*
127 * Get the number for this sequence
128 */
129 for (i = 0; i < svector_size (mp->msgattrs); i++) {
130 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
131 new_seq = 0;
132 break;
133 }
134 }
135
136 /*
137 * If this is a new sequence, add a slot for it
138 */
139 if (new_seq) {
140 if (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
141 inform("strdup failed");
142 return 0;
143 }
144 }
145
146 /*
147 * If sequence is new, or zero flag is set, then first
148 * clear the bit for this sequence from all messages.
149 */
150 if ((new_seq || zero) && mp->nummsg > 0) {
151 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
152 clear_sequence (mp, i, j);
153 }
154
155 /*
156 * Now flip on the bit for this sequence
157 * for this particular message.
158 */
159 add_sequence (mp, i, msgnum);
160
161 /*
162 * Set the public/private bit for this sequence.
163 */
164 if (public == 1)
165 make_seq_public (mp, i);
166 else if (public == 0)
167 make_seq_private (mp, i);
168 else if (new_seq) {
169 /*
170 * If public == -1, then only set the
171 * public/private bit for new sequences.
172 */
173 if (is_readonly (mp))
174 make_seq_private (mp, i);
175 else
176 make_seq_public (mp, i);
177 }
178
179 mp->msgflags |= SEQMOD;
180 return 1;
181 }