source: trunk/third/nmh/sbr/snprintb.c @ 12455

Revision 12455, 649 bytes checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12454, which included commits to RCS files with non-trunk default branches.
Line 
1
2/*
3 * snprintb.c -- snprintf a %b string
4 *
5 * $Id: snprintb.c,v 1.1.1.1 1999-02-07 18:14:10 danw Exp $
6 */
7
8#include <h/mh.h>
9
10
11char *
12snprintb (char *buffer, size_t n, unsigned v, char *bits)
13{
14    register int i, j;
15    register char c, *bp;
16
17    snprintf (buffer, n, bits && *bits == 010 ? "0%o" : "0x%x", v);
18    bp = buffer + strlen(buffer);
19
20    if (bits && *++bits) {
21        j = 0;
22        *bp++ = '<';
23        while ((i = *bits++))
24            if (v & (1 << (i - 1))) {
25                if (j++)
26                    *bp++ = ',';
27                for (; (c = *bits) > 32; bits++)
28                    *bp++ = c;
29            }
30            else
31                for (; *bits > 32; bits++)
32                    continue;
33        *bp++ = '>';
34        *bp = 0;
35    }
36
37    return buffer;
38}
Note: See TracBrowser for help on using the repository browser.