diff --git a/kernel/include/console.hpp b/kernel/include/console.hpp index 3d0af954..b4cbe05e 100644 --- a/kernel/include/console.hpp +++ b/kernel/include/console.hpp @@ -12,5 +12,6 @@ void k_print(const char* string); void k_print(std::size_t number); void k_print_line(); void k_print_line(const char* string); +void k_printf(const char* fmt, ...); #endif diff --git a/kernel/src/console.cpp b/kernel/src/console.cpp index a449c1d3..9eaf73f1 100644 --- a/kernel/src/console.cpp +++ b/kernel/src/console.cpp @@ -1,4 +1,5 @@ #include +#include #include "console.hpp" #include "types.hpp" @@ -109,3 +110,28 @@ void wipeout(){ current_line = 0; current_column = 0; } + +void k_printf(const char* fmt, ...){ + va_list va; + va_start(va, fmt); + + char ch; + + while ((ch=*(fmt++))) { + if(ch != '%'){ + k_print(ch); + } else { + ch = *(fmt++); + + if(ch == 'd'){ + auto arg = va_arg(va, std::size_t); + k_print(arg); + } else if(ch == 's'){ + auto arg = va_arg(va, const char*); + k_print(arg); + } + } + } + + va_end(va); +} diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index b837f902..0bb70517 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -100,9 +100,7 @@ void exec_command(){ } } - k_print("The command \""); - k_print(current_input); - k_print("\" does not exist \n"); + k_printf("The command \"%s\" does not exist\n", current_input); } void clear_command(const char*){