]> diplodocus.org Git - nmh/blob - sbr/snprintb.h
Improve fmttest output
[nmh] / sbr / snprintb.h
1 /* snprintb.h -- snprintf a %b string
2 *
3 * This code is Copyright (c) 2017, 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 * Convert a set of bit flags to printable format.
9 *
10 * Arguments:
11 *
12 * buffer - Buffer to output string to.
13 * size - Size of buffer in bytes. Buffer is always NUL terminated.
14 * flags - Binary flags to output
15 * bitfield - Textual representation of bits to output. This string
16 * is in the following format:
17 *
18 * Option byte 0x01 STRING1 0x02 STRING2 ....
19 *
20 * The first byte is an option byte to snprintb(). Currently the only option
21 * supported is 0x08, which indicates that the flags should be output in
22 * octal format; if the option byte is any other value, the flags will be
23 * output in hexadecimal.
24 *
25 * After the option bytes are series of text strings, prefixed by the number
26 * of the bit they correspond to. For example, the bitfield string:
27 *
28 * "\020\01FLAG1\02FLAG2\03FLAG3\04FLAG4"
29 *
30 * will output the following string if "flags" is set to 0x09:
31 *
32 * 0x2<FLAG1,FLAG4>
33 *
34 * You don't have to use octal in the bitfield string, that's just the
35 * convention currently used by the nmh code. The order of flags in the
36 * bitfield string is not significant, but again, general convention is
37 * from least significant bit to most significant.
38 */
39 char *snprintb(char *, size_t, unsigned, char *);