diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-16 18:07:24 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-16 18:07:24 +0200 |
commit | bb2dd23f315bafa7b0b64845c2fe25d7a0893b10 (patch) | |
tree | 51657cd1ad8b6f1d5941604e75c251a246809034 /src/common | |
parent | 3d6a857b9186ef6304ea6cf04627c2b787169f29 (diff) | |
download | kogata-bb2dd23f315bafa7b0b64845c2fe25d7a0893b10.tar.gz kogata-bb2dd23f315bafa7b0b64845c2fe25d7a0893b10.zip |
Got Lua running \o/
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/libc/printf.c | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/src/common/libc/printf.c b/src/common/libc/printf.c index d1671c3..0498b2d 100644 --- a/src/common/libc/printf.c +++ b/src/common/libc/printf.c @@ -1,4 +1,5 @@ #include <stdarg.h> +#include <stdbool.h> #include <kogata/printf.h> @@ -29,31 +30,56 @@ int vsnprintf(char *buff, size_t len, const char* format, va_list ap){ for(i = 0; format[i] != '\0' ; i++) { if (format[i] == '%') { i++; + int u = 0; + int l = 0; + bool spec = true; + while (spec) { + switch(format[i]) { + case 'l': { + l++; + i++; + break; + } + case 'u': { + u = 1; + i++; + break; + } + default: + spec = false; + } + } switch(format[i]) { case '%': PUTCHAR('%'); break; - case 'i':; case 'd': { - int integer = va_arg(ap,int); - int cpt2 = 0; - char buff_int[16]; + if (u) { + // TODO + } else { + long long int integer; + if (l == 0) integer = va_arg(ap, int); + if (l == 1) integer = va_arg(ap, long int); + if (l == 2) integer = va_arg(ap, long long int); - if (integer<0) - PUTCHAR('-'); + int cpt2 = 0; + char buff_int[32]; - do { - int m10 = integer%10; - m10 = (m10 < 0)? -m10:m10; - buff_int[cpt2++] = (char)('0'+ m10); - integer = integer/10; - } while(integer != 0); + if (integer<0) + PUTCHAR('-'); - for(cpt2 = cpt2 - 1; cpt2 >= 0; cpt2--) - PUTCHAR(buff_int[cpt2]); + do { + int m10 = integer%10; + m10 = (m10 < 0)? -m10:m10; + buff_int[cpt2++] = (char)('0'+ m10); + integer = integer/10; + } while(integer != 0); - break; + for(cpt2 = cpt2 - 1; cpt2 >= 0; cpt2--) + PUTCHAR(buff_int[cpt2]); + } + break; } case 'c': { int value = va_arg(ap,int); |