3 * seq_list.c -- Get all messages in a sequence and return them
4 * -- as a space separated list of message ranges.
11 /* allocate this much buffer space at a time */
12 #define MAXBUFFER 1024
14 /* static buffer to collect the sequence line */
15 static char *buffer = NULL;
20 seq_list(struct msgs *mp, char *seqname)
25 /* On first invocation, allocate initial buffer space */
28 if (!(buffer = malloc ((size_t) len)))
29 adios (NULL, "unable to malloc storage in seq_list");
33 * Special processing for "cur" sequence. We assume that the
34 * "cur" sequence and mp->curmsg are in sync (see seq_add.c).
35 * This is returned, even if message doesn't exist or the
38 if (!strcmp (current, seqname)) {
40 sprintf(buffer, "%s", m_name(mp->curmsg));
46 /* If the folder is empty, just return NULL */
50 /* Get the index of the sequence */
51 if ((seqnum = seq_getnum (mp, seqname)) == -1)
56 for (i = mp->lowmsg; i <= mp->hghmsg; ++i) {
58 * If message doesn't exist, or isn't in
59 * the sequence, then continue.
61 if (!does_exist(mp, i) || !in_sequence(mp, seqnum, i))
65 * See if we need to enlarge buffer. Since we don't know
66 * exactly how many character this particular message range
67 * will need, we enlarge the buffer if we are within
68 * 50 characters of the end.
70 if (bp - buffer > len - 50) {
74 if (!(newbuf = realloc (buffer, (size_t) len)))
75 adios (NULL, "unable to realloc storage in seq_list");
76 bp = newbuf + (bp - buffer);
81 * If this is not the first message range in
82 * the list, first add a space.
87 sprintf(bp, "%s", m_name(i));
89 j = i; /* Remember beginning of message range */
92 * Scan to the end of this message range
94 for (++i; i <= mp->hghmsg && does_exist(mp, i) && in_sequence(mp, seqnum, i);
99 sprintf(bp, "-%s", m_name(i - 1));
103 return (bp > buffer? buffer : NULL);