Commit bb788c78 authored by 若尘's avatar 若尘
Browse files

改格式

Showing with 8 additions and 15 deletions
+8 -15
......@@ -5,7 +5,7 @@
void print_init(void);
void printf(const char* fmt, ...);
void panic(const char* warning);
void panic(const char* warning,...);
void assert(bool condition, const char* warning);
#endif
\ No newline at end of file
......@@ -68,20 +68,19 @@ printptr(uint64 x)
void printf(const char *fmt, ...)
{
va_list ap;//va_list用于接收...的所有参数
int i,c,locking;//
int i,c,locking;
char *s;
locking = pr.locking;
locking = pr.locking;
if(locking)
spinlock_acquire(&pr.lock);
if (fmt == 0)
panic("null fmt");
va_start(ap, fmt);//初始化fmt
//关键函数,借鉴xv6
for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
va_start(ap, fmt);//初始化fmt
for(i = 0; (c = fmt[i] & 0xff) != 0; i++)
{
if(c != '%'){
uart_putc_sync(c);
continue;
......@@ -89,7 +88,8 @@ va_start(ap, fmt);//初始化fmt
c = fmt[++i] & 0xff;
if(c == 0)
break;
switch(c){
switch(c)
{
case 'd':
printint(va_arg(ap, int), 10, 1);
break;
......@@ -113,12 +113,6 @@ va_start(ap, fmt);//初始化fmt
uart_putc_sync('%');
uart_putc_sync(c);
break;
//条件: default: 这一部分是在 switch 语句中处理所有未明确处理的字符。
//在格式字符串中,如果 % 后面跟随的字符不是有效的格式说明符(如 d, x, s 等),程序会进入这一部分。
// 输出:
}
}
......@@ -129,7 +123,6 @@ va_start(ap, fmt);//初始化fmt
void panic(const char *s)
{
spinlock_acquire(&panic_lock);
pr.locking = 0;
printf("panic: %s\n", s); // 单次调用
panicked = 1; // freeze uart output from other CPUs
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment