]>
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 /* allocate this much buffer space at a time */
13 #define MAXBUFFER 1024
15 /* static buffer to collect the sequence line */
16 static char *buffer
= NULL
;
21 seq_list(struct msgs
*mp
, char *seqname
)
26 /* On first invocation, allocate initial buffer space */
29 buffer
= mh_xmalloc ((size_t) len
);
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 snprintf(buffer
, len
, "%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 newbuf
= mh_xrealloc (buffer
, (size_t) len
);
75 bp
= newbuf
+ (bp
- buffer
);
80 * If this is not the first message range in
81 * the list, first add a space.
86 strcpy(bp
, m_name(i
));
88 j
= i
; /* Remember beginning of message range */
91 * Scan to the end of this message range
93 for (++i
; i
<= mp
->hghmsg
&& does_exist(mp
, i
) && in_sequence(mp
, seqnum
, i
);
99 strcpy(bp
, m_name(i
- 1));
103 return bp
> buffer
? buffer
: NULL
;