3 * seq_list.c -- Get all messages in a sequence and return them
4 * -- as a space separated list of message ranges.
6 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
14 /* allocate this much buffer space at a time */
15 #define MAXBUFFER 1024
17 /* static buffer to collect the sequence line */
18 static char *buffer = NULL;
23 seq_list(struct msgs *mp, char *seqname)
28 /* On first invocation, allocate initial buffer space */
31 buffer = mh_xmalloc ((size_t) len);
35 * Special processing for "cur" sequence. We assume that the
36 * "cur" sequence and mp->curmsg are in sync (see seq_add.c).
37 * This is returned, even if message doesn't exist or the
40 if (!strcmp (current, seqname)) {
42 sprintf(buffer, "%s", m_name(mp->curmsg));
48 /* If the folder is empty, just return NULL */
52 /* Get the index of the sequence */
53 if ((seqnum = seq_getnum (mp, seqname)) == -1)
58 for (i = mp->lowmsg; i <= mp->hghmsg; ++i) {
60 * If message doesn't exist, or isn't in
61 * the sequence, then continue.
63 if (!does_exist(mp, i) || !in_sequence(mp, seqnum, i))
67 * See if we need to enlarge buffer. Since we don't know
68 * exactly how many character this particular message range
69 * will need, we enlarge the buffer if we are within
70 * 50 characters of the end.
72 if (bp - buffer > len - 50) {
76 newbuf = mh_xrealloc (buffer, (size_t) len);
77 bp = newbuf + (bp - buffer);
82 * If this is not the first message range in
83 * the list, first add a space.
88 sprintf(bp, "%s", m_name(i));
90 j = i; /* Remember beginning of message range */
93 * Scan to the end of this message range
95 for (++i; i <= mp->hghmsg && does_exist(mp, i) && in_sequence(mp, seqnum, i);
100 sprintf(bp, "-%s", m_name(i - 1));
104 return (bp > buffer? buffer : NULL);