X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flib.c;h=bfae2a41da89df0f7d920ef7cbef8b278bd407ef;hb=c3d486ba13c6cd12558d4c0cf01d3fd93e797d64;hp=f99f58ac705bcb821d03ebe13a3a51ed1e8ad4ac;hpb=6ea2f6040da80c963882f6ccfe4bf21ff048eaff;p=tpg%2Facess2.git diff --git a/Kernel/lib.c b/Kernel/lib.c index f99f58ac..bfae2a41 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -20,9 +20,62 @@ const short DAYS_BEFORE[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 3 static Uint giRandomState = RANDOM_SEED; // === CODE === +/** + * \brief Convert a string into an integer + */ +int atoi(const char *string) +{ + int ret = 0; + + // Clear non-numeric characters + while( !('0' <= *string && *string <= '9') ) string++; + + if(*string == '0') + { + string ++; + if(*string == 'x') + { + // Hex + string ++; + for( ;; ) { + ret *= 16; + if('0' <= *string && *string <= '9') + ret += *string - '0'; + else if('A' <= *string && *string <= 'F') + ret += *string - 'A' + 10; + else if('a' <= *string && *string <= 'f') + ret += *string - 'a' + 10; + else + break; + string ++; + } + } + else + { + for( ;; ) + { + ret *= 8; + if('0' <= *string && *string <= '7') + ret += *string - '0'; + else + break; + } + } + } + else + { + for( ; '0' <= *string && *string <= '9'; string++) + { + ret *= 10; + ret += *string - '0'; + } + } + return ret; +} + static const char cUCDIGITS[] = "0123456789ABCDEF"; /** - * \fn static void itoa(char *buf, Uint num, int base, int minLength, char pad) + * \fn void itoa(char *buf, Uint num, int base, int minLength, char pad) * \brief Convert an integer into a character string */ void itoa(char *buf, Uint num, int base, int minLength, char pad) @@ -209,7 +262,7 @@ int tolower(int c) } /** - * \fn int strucmp(char *Str1, char *Str2) + * \fn int strucmp(const char *Str1, const char *Str2) * \brief Compare \a Str1 and \a Str2 case-insensitively */ int strucmp(const char *Str1, const char *Str2) @@ -256,7 +309,7 @@ Uint strlen(const char *__str) } /** - * \fn char *strcpy(const char *__str1, const char *__str2) + * \fn char *strcpy(char *__str1, const char *__str2) * \brief Copy a string to a new location */ char *strcpy(char *__str1, const char *__str2) @@ -268,7 +321,7 @@ char *strcpy(char *__str1, const char *__str2) } /** - * \fn char *strcpy(const char *__str1, const char *__str2) + * \fn char *strncpy(char *__str1, const char *__str2, size_t max) * \brief Copy a string to a new location */ char *strncpy(char *__str1, const char *__str2, size_t max)