2024-09-07 08:40:46 -04:00
|
|
|
#include "ctype.h"
|
|
|
|
#include "kprintf.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "terminal.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
static int print_flag(char flag, va_list *ap)
|
|
|
|
{
|
|
|
|
switch (flag) {
|
|
|
|
case '%':
|
|
|
|
return terminal_putchar('%');
|
|
|
|
case 'i':
|
|
|
|
return terminal_writelong(va_arg(*ap, int));
|
|
|
|
case 'd':
|
|
|
|
return terminal_writelong(va_arg(*ap, int));
|
|
|
|
case 'c':
|
|
|
|
return terminal_putchar(va_arg(*ap, int));
|
|
|
|
case 's':
|
|
|
|
return terminal_writestring(va_arg(*ap, char *));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int kvprintf(int level, const char *restrict format, va_list ap)
|
|
|
|
{
|
|
|
|
const char *start = format;
|
|
|
|
int ret = 0;
|
|
|
|
|
2024-09-07 23:03:50 -04:00
|
|
|
(void)level;
|
2024-09-07 08:40:46 -04:00
|
|
|
while (*start != '\0') {
|
|
|
|
if (*start == '%' && *(start + 1) != '\0') {
|
|
|
|
ret += print_flag(*(start + 1), &ap);
|
|
|
|
start++;
|
|
|
|
} else {
|
|
|
|
ret += terminal_putchar(*start);
|
|
|
|
}
|
|
|
|
start++;
|
|
|
|
}
|
2024-09-07 23:03:50 -04:00
|
|
|
update_cursor();
|
2024-09-07 08:40:46 -04:00
|
|
|
return ret;
|
|
|
|
}
|