Last active
February 9, 2021 21:59
-
-
Save vkoskiv/61c7599861a2e763f7859c8c3103c298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void kprintf(const char *fmt, ...) { | |
if (!fmt) return; | |
size_t len = strlen(fmt); | |
va_list vl; | |
va_start(vl, fmt); | |
for (size_t i = 0; i < len; ++i) { | |
if (fmt[i] == '%') { | |
// I just completely made these up, will fix later I guess | |
switch (fmt[i + 1]) { | |
case 'h': { // Hex | |
i += 2; | |
kprintaddr((void *)va_arg(vl, uint32_t)); | |
} break; | |
case 'i': { // Int | |
i += 2; | |
kprintnum((uint64_t)va_arg(vl, uint64_t)); | |
} break; | |
case 's': { // string | |
i += 2; | |
char *str = va_arg(vl, char *); | |
size_t str_len = strlen(str); | |
terminal_write(str, str_len); | |
} break; | |
default: | |
continue; | |
break; | |
} | |
} | |
terminal_putchar(fmt[i]); | |
} | |
va_end(vl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment