1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/* seq_print.c -- Routines to print sequence information.
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
#include "h/mh.h"
#include "seq_getnum.h"
#include "seq_print.h"
#include "error.h"
#include "globals.h"
/*
* Print the sequence membership for the selected messages, for just
* the given sequence.
*/
int
seq_print_msgs (struct msgs *mp, int i, char *seqname, bool emptyok, bool rangeok)
{
int msgnum, r;
int found = 0;
if (i < 0)
i = seq_getnum (mp, seqname); /* may not exist */
/*
* Special processing for "cur" sequence. We assume that the
* "cur" sequence and mp->curmsg are in sync (see seq_add.c).
* This is returned, even if message doesn't exist or the
* folder is empty.
*/
if (!strcmp (current, seqname)) {
if (mp->curmsg)
printf("%s: %d\n", current, mp->curmsg);
return 1;
}
/*
* Now look for the sequence bit on all selected messages
*/
if (i >= 0) {
for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
if (!is_selected (mp, msgnum) || !in_sequence (mp, i, msgnum))
continue;
if (!found) {
printf("%s%s:", seqname,
is_seq_private(mp, i) ? " (private)" : "");
found = 1;
}
printf(" %d", msgnum);
if (rangeok) { /* turn "8 9 10 11" into "8-11" */
r = msgnum; /* start of range? */
for (++msgnum; msgnum <= mp->hghsel &&
(is_selected (mp, msgnum) && in_sequence (mp, i, msgnum));
msgnum++)
/* loop to end of range */ ;
if (msgnum - r > 1)
printf("-%d", msgnum - 1);
}
}
}
if (found) {
printf("\n");
} else if (emptyok) {
printf("%s%s: \n", seqname,
(i == -1) ? "" : (is_seq_private(mp, i) ? " (private)" : ""));
}
return 1;
}
|