* Copyright (c) 1991 The Regents of the University of California.
* %sccs.include.redist.c%
* @(#)printf.c 5.7 (Berkeley) %G%
* Scaled down version of printf(3).
* The format %b is supported to decode error registers.
* printf("reg=%b\n", regval, "<base><arg>*");
* where <base> is the output base expressed as a control character, e.g.
* \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
* the first of which gives the bit number to be inspected (origin 1), and
* the next characters (up to a control character, i.e. a character <= 32),
* give the name of the register. Thus:
* printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
* Note that stdarg.h and the ANSI style va_start macro is used for both
* ANSI and traditional C compilers.
#include <machine/stdarg.h>
static void kprintn
__P((u_long
, int));
printf(const char *fmt
, ...)
printf(fmt
/* , va_alist */)
while ((ch
= *fmt
++) != '%') {
reswitch
: switch (ch
= *fmt
++) {
for (set
= 0; n
= *p
++;) {
if (ul
& (1 << (n
- 1))) {
putchar(set
? ',' : '<');
for (; (n
= *p
) > ' '; ++p
)
va_arg(ap
, long) : va_arg(ap
, int);
va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
/* hold a long in base 8 */
char *p
, buf
[(sizeof(long) * NBBY
/ 3) + 1];
*p
++ = "0123456789abcdef"[ul
% base
];