]>
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.
15 /* allocate this much buffer space at a time */
16 #define MAXBUFFER 1024
18 /* static buffer to collect the sequence line */
19 static char *buffer
= NULL
;
24 seq_list(struct msgs
*mp
, char *seqname
)
29 /* On first invocation, allocate initial buffer space */
32 if (!(buffer
= malloc ((size_t) len
)))
33 adios (NULL
, "unable to malloc storage in seq_list");
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 if (!(newbuf
= realloc (buffer
, (size_t) len
)))
79 adios (NULL
, "unable to realloc storage in seq_list");
80 bp
= newbuf
+ (bp
- buffer
);
85 * If this is not the first message range in
86 * the list, first add a space.
91 sprintf(bp
, "%s", m_name(i
));
93 j
= i
; /* Remember beginning of message range */
96 * Scan to the end of this message range
98 for (++i
; i
<= mp
->hghmsg
&& does_exist(mp
, i
) && in_sequence(mp
, seqnum
, i
);
103 sprintf(bp
, "-%s", m_name(i
- 1));
107 return (bp
> buffer
? buffer
: NULL
);