From: John Hodge Date: Thu, 12 Jul 2012 08:47:32 +0000 (+0800) Subject: Kernel - Added ctype.h header X-Git-Tag: rel0.15~611^2~41^2~15 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d5d0dcb9b2daecbc88a972f74b39967f020faa15;p=tpg%2Facess2.git Kernel - Added ctype.h header --- diff --git a/KernelLand/Kernel/include/acess.h b/KernelLand/Kernel/include/acess.h index e673290a..1415237c 100644 --- a/KernelLand/Kernel/include/acess.h +++ b/KernelLand/Kernel/include/acess.h @@ -442,6 +442,8 @@ extern int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString); * \} */ +#include + /** * \brief Get a random number * \return Random number diff --git a/KernelLand/Kernel/include/ctype.h b/KernelLand/Kernel/include/ctype.h new file mode 100644 index 00000000..2db66c9a --- /dev/null +++ b/KernelLand/Kernel/include/ctype.h @@ -0,0 +1,29 @@ +/* + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * ctype.h + * - + */ +#ifndef _ACESS__CTYPE_H_ +#define _ACESS__CTYPE_H_ + +extern int isalnum(int c); +extern int isalpha(int c); +extern int isascii(int c); +extern int isblank(int c); +extern int iscntrl(int c); +extern int isdigit(int c); +extern int isgraph(int c); +extern int islower(int c); +extern int isprint(int c); +extern int ispunct(int c); +extern int isspace(int c); +extern int isupper(int c); +extern int isxdigit(int c); + +extern int toupper(int c); +extern int tolower(int c); + +#endif + diff --git a/KernelLand/Kernel/lib.c b/KernelLand/Kernel/lib.c index cab5ea8e..68d2032f 100644 --- a/KernelLand/Kernel/lib.c +++ b/KernelLand/Kernel/lib.c @@ -441,4 +441,3 @@ Uint64 SwapEndian64(Uint64 Val) { return SwapEndian32(Val >> 32) | ((Uint64)SwapEndian32(Val) << 32); } - diff --git a/KernelLand/Kernel/libc.c b/KernelLand/Kernel/libc.c index be645a58..bd349735 100644 --- a/KernelLand/Kernel/libc.c +++ b/KernelLand/Kernel/libc.c @@ -22,9 +22,6 @@ void itoa(char *buf, Uint64 num, int base, int minLength, char pad); int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args); int snprintf(char *__s, size_t __n, const char *__format, ...); int sprintf(char *__s, const char *__format, ...); -#endif - int tolower(int c); -#if 0 int strucmp(const char *Str1, const char *Str2); char *strchr(const char *__s, int __c); int strpos(const char *Str, char Ch); @@ -49,6 +46,7 @@ EXPORT(vsnprintf); EXPORT(snprintf); EXPORT(sprintf); EXPORT(tolower); + EXPORT(strucmp); EXPORT(strchr); EXPORT(strpos); @@ -417,15 +415,95 @@ int sprintf(char *__s, const char *__format, ...) return ret; } -/** - * \fn int tolower(int c) - * \brief Converts a character to lower case +/* + * ================== + * ctype.h + * ================== */ +int isalnum(int c) +{ + return isalpha(c) || isdigit(c); +} +int isalpha(int c) +{ + return isupper(c) || islower(c); +} +int isascii(int c) +{ + return (0 <= c && c < 128); +} +int isblank(int c) +{ + if(c == '\t') return 1; + if(c == ' ') return 1; + return 0; +} +int iscntrl(int c) +{ + // TODO: Check iscntrl + if(c < ' ') return 1; + return 0; +} +int isdigit(int c) +{ + return ('0' <= c && c <= '9'); +} +int isgraph(int c) +{ + // TODO: Check isgraph + return 0; +} +int islower(int c) +{ + return ('a' <= c && c <= 'z'); +} +int isprint(int c) +{ + if( ' ' <= c && c <= 0x7F ) return 1; + return 0; +} +int ispunct(int c) +{ + switch(c) + { + case '.': case ',': + case '?': case '!': + return 1; + default: + return 0; + } +} +int isspace(int c) +{ + if(c == ' ') return 1; + if(c == '\t') return 1; + if(c == '\v') return 1; + if(c == '\n') return 1; + if(c == '\r') return 1; + return 0; +} +int isupper(int c) +{ + return ('a' <= c && c <= 'z'); +} +int isxdigit(int c) +{ + return isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); +} + +int toupper(int c) +{ + if( islower(c) ) + return c - 0x20; + else + return c; +} int tolower(int c) { - if('A' <= c && c <= 'Z') - return c - 'A' + 'a'; - return c; + if( isupper(c) ) + return c + 0x20; + else + return c; } /**