]> diplodocus.org Git - nmh/blob - sbr/seq_add.c
Ignore a.out.DSYM (this file sometims shows up when using the debugger)
[nmh] / sbr / seq_add.c
1
2 /*
3 * seq_add.c -- add message(s) to a sequence
4 *
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.
8 */
9
10 #include <h/mh.h>
11
12
13 /*
14 * Add all the SELECTED messages to a (possibly new) sequence.
15 *
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.
21 *
22 * If error, return 0, else return 1.
23 */
24
25 int
26 seq_addsel (struct msgs *mp, char *cp, int public, int zero)
27 {
28 int i, msgnum, new_seq = 1;
29
30 if (!seq_nameok (cp))
31 return 0;
32
33 /*
34 * We keep mp->curmsg and "cur" sequence in sync.
35 * See seq_list() and seq_init().
36 */
37 if (!strcmp (current,cp))
38 mp->curmsg = mp->hghsel;
39
40 /*
41 * Get the number for this sequence
42 */
43 for (i = 0; mp->msgattrs[i]; i++) {
44 if (!strcmp (mp->msgattrs[i], cp)) {
45 new_seq = 0;
46 break;
47 }
48 }
49
50 /*
51 * If this is a new sequence, add a slot for it
52 */
53 if (new_seq) {
54 if (i >= NUMATTRS) {
55 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
56 return 0;
57 }
58 if (!(mp->msgattrs[i] = strdup (cp))) {
59 advise (NULL, "strdup failed");
60 return 0;
61 }
62 mp->msgattrs[i + 1] = NULL;
63 }
64
65 /*
66 * If sequence is new, or zero flag is set, then first
67 * clear the bit for this sequence from all messages.
68 */
69 if (new_seq || zero) {
70 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
71 clear_sequence (mp, i, msgnum);
72 }
73
74 /*
75 * Now flip on the bit for this sequence
76 * for all selected messages.
77 */
78 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
79 if (is_selected (mp, msgnum))
80 add_sequence (mp, i, msgnum);
81
82 /*
83 * Set the public/private bit for this sequence.
84 */
85 if (public == 1)
86 make_seq_public (mp, i);
87 else if (public == 0)
88 make_seq_private (mp, i);
89 else if (new_seq) {
90 /*
91 * If public == -1, then only set the
92 * public/private bit for new sequences.
93 */
94 if (is_readonly (mp))
95 make_seq_private (mp, i);
96 else
97 make_seq_public (mp, i);
98 }
99
100 mp->msgflags |= SEQMOD;
101 return 1;
102 }
103
104
105 /*
106 * Add a message to a (possibly new) sequence.
107 *
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.
113 *
114 * If error, return 0, else return 1.
115 */
116
117 int
118 seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
119 {
120 int i, j, new_seq = 1;
121
122 if (!seq_nameok (cp))
123 return 0;
124
125 /*
126 * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
127 */
128 if (!strcmp (current,cp))
129 mp->curmsg = msgnum;
130
131 /*
132 * Get the number for this sequence
133 */
134 for (i = 0; mp->msgattrs[i]; i++) {
135 if (!strcmp (mp->msgattrs[i], cp)) {
136 new_seq = 0;
137 break;
138 }
139 }
140
141 /*
142 * If this is a new sequence, add a slot for it
143 */
144 if (new_seq) {
145 if (i >= NUMATTRS) {
146 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
147 return 0;
148 }
149 if (!(mp->msgattrs[i] = strdup (cp))) {
150 advise (NULL, "strdup failed");
151 return 0;
152 }
153 mp->msgattrs[i + 1] = NULL;
154 }
155
156 /*
157 * If sequence is new, or zero flag is set, then first
158 * clear the bit for this sequence from all messages.
159 */
160 if (new_seq || zero) {
161 for (j = mp->lowmsg; j <= mp->hghmsg; j++)
162 clear_sequence (mp, i, j);
163 }
164
165 /*
166 * Now flip on the bit for this sequence
167 * for this particular message.
168 */
169 add_sequence (mp, i, msgnum);
170
171 /*
172 * Set the public/private bit for this sequence.
173 */
174 if (public == 1)
175 make_seq_public (mp, i);
176 else if (public == 0)
177 make_seq_private (mp, i);
178 else if (new_seq) {
179 /*
180 * If public == -1, then only set the
181 * public/private bit for new sequences.
182 */
183 if (is_readonly (mp))
184 make_seq_private (mp, i);
185 else
186 make_seq_public (mp, i);
187 }
188
189 mp->msgflags |= SEQMOD;
190 return 1;
191 }