Implement printf

This commit is contained in:
Baptiste Wicht 2013-10-29 21:39:59 +01:00
parent 0b6c3b3b3c
commit 185c49c35b
3 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -1,4 +1,5 @@
#include <cstddef>
#include <cstdarg>
#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);
}

View File

@ -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*){