*/
#include <acess.h>
#include <hal_proc.h> // For MM_*
+#include <utf16.h>
// === CONSTANTS ===
#define RANDOM_SEED 0xACE55052
// === PROTOTYPES ===
#if 0
+unsigned long long strtoull(const char *str, char **end, int base);
+unsigned long strtoul(const char *str, char **end, int base);
+signed long long strtoll(const char *str, char **end, int base);
+signed long strtol(const char *str, char **end, int base);
int atoi(const char *string);
int ParseInt(const char *string, int *Val);
void itoa(char *buf, Uint64 num, int base, int minLength, char pad);
EXPORT(CheckMem);
// === CODE ===
-/**
- * \brief Convert a string into an integer
- */
-int atoi(const char *string)
-{
- int ret = 0;
- ParseInt(string, &ret);
- return ret;
-}
+// - Import userland stroi.c file
+#define _LIB_H_
+#include "../../Usermode/Libraries/libc.so_src/strtoi.c"
+
int ParseInt(const char *string, int *Val)
{
int ret = 0;
// Convert
while(num > base-1) {
num = DivMod64U(num, base, &rem); // Shift `num` and get remainder
+ ASSERT(rem >= 0);
+ ASSERT(rem < base);
tmpBuf[pos] = cUCDIGITS[ rem ];
pos++;
}
int minSize = 0, precision = -1, len;
char tmpBuf[34]; // For Integers
const char *p = NULL;
- int isLongLong = 0;
+ int isLongLong = 0, isLong;
Uint64 val;
size_t pos = 0;
// Flags
PUTCH('*'); PUTCH('0'); PUTCH('x');
for( len = BITS/4; len -- && ((ptr>>(len*4))&15) == 0; )
;
- for( len ++; len --; )
- PUTCH( cUCDIGITS[ (ptr>>(len*4))&15 ] );
+ len ++;
+ if( len == 0 )
+ PUTCH( '0' );
+ else
+ while( len -- )
+ PUTCH( cUCDIGITS[ (ptr>>(len*4))&15 ] );
continue ;
}
-
+
+ isLongLong = 0;
+ isLong = 0;
+
// - Padding Side Flag
if(c == '-') {
bPadLeft = 1;
isLongLong = 0;
if(c == 'l') // Long is actually the default on x86
{
+ isLong = 1;
c = *__format++;
if(c == 'l') {
c = *__format++;
// String - Null Terminated Array
case 's':
+ if( isLong ) {
+ Uint16 *p16 = va_arg(args, Uint16*);
+ Uint8 tmp[5];
+ while( *p16 && precision-- ) {
+ Uint32 cp;
+ p16 += ReadUTF16(p16, &cp);
+ tmp[WriteUTF8(tmp, cp)] = 0;
+ for(int i = 0; tmp[i] && i<5; i ++)
+ PUTCH(tmp[i]);
+ }
+ break;
+ }
p = va_arg(args, char*); // Get Argument
if( !p || !CheckString(p) ) p = "(inval)"; // Avoid #PFs
printString:
if(!p) p = "(null)";
len = strlen(p);
if( !bPadLeft ) while(len++ < minSize) PUTCH(pad);
- while(*p && precision--) PUTCH(*p++);
+ while(*p && precision--) { PUTCH(*p); p++;}
if( bPadLeft ) while(len++ < minSize) PUTCH(pad);
break;
p = va_arg(args, char*);
if( !CheckMem(p, minSize) ) continue; // No #PFs please
if(!p) goto printString;
- while(minSize--) PUTCH(*p++);
+ while(minSize--) {
+ PUTCH(*p);
+ p ++;
+ }
break;
// Single Character
}
int isupper(int c)
{
- return ('a' <= c && c <= 'z');
+ return ('A' <= c && c <= 'Z');
}
int isxdigit(int c)
{