Fixed all previous bugs...however strange things happens when OS runs
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
#include "../drivers/tty.h"
|
||||
|
||||
int printf(const char *format, ...) {
|
||||
char buf[20],c,*s;
|
||||
uint8_t buf[20],c,*s;
|
||||
int val;
|
||||
int32_t uval;
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
for(size_t i = 0; i < strlen(format); i++) {
|
||||
for(size_t i = 0; i < strlen((uint8_t*)format); i++) {
|
||||
if(format[i] == '%') {
|
||||
i++;
|
||||
while(format[i] == ' ')
|
||||
@@ -32,23 +32,23 @@ int printf(const char *format, ...) {
|
||||
kprint(buf);
|
||||
break;
|
||||
case 'c':
|
||||
s = va_arg(ap, char*);
|
||||
s = va_arg(ap, uint8_t*);
|
||||
kprint_c(&c, 1, WHITE, BLACK);
|
||||
break;
|
||||
case 's':
|
||||
s = va_arg(ap, char*);
|
||||
s = va_arg(ap, uint8_t*);
|
||||
kprint(s);
|
||||
break;
|
||||
default:
|
||||
kprint_c((char*)format+1, 1, WHITE, BLACK);
|
||||
kprint_c((uint8_t*)format+1, 1, WHITE, BLACK);
|
||||
}
|
||||
} else
|
||||
kprint_c((char*)format+1, 1, WHITE, BLACK);
|
||||
kprint_c((uint8_t*)format+1, 1, WHITE, BLACK);
|
||||
}
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void puts(int8_t *buf) {
|
||||
void puts(const char *buf) {
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
int printf(const char *format, ...);
|
||||
void puts(uint8_t *buf);
|
||||
void puts(const char *buf);
|
||||
|
||||
#endif
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
// C library implementation
|
||||
|
||||
int32_t strcmp(const char *s1, const char *s2) {
|
||||
int32_t strcmp(const uint8_t *s1, const uint8_t *s2) {
|
||||
while ((*s1) && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (*(uint8_t*)s1 - *(uint8_t*)s2);
|
||||
}
|
||||
|
||||
char *itoa(int val, char *buf, int radix) {
|
||||
uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix) {
|
||||
uint32_t i = 0;
|
||||
uint32_t start = i;
|
||||
|
||||
@@ -34,19 +33,21 @@ char *itoa(int val, char *buf, int radix) {
|
||||
buf[i++]= a + 'a' - 10;
|
||||
} while(x /= radix);
|
||||
|
||||
char *s = buf+start;
|
||||
char *e = buf+(i-1);
|
||||
uint8_t *s = buf+start;
|
||||
uint8_t *e = buf+(i-1);
|
||||
|
||||
while(s < e) {
|
||||
char t = *s;
|
||||
uint8_t t = *s;
|
||||
*s = *e;
|
||||
*e = t;
|
||||
i++;
|
||||
e--;
|
||||
}
|
||||
buf[i] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *uitoa(uint32_t val, char *buf, int radix) {
|
||||
uint8_t *uitoa(uint32_t val, uint8_t *buf, uint32_t radix) {
|
||||
uint32_t i = 0;
|
||||
uint32_t start = i;
|
||||
uint32_t x = val;
|
||||
@@ -65,11 +66,11 @@ char *uitoa(uint32_t val, char *buf, int radix) {
|
||||
buf[i++] = a + 'a' - 10;
|
||||
} while(x /= radix);
|
||||
|
||||
char *s = buf+start;
|
||||
char *e = buf+(i+1);
|
||||
uint8_t *s = buf+start;
|
||||
uint8_t *e = buf+(i+1);
|
||||
|
||||
while(s < e) {
|
||||
char t = *s;
|
||||
uint8_t t = *s;
|
||||
*s = *e;
|
||||
*e = t;
|
||||
s++;
|
||||
@@ -80,7 +81,7 @@ char *uitoa(uint32_t val, char *buf, int radix) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
size_t strlen(const char *buf) {
|
||||
size_t strlen(const uint8_t *buf) {
|
||||
unsigned int i = 0;
|
||||
while(buf[i] != 0)
|
||||
i++;
|
||||
@@ -90,7 +91,7 @@ size_t strlen(const char *buf) {
|
||||
/* Worst memset implementation
|
||||
* i could find on the net.
|
||||
* however it works so... */
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
void *memset(void *s, uint32_t c, size_t n) {
|
||||
char *mem = (char*)s;
|
||||
|
||||
for(size_t i = 0; i < n; i++)
|
||||
@@ -109,14 +110,14 @@ void *memmove(void *dst, const void *src, size_t len) {
|
||||
return dstmem;
|
||||
}
|
||||
|
||||
void strupper(char *str) {
|
||||
void strupper(uint8_t *str) {
|
||||
for(unsigned int i = 0; i < strlen(str); i++) {
|
||||
if(str[i] == 'a' && str[i] < 'z')
|
||||
str[i] &= 0x4F;
|
||||
}
|
||||
}
|
||||
|
||||
void strlower(char *str) {
|
||||
void strlower(uint8_t *str) {
|
||||
for(unsigned int i = 0; i < strlen(str); i++) {
|
||||
if(str[i] == 'A' && str[i] < 'Z')
|
||||
str[i] |= 0x60;
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
#include <stdint.h> // For uinx_t
|
||||
#include <stddef.h> // For size_t
|
||||
|
||||
int32_t strcmp(const char *s1, const char *s2);
|
||||
char *itoa(int val, char *buf, int radix);
|
||||
char *uitoa(uint32_t val, char *buf, int radix);
|
||||
size_t strlen(const char *buf);
|
||||
void *memset(void *s, int c, size_t n);
|
||||
int32_t strcmp(const uint8_t *s1, const uint8_t *s2);
|
||||
uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix);
|
||||
uint8_t *uitoa(uint32_t val, uint8_t *buf, uint32_t radix);
|
||||
size_t strlen(const uint8_t *buf);
|
||||
void *memset(void *s, uint32_t c, size_t n);
|
||||
void *memmove(void *dst, const void *src, size_t len);
|
||||
void strupper(char *str);
|
||||
void strlower(char *str);
|
||||
void strupper(uint8_t *str);
|
||||
void strlower(uint8_t *str);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user