From 4fee1d1c64c192f06a20351a4f6bc2075b01ec05 Mon Sep 17 00:00:00 2001 From: Aren Elchinyan Date: Thu, 18 Jan 2024 22:10:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20tool=5Fuint=5Fpow=20=D0=B8=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/tool.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/kernel/tool.c b/kernel/tool.c index a69882c..91a4285 100644 --- a/kernel/tool.c +++ b/kernel/tool.c @@ -160,29 +160,42 @@ int is_digit(char c) { return 0; } -int char_to_digit(char c) { - if (is_digit(c)) { return (int)(c - '0'); } +int64_t char_to_digit(char c) { + if (is_digit(c)) { return (int64_t)(c - '0'); } return -1; } +uint64_t tool_uint_pow(uint64_t d, uint64_t n) { + uint64_t result = 1; + for (uint64_t i = 0; i < n; i++) { result *= d; } + return result; +} + // Функция для форматированного вывода void tool_format(void (*putc)(char c), const char *format_string, va_list args) { while (*format_string != '\0') { if (*format_string == '%') { char buf[48]; + uint64_t i_temp = 0; uint64_t point = 0; char *arg_s; int64_t arg_d = 0; uint64_t arg_u = 0; - uint64_t width = 0; + int64_t width = 0; format_string++; - if (is_digit(*format_string)) { - width = char_to_digit(*format_string); + while (is_digit(*format_string)) { + arg_u += char_to_digit(*format_string); + + if (is_digit(*(format_string + 1))) { arg_u *= 10; } + format_string++; + i_temp++; } + width = arg_u; + if (*format_string == '\0') { break; // Неожиданный конец строки формата } @@ -192,6 +205,13 @@ void tool_format(void (*putc)(char c), const char *format_string, va_list args) case 'c': putc(va_arg(args, int)); break; case 's': arg_s = va_arg(args, char *); + + if (width) { width -= tool_strlen(arg_s); } + + while (width > 0) { + putc(' '); + width--; + } // Вывод каждого символа строки while (*arg_s != '\0') { putc(*arg_s);