feature (kernel): Implemented variable numeric_specifiers

This commit is contained in:
antifallobst 2023-02-23 11:34:01 +01:00
parent 547f74758e
commit 49a48c70ca
1 changed files with 16 additions and 10 deletions

View File

@ -50,12 +50,17 @@ uint64_t variadic_format_size(string_t string, va_list args) {
buffer_in++; buffer_in++;
if (*buffer_in == '.') { if (*buffer_in == '.') {
buffer_in++; buffer_in++;
if (*buffer_in == '*') {
buffer_in++;
numeric_specifier = va_arg(args, uint64_t);
} else {
while (*buffer_in > '0' && *buffer_in < '9') { while (*buffer_in > '0' && *buffer_in < '9') {
numeric_specifier *= 10; numeric_specifier *= 10;
numeric_specifier += *buffer_in - '0'; numeric_specifier += *buffer_in - '0';
buffer_in++; buffer_in++;
} }
} }
}
switch(*buffer_in) { switch(*buffer_in) {
case '%': { case '%': {
@ -67,8 +72,6 @@ uint64_t variadic_format_size(string_t string, va_list args) {
uint64_t strlen = string_length(va_arg(args, string_t)); uint64_t strlen = string_length(va_arg(args, string_t));
if (numeric_specifier > 0) { if (numeric_specifier > 0) {
strlen = MIN(strlen, numeric_specifier); strlen = MIN(strlen, numeric_specifier);
} else {
strlen = numeric_specifier;
} }
length += strlen; length += strlen;
@ -176,12 +179,17 @@ void variadic_format(string_t output, string_t string, va_list args) {
buffer_in++; buffer_in++;
if (*buffer_in == '.') { if (*buffer_in == '.') {
buffer_in++; buffer_in++;
if (*buffer_in == '*') {
buffer_in++;
numeric_specifier = va_arg(args, uint64_t);
} else {
while (*buffer_in > '0' && *buffer_in < '9') { while (*buffer_in > '0' && *buffer_in < '9') {
numeric_specifier *= 10; numeric_specifier *= 10;
numeric_specifier += *buffer_in - '0'; numeric_specifier += *buffer_in - '0';
buffer_in++; buffer_in++;
} }
} }
}
switch(*buffer_in) { switch(*buffer_in) {
case '%': { case '%': {
@ -196,8 +204,6 @@ void variadic_format(string_t output, string_t string, va_list args) {
if (numeric_specifier > 0) { if (numeric_specifier > 0) {
strlen = MIN(strlen, numeric_specifier); strlen = MIN(strlen, numeric_specifier);
} else {
strlen = numeric_specifier;
} }
memory_copy((void*)str, buffer_out, strlen); memory_copy((void*)str, buffer_out, strlen);