]>
diplodocus.org Git - nmh/blob - sbr/seq_list.c
3 * seq_list.c -- Get all messages in a sequence and return them
4 * -- as a space separated list of message ranges.
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
16 /* allocate this much buffer space at a time */
17 #define MAXBUFFER 1024
19 /* static buffer to collect the sequence line */
20 static char *buffer
= NULL
;
25 seq_list(struct msgs
*mp
, char *seqname
)
30 /* On first invocation, allocate initial buffer space */
33 buffer
= mh_xmalloc ((size_t) len
);
37 * Special processing for "cur" sequence. We assume that the
38 * "cur" sequence and mp->curmsg are in sync (see seq_add.c).
39 * This is returned, even if message doesn't exist or the
42 if (!strcmp (current
, seqname
)) {
44 sprintf(buffer
, "%s", m_name(mp
->curmsg
));
50 /* If the folder is empty, just return NULL */
54 /* Get the index of the sequence */
55 if ((seqnum
= seq_getnum (mp
, seqname
)) == -1)
60 for (i
= mp
->lowmsg
; i
<= mp
->hghmsg
; ++i
) {
62 * If message doesn't exist, or isn't in
63 * the sequence, then continue.
65 if (!does_exist(mp
, i
) || !in_sequence(mp
, seqnum
, i
))
69 * See if we need to enlarge buffer. Since we don't know
70 * exactly how many character this particular message range
71 * will need, we enlarge the buffer if we are within
72 * 50 characters of the end.
74 if (bp
- buffer
> len
- 50) {
78 newbuf
= mh_xrealloc (buffer
, (size_t) len
);
79 bp
= newbuf
+ (bp
- buffer
);
84 * If this is not the first message range in
85 * the list, first add a space.
90 sprintf(bp
, "%s", m_name(i
));
92 j
= i
; /* Remember beginning of message range */
95 * Scan to the end of this message range
97 for (++i
; i
<= mp
->hghmsg
&& does_exist(mp
, i
) && in_sequence(mp
, seqnum
, i
);
102 sprintf(bp
, "-%s", m_name(i
- 1));
106 return (bp
> buffer
? buffer
: NULL
);