2 ** seq_list.c -- Get all messages in a sequence and return them
3 ** -- as a space separated list of message ranges.
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.
13 /* allocate this much buffer space at a time */
14 #define MAXBUFFER 1024
16 /* static buffer to collect the sequence line */
17 static char *buffer = NULL;
22 seq_list(struct msgs *mp, char *seqname)
27 /* On first invocation, allocate initial buffer space */
30 buffer = mh_xmalloc((size_t) len);
34 ** Special processing for the cur sequence. We assume that the
35 ** cur sequence and mp->curmsg are in sync (see seq_add.c).
36 ** This is returned, even if message doesn't exist or the
39 if (strcmp(seq_cur, seqname)==0) {
41 sprintf(buffer, "%s", m_name(mp->curmsg));
47 /* If the folder is empty, just return NULL */
51 /* Get the index of the sequence */
52 if ((seqnum = seq_getnum(mp, seqname)) == -1)
57 for (i = mp->lowmsg; i <= mp->hghmsg; ++i) {
59 ** If message doesn't exist, or isn't in
60 ** the sequence, then continue.
62 if (!does_exist(mp, i) || !in_sequence(mp, seqnum, i))
66 ** See if we need to enlarge buffer. Since we don't know
67 ** exactly how many character this particular message range
68 ** will need, we enlarge the buffer if we are within
69 ** 50 characters of the end.
71 if (bp - buffer > len - 50) {
75 newbuf = mh_xrealloc(buffer, (size_t) len);
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) &&
95 in_sequence(mp, seqnum, i); ++i)
99 sprintf(bp, "-%s", m_name(i - 1));
103 return (bp > buffer? buffer : NULL);