提交 84878e55 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Add %lx to cprintf.

上级 b31a215b
...@@ -17,12 +17,12 @@ static struct { ...@@ -17,12 +17,12 @@ static struct {
static void static void
printint(void (*putch) (void*, char), void *putarg, printint(void (*putch) (void*, char), void *putarg,
int xx, int base, int sign) u64 xx, int base, int sign)
{ {
static char digits[] = "0123456789abcdef"; static char digits[] = "0123456789abcdef";
char buf[16]; char buf[16];
int i; int i;
u32 x; u64 x;
if(sign && (sign = xx < 0)) if(sign && (sign = xx < 0))
x = -xx; x = -xx;
...@@ -49,7 +49,7 @@ writecons(void *arg, char c) ...@@ -49,7 +49,7 @@ writecons(void *arg, char c)
cgaputc(c); cgaputc(c);
} }
// Only understands %d, %x, %s. // Only understands %d, %x, %s, %lx.
void void
vprintfmt(void (*putch) (void*, char), void *putarg, vprintfmt(void (*putch) (void*, char), void *putarg,
const char *fmt, va_list ap) const char *fmt, va_list ap)
...@@ -71,6 +71,9 @@ vprintfmt(void (*putch) (void*, char), void *putarg, ...@@ -71,6 +71,9 @@ vprintfmt(void (*putch) (void*, char), void *putarg,
printint(putch, putarg, va_arg(ap, u32), 10, 1); printint(putch, putarg, va_arg(ap, u32), 10, 1);
} else if(c == 'x') { } else if(c == 'x') {
printint(putch, putarg, va_arg(ap, u32), 16, 0); printint(putch, putarg, va_arg(ap, u32), 16, 0);
} else if(c == 'l') {
state = 'l';
continue;
} else if(c == 's'){ } else if(c == 's'){
s = (char*) va_arg(ap, char*); s = (char*) va_arg(ap, char*);
if(s == 0) if(s == 0)
...@@ -89,6 +92,16 @@ vprintfmt(void (*putch) (void*, char), void *putarg, ...@@ -89,6 +92,16 @@ vprintfmt(void (*putch) (void*, char), void *putarg,
putch(putarg, c); putch(putarg, c);
} }
state = 0; state = 0;
} else if(state == 'l') {
if(c == 'x') {
printint(putch, putarg, va_arg(ap, u64), 16, 0);
}
else {
// Unknown % sequence. Print it to draw attention.
putch(putarg, '%');
putch(putarg, c);
}
state = 0;
} }
} }
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论