]>
diplodocus.org Git - nmh/blob - sbr/seq_list.c
1 /* seq_list.c -- Get all messages in a sequence and return them
2 * -- as a space separated list of message ranges.
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.
12 #include "seq_getnum.h"
15 /* allocate this much buffer space at a time */
16 #define MAXBUFFER 1024
18 /* static buffer to collect the sequence line */
19 static char *buffer
= NULL
;
24 seq_list(struct msgs
*mp
, char *seqname
)
29 /* On first invocation, allocate initial buffer space */
32 buffer
= mh_xmalloc ((size_t) len
);
36 * Special processing for "cur" sequence. We assume that the
37 * "cur" sequence and mp->curmsg are in sync (see seq_add.c).
38 * This is returned, even if message doesn't exist or the
41 if (!strcmp (current
, seqname
)) {
43 snprintf(buffer
, len
, "%s", m_name(mp
->curmsg
));
49 /* If the folder is empty, just return NULL */
53 /* Get the index of the sequence */
54 if ((seqnum
= seq_getnum (mp
, seqname
)) == -1)
59 for (i
= mp
->lowmsg
; i
<= mp
->hghmsg
; ++i
) {
61 * If message doesn't exist, or isn't in
62 * the sequence, then continue.
64 if (!does_exist(mp
, i
) || !in_sequence(mp
, seqnum
, i
))
68 * See if we need to enlarge buffer. Since we don't know
69 * exactly how many character this particular message range
70 * will need, we enlarge the buffer if we are within
71 * 50 characters of the end.
73 if (bp
- buffer
> len
- 50) {
77 newbuf
= mh_xrealloc (buffer
, (size_t) len
);
78 bp
= newbuf
+ (bp
- buffer
);
83 * If this is not the first message range in
84 * the list, first add a space.
89 strcpy(bp
, m_name(i
));
91 j
= i
; /* Remember beginning of message range */
94 * Scan to the end of this message range
96 for (++i
; i
<= mp
->hghmsg
&& does_exist(mp
, i
) && in_sequence(mp
, seqnum
, i
);
102 strcpy(bp
, m_name(i
- 1));
106 return bp
> buffer
? buffer
: NULL
;