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
|
#include "fmt.h"
#include "obuf.h"
/** Write an unsigned integer to the \c obuf with optional padding. */
int obuf_putunumw(obuf* out, unsigned long data, unsigned width, char pad,
unsigned base, const char* digits)
{
unsigned len = fmt_unumw(0, data, width, pad, base, digits);
char buf[len];
fmt_unumw(buf, data, width, pad, base, digits);
return obuf_write(out, buf, len);
}
/** Write an unsigned integer as decimal to the \c obuf with padding. */
int obuf_putuw(obuf* out, unsigned long data, unsigned width, char pad)
{
return obuf_putunumw(out, data, width, pad, 10, fmt_lcase_digits);
}
/** Write an unsigned integer as decimal to the \c obuf. */
int obuf_putu(obuf* out, unsigned long data)
{
return obuf_putunumw(out, data, 0, 0, 10, fmt_lcase_digits);
}
/** Write an unsigned integer as (lower-case) hexadecimal to the \c obuf
with padding. */
int obuf_putxw(obuf* out, unsigned long data, unsigned width, char pad)
{
return obuf_putunumw(out, data, width, pad, 16, fmt_lcase_digits);
}
/** Write an unsigned integer as (lower-case) hexadecimal to the \c obuf. */
int obuf_putx(obuf* out, unsigned long data)
{
return obuf_putunumw(out, data, 0, 0, 16, fmt_lcase_digits);
}
/** Write an unsigned integer as (upper-case) hexadecimal to the \c obuf
with padding. */
int obuf_putXw(obuf* out, unsigned long data, unsigned width, char pad)
{
return obuf_putunumw(out, data, width, pad, 16, fmt_ucase_digits);
}
/** Write an unsigned integer as (upper-case) hexadecimal to the \c obuf. */
int obuf_putX(obuf* out, unsigned long data)
{
return obuf_putunumw(out, data, 0, 0, 16, fmt_ucase_digits);
}
#ifdef SELFTEST_MAIN
MAIN
{
obuf_putuw(&outbuf, 10, 0, 0); NL();
obuf_putuw(&outbuf, 10, 5, ' '); NL();
obuf_putuw(&outbuf, 10, 5, '0'); NL();
obuf_putxw(&outbuf, 30, 0, 0); NL();
obuf_putxw(&outbuf, 30, 5, ' '); NL();
obuf_putxw(&outbuf, 30, 5, '0'); NL();
obuf_putXw(&outbuf, 30, 0, 0); NL();
obuf_putXw(&outbuf, 30, 5, ' '); NL();
obuf_putXw(&outbuf, 30, 5, '0'); NL();
}
#endif
#ifdef SELFTEST_EXP
10
10
00010
1e
1e
0001e
1E
1E
0001E
#endif
|