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_xcalloc(len, sizeof(char));
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->lowoff; i <= mp->hghoff; ++i) {
58 /* If message isn't in the sequence, then continue */
59 if (!in_sequence(mp, seqnum, i))
63 ** See if we need to enlarge buffer. Since we don't know
64 ** exactly how many character this particular message range
65 ** will need, we enlarge the buffer if we are within
66 ** 50 characters of the end.
68 if (bp - buffer > len - 50) {
72 newbuf = mh_xrealloc(buffer, len);
73 bp = newbuf + (bp - buffer);
78 ** If this is not the first message range in
79 ** the list, first add a space.
84 sprintf(bp, "%s", m_name(i));
86 j = i; /* Remember beginning of message range */
89 ** Scan to the end of this message range
91 for (++i; i <= mp->hghoff && in_sequence(mp, seqnum, i); ++i)
95 sprintf(bp, "-%s", m_name(i - 1));
99 return (bp > buffer? buffer : NULL);