]> diplodocus.org Git - nmh/blob - sbr/seq_bits.c
sendsbr.c: Move interface to own file.
[nmh] / sbr / seq_bits.c
1 /* seq_bits.c -- return the snprintb() string for a sequence
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include "h/mh.h"
9 #include "seq_bits.h"
10
11
12 char *
13 seq_bits (struct msgs *mp)
14 {
15 size_t i;
16 size_t len;
17 static char buffer[BUFSIZ];
18
19 strncpy (buffer, MBITS, sizeof(buffer));
20
21 for (i = 0; i < svector_size (mp->msgattrs); i++) {
22 len = strlen (buffer);
23 snprintf (buffer + len, sizeof(buffer) - len,
24 "%c%s", FFATTRSLOT + 1 + (int) i,
25 svector_at (mp->msgattrs, i));
26 /*
27 * seq_bits() is used by seq_printdebug(), which passes an
28 * unsigned int bit vector to snprintb(). So limit the
29 * size of the return value accordingly. Even worse,
30 * snprintb() only uses characters up through ASCII space
31 * as the delimiter (the %c character above). So limit
32 * based on that.
33 */
34 if ((int) i == ' ' - FFATTRSLOT - 1) break;
35 }
36
37 return buffer;
38 }