diff --git a/headers/kprintf.h b/headers/kprintf.h index c90ec5f..83fc8f0 100644 --- a/headers/kprintf.h +++ b/headers/kprintf.h @@ -13,7 +13,7 @@ enum print_level { KERN_DEBUG, KERN_DEFAULT, KERN_CONT -} +}; -int kprintf(enum print_level level, const char *restrict format, ...); -int vprintf(enum print_level level, const char *restrict format, va_list ap); \ No newline at end of file +int kprintf(int level, const char *restrict format, ...); +int kvprintf(int level, const char *restrict format, va_list ap); \ No newline at end of file diff --git a/headers/terminal.h b/headers/terminal.h index 49c8c70..9154f16 100644 --- a/headers/terminal.h +++ b/headers/terminal.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include + enum vga_color { VGA_COLOR_BLACK = 0, VGA_COLOR_BLUE = 1, @@ -22,6 +26,7 @@ enum vga_color { void terminal_initialize(void); void terminal_setcolor(uint8_t color); void terminal_putentryat(char c, uint8_t color, size_t x, size_t y); -void terminal_putchar(char c); -void terminal_write(const char* data, size_t size); -void terminal_writestring(const char* data); \ No newline at end of file +int terminal_putchar(char c); +int terminal_write(const char* data, size_t size); +int terminal_writestring(const char* data); +int terminal_writelong(long number); \ No newline at end of file diff --git a/src/kprint/kprintf.c b/src/kprint/kprintf.c index 20a80c3..2eafaa0 100644 --- a/src/kprint/kprintf.c +++ b/src/kprint/kprintf.c @@ -1,4 +1,4 @@ -#include "kprint.h" +#include "kprintf.h" #include "string.h" #include "terminal.h" #include "ctype.h" @@ -11,7 +11,7 @@ int kprintf(int level, const char *restrict format, ...) int i; va_start(va, format); - i = ft_vdprintf(level, format, va); + i = kvprintf(level, format, va); va_end(va); return (i); diff --git a/src/kprint/kvprintf.c b/src/kprint/kvprintf.c index 1730928..abb32fb 100644 --- a/src/kprint/kvprintf.c +++ b/src/kprint/kvprintf.c @@ -1,7 +1,8 @@ -#include "../../headers/kprint.h" -#include "../../headers/string.h" -#include "../../headers/terminal.h" -#include "../../headers/ctype.h" +#include "kprintf.h" +#include "string.h" +#include "terminal.h" +#include "ctype.h" +#include "stdlib.h" #include @@ -30,9 +31,9 @@ int kvprintf(int level, const char *restrict format, va_list ap) flag = strchr(start, '%'); if (flag != NULL) { padding = atoll(start + 1); - for (; isdigit(*padding); padding++); - ret += print_flag(*padding, ap); - start = padding + 1; + for (; isdigit(*flag); flag++); + ret += print_flag(*flag, ap); + start = flag + 1; } else { terminal_writestring(start); diff --git a/src/string/strchr.c b/src/string/strchr.c index e06e9f1..4de6e27 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -1,8 +1,8 @@ - +#include char *strchr(const char *str, int c) { - const char *start = str; + char *start = (char *) str; while (*start) { diff --git a/src/string/strstr.c b/src/string/strstr.c index b035d18..7353632 100644 --- a/src/string/strstr.c +++ b/src/string/strstr.c @@ -1,6 +1,10 @@ +#include "string.h" + +#include + char *strstr(const char *haystack, const char *needle) { - const char *start = haystack; + char *start = (char *) haystack; size_t len; len = strlen(needle); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index bed1a42..bcfd583 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -1,5 +1,9 @@ #include "../../headers/terminal.h" +#include +#include +#include + static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) { return fg | bg << 4; @@ -51,7 +55,7 @@ void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) terminal_buffer[index] = vga_entry(c, color); } -void terminal_putchar(char c) +int terminal_putchar(char c) { terminal_putentryat(c, terminal_color, terminal_column, terminal_row); if (++terminal_column == VGA_WIDTH) { @@ -59,20 +63,25 @@ void terminal_putchar(char c) if (++terminal_row == VGA_HEIGHT) terminal_row = 0; } + return 1; } -void terminal_write(const char* data, size_t size) +int terminal_write(const char* data, size_t size) { - for (size_t i = 0; i < size; i++) + size_t i; + for (i = 0; i < size; i++) terminal_putchar(data[i]); + return (int) i; } -void terminal_writestring(const char* data) +int terminal_writestring(const char* data) { - terminal_write(data, strlen(data)); + size_t len = strlen(data); + terminal_write(data, len); + return len; } -void terminal_writelong(long number) +int terminal_writelong(long number) { unsigned long number2 = number;