vulcanos/kernel/libc/stdio.c

55 lines
1.4 KiB
C
Raw Normal View History

2019-07-03 12:37:16 +02:00
#include "stdio.h"
#include "string.h"
#include "../drivers/tty.h"
2019-07-03 12:37:16 +02:00
int printf(const char *format, ...) {
uint8_t buf[20],c,*s;
2019-07-03 12:37:16 +02:00
int val;
int32_t uval;
va_list ap;
va_start(ap, format);
for(size_t i = 0; i < strlen((uint8_t*)format); i++) {
2019-07-03 12:37:16 +02:00
if(format[i] == '%') {
i++;
while(format[i] == ' ')
i++;
switch(format[i]) {
case 'i':
val = va_arg(ap, int);
itoa(val, buf, 10);
kprint(buf);
2019-07-03 12:37:16 +02:00
break;
case 'x':
uval = va_arg(ap, uint32_t);
uitoa(uval, buf, 16);
kprint(buf);
2019-07-03 12:37:16 +02:00
break;
case 'd':
uval = va_arg(ap, uint32_t);
uitoa(uval, buf, 10);
kprint(buf);
2019-07-03 12:37:16 +02:00
break;
case 'c':
s = va_arg(ap, uint8_t*);
kprint_c(&c, 1, WHITE, BLACK);
2019-07-03 12:37:16 +02:00
break;
case 's':
s = va_arg(ap, uint8_t*);
kprint(s);
2019-07-03 12:37:16 +02:00
break;
default:
kprint_c((uint8_t*)format+i, 1, WHITE, BLACK);
2019-07-03 12:37:16 +02:00
}
} else
kprint_c((uint8_t*)format+i, 1, WHITE, BLACK);
2019-07-03 12:37:16 +02:00
}
va_end(ap);
return 0;
}
void puts(const char *buf) {
printf("%s\n", buf);
}