2006-04-19 17:16:49 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Robert Nordier
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2006 M. Warner Losh
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are freely
|
|
|
|
* permitted provided that the above copyright notice and this
|
|
|
|
* paragraph and the following disclaimer are duplicated in all
|
|
|
|
* such forms.
|
|
|
|
*
|
|
|
|
* This software is provided "AS IS" and without any express or
|
|
|
|
* implied warranties, including, without limitation, the implied
|
|
|
|
* warranties of merchantability and fitness for a particular
|
|
|
|
* purpose.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "lib.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
printf(const char *fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
const char *hex = "0123456789abcdef";
|
|
|
|
char buf[10];
|
|
|
|
char *s;
|
|
|
|
unsigned u;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
while ((c = *fmt++)) {
|
|
|
|
if (c == '%') {
|
|
|
|
c = *fmt++;
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
2006-10-20 09:12:05 +00:00
|
|
|
xputchar(va_arg(ap, int));
|
2006-04-19 17:16:49 +00:00
|
|
|
continue;
|
|
|
|
case 's':
|
|
|
|
for (s = va_arg(ap, char *); *s; s++)
|
2006-10-20 09:12:05 +00:00
|
|
|
xputchar(*s);
|
2006-04-19 17:16:49 +00:00
|
|
|
continue;
|
2006-10-20 09:12:05 +00:00
|
|
|
case 'd': /* A lie, always prints unsigned */
|
2006-04-19 17:16:49 +00:00
|
|
|
case 'u':
|
|
|
|
u = va_arg(ap, unsigned);
|
|
|
|
s = buf;
|
|
|
|
do
|
|
|
|
*s++ = '0' + u % 10U;
|
|
|
|
while (u /= 10U);
|
|
|
|
dumpbuf:;
|
|
|
|
while (--s >= buf)
|
2006-10-20 09:12:05 +00:00
|
|
|
xputchar(*s);
|
2006-04-19 17:16:49 +00:00
|
|
|
continue;
|
|
|
|
case 'x':
|
|
|
|
u = va_arg(ap, unsigned);
|
|
|
|
s = buf;
|
|
|
|
do
|
|
|
|
*s++ = hex[u & 0xfu];
|
|
|
|
while (u >>= 4);
|
|
|
|
goto dumpbuf;
|
|
|
|
}
|
|
|
|
}
|
2006-10-20 09:12:05 +00:00
|
|
|
xputchar(c);
|
2006-04-19 17:16:49 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|