Removed the space between function names and the opening parenthesis.
[mmh] / sbr / snprintb.c
1 /*
2 ** snprintb.c -- snprintf a %b string
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11
12 char *
13 snprintb(char *buffer, size_t n, unsigned v, char *bits)
14 {
15         register int i, j;
16         register char c, *bp;
17
18         snprintf(buffer, n, bits && *bits == 010 ? "0%o" : "0x%x", v);
19         bp = buffer + strlen(buffer);
20
21         if (bits && *++bits) {
22                 j = 0;
23                 *bp++ = '<';
24                 while ((i = *bits++))
25                         if (v & (1 << (i - 1))) {
26                                 if (j++)
27                                         *bp++ = ',';
28                                 for (; (c = *bits) > 32; bits++)
29                                         *bp++ = c;
30                         } else
31                                 for (; *bits > 32; bits++)
32                                         continue;
33                 *bp++ = '>';
34                 *bp = 0;
35         }
36
37         return buffer;
38 }