mirror of
https://github.com/Fishwaldo/opensbi.git
synced 2025-06-28 17:18:37 +00:00
lib: sbi: implifying the parameters of printi
The information of sg/b/letbase can be obtained by the type character, simplifying the parameter by passing the type directly. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
parent
458fa74266
commit
05cbb6e908
1 changed files with 50 additions and 77 deletions
|
@ -184,15 +184,26 @@ static int prints(char **out, u32 *out_len, const char *string, int width,
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int printi(char **out, u32 *out_len, long long i, int b, int sg,
|
static int printi(char **out, u32 *out_len, long long i,
|
||||||
int width, int flags, int letbase)
|
int width, int flags, int type)
|
||||||
{
|
{
|
||||||
char *s, sign = 0, print_buf[PRINT_BUF_LEN];
|
|
||||||
int pc = 0;
|
int pc = 0;
|
||||||
u64 t;
|
char *s, sign = 0, letbase, print_buf[PRINT_BUF_LEN];
|
||||||
unsigned long long u = i;
|
unsigned long long u, b, t;
|
||||||
|
|
||||||
if (sg && b == 10) {
|
b = 10;
|
||||||
|
letbase = 'a';
|
||||||
|
if (type == 'o')
|
||||||
|
b = 8;
|
||||||
|
else if (type == 'x' || type == 'X' || type == 'p' || type == 'P') {
|
||||||
|
b = 16;
|
||||||
|
letbase &= ~0x20;
|
||||||
|
letbase |= type & 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
|
u = i;
|
||||||
|
sign = 0;
|
||||||
|
if (type == 'i' || type == 'd') {
|
||||||
if ((flags & PAD_SIGN) && i > 0)
|
if ((flags & PAD_SIGN) && i > 0)
|
||||||
sign = '+';
|
sign = '+';
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -242,9 +253,8 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
bool flags_done;
|
bool flags_done;
|
||||||
int width, flags, pc = 0;
|
int width, flags, pc = 0;
|
||||||
char scr[2], *tout;
|
char type, scr[2], *tout;
|
||||||
bool use_tbuf = (!out) ? true : false;
|
bool use_tbuf = (!out) ? true : false;
|
||||||
unsigned long long tmp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The console_tbuf is protected by console_out_lock and
|
* The console_tbuf is protected by console_out_lock and
|
||||||
|
@ -314,83 +324,46 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||||
}
|
}
|
||||||
if ((*format == 'd') || (*format == 'i')) {
|
if ((*format == 'd') || (*format == 'i')) {
|
||||||
pc += printi(out, out_len, va_arg(args, int),
|
pc += printi(out, out_len, va_arg(args, int),
|
||||||
10, 1, width, flags, '0');
|
width, flags, *format);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'x') {
|
if ((*format == 'u') || (*format == 'x') || (*format == 'X')) {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len, va_arg(args, unsigned int),
|
||||||
va_arg(args, unsigned int), 16, 0,
|
width, flags, *format);
|
||||||
width, flags, 'a');
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'X') {
|
if ((*format == 'p') || (*format == 'P')) {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len, (uintptr_t)va_arg(args, void*),
|
||||||
va_arg(args, unsigned int), 16, 0,
|
width, flags, *format);
|
||||||
width, flags, 'A');
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'u') {
|
if (*format == 'l') {
|
||||||
pc += printi(out, out_len,
|
type = 'i';
|
||||||
va_arg(args, unsigned int), 10, 0,
|
if (format[1] == 'l') {
|
||||||
width, flags, 'a');
|
++format;
|
||||||
continue;
|
if ((format[1] == 'u')
|
||||||
}
|
|| (format[1] == 'd') || (format[1] == 'i')
|
||||||
if (*format == 'p') {
|
|| (format[1] == 'x') || (format[1] == 'X')) {
|
||||||
pc += printi(out, out_len,
|
++format;
|
||||||
va_arg(args, unsigned long), 16, 0,
|
type = *format;
|
||||||
width, flags, 'a');
|
}
|
||||||
continue;
|
pc += printi(out, out_len, va_arg(args, long long),
|
||||||
}
|
width, flags, type);
|
||||||
if (*format == 'P') {
|
continue;
|
||||||
pc += printi(out, out_len,
|
|
||||||
va_arg(args, unsigned long), 16, 0,
|
|
||||||
width, flags, 'A');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (*format == 'l' && *(format + 1) == 'l') {
|
|
||||||
tmp = va_arg(args, unsigned long long);
|
|
||||||
if (*(format + 2) == 'u') {
|
|
||||||
format += 2;
|
|
||||||
pc += printi(out, out_len, tmp, 10, 0,
|
|
||||||
width, flags, 'a');
|
|
||||||
} else if (*(format + 2) == 'x') {
|
|
||||||
format += 2;
|
|
||||||
pc += printi(out, out_len, tmp, 16, 0,
|
|
||||||
width, flags, 'a');
|
|
||||||
} else if (*(format + 2) == 'X') {
|
|
||||||
format += 2;
|
|
||||||
pc += printi(out, out_len, tmp, 16, 0,
|
|
||||||
width, flags, 'A');
|
|
||||||
} else {
|
|
||||||
format += 1;
|
|
||||||
pc += printi(out, out_len, tmp, 10, 1,
|
|
||||||
width, flags, '0');
|
|
||||||
}
|
}
|
||||||
continue;
|
if ((format[1] == 'u')
|
||||||
} else if (*format == 'l') {
|
|| (format[1] == 'd') || (format[1] == 'i')
|
||||||
if (*(format + 1) == 'u') {
|
|| (format[1] == 'x') || (format[1] == 'X')) {
|
||||||
format += 1;
|
++format;
|
||||||
pc += printi(
|
type = *format;
|
||||||
out, out_len,
|
|
||||||
va_arg(args, unsigned long), 10,
|
|
||||||
0, width, flags, 'a');
|
|
||||||
} else if (*(format + 1) == 'x') {
|
|
||||||
format += 1;
|
|
||||||
pc += printi(
|
|
||||||
out, out_len,
|
|
||||||
va_arg(args, unsigned long), 16,
|
|
||||||
0, width, flags, 'a');
|
|
||||||
} else if (*(format + 1) == 'X') {
|
|
||||||
format += 1;
|
|
||||||
pc += printi(
|
|
||||||
out, out_len,
|
|
||||||
va_arg(args, unsigned long), 16,
|
|
||||||
0, width, flags, 'A');
|
|
||||||
} else {
|
|
||||||
pc += printi(out, out_len,
|
|
||||||
va_arg(args, long), 10, 1,
|
|
||||||
width, flags, '0');
|
|
||||||
}
|
}
|
||||||
|
if ((type == 'd') || (type == 'i'))
|
||||||
|
pc += printi(out, out_len, va_arg(args, long),
|
||||||
|
width, flags, type);
|
||||||
|
else
|
||||||
|
pc += printi(out, out_len, va_arg(args, unsigned long),
|
||||||
|
width, flags, type);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'c') {
|
if (*format == 'c') {
|
||||||
/* char are converted to int then pushed on the stack */
|
/* char are converted to int then pushed on the stack */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue