From 03ffdeb43a76da25bf06f3619856da91f3302750 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 10 Apr 2021 15:52:01 +0200 Subject: [PATCH] LibC: Provide macros for the functions These are required for the 'tr' port. --- Userland/Libraries/LibC/ctype.cpp | 90 ++++++++++++++++++++++-- Userland/Libraries/LibC/ctype.h | 111 ++++++++++++++++++++++-------- 2 files changed, 167 insertions(+), 34 deletions(-) diff --git a/Userland/Libraries/LibC/ctype.cpp b/Userland/Libraries/LibC/ctype.cpp index 3649afba31..5322f4c3ee 100644 --- a/Userland/Libraries/LibC/ctype.cpp +++ b/Userland/Libraries/LibC/ctype.cpp @@ -47,17 +47,93 @@ const char _ctype_[256] = { _L, _L, _L, _P, _P, _P, _P, _C }; -int tolower(int c) +#undef isalnum +int isalnum(int c) { - if (c >= 'A' && c <= 'Z') - return c | 0x20; - return c; + return __inline_isalnum(c); } +#undef isalpha +int isalpha(int c) +{ + return __inline_isalpha(c); +} + +#undef iscntrl +int iscntrl(int c) +{ + return __inline_iscntrl(c); +} + +#undef isdigit +int isdigit(int c) +{ + return __inline_isdigit(c); +} + +#undef isxdigit +int isxdigit(int c) +{ + return __inline_isxdigit(c); +} + +#undef isspace +int isspace(int c) +{ + return __inline_isspace(c); +} + +#undef ispunct +int ispunct(int c) +{ + return __inline_ispunct(c); +} + +#undef isprint +int isprint(int c) +{ + return __inline_isprint(c); +} + +#undef isgraph +int isgraph(int c) +{ + return __inline_isgraph(c); +} + +#undef isupper +int isupper(int c) +{ + return __inline_isupper(c); +} + +#undef islower +int islower(int c) +{ + return __inline_islower(c); +} + +#undef isascii +int isascii(int c) +{ + return ((unsigned)c <= 127); +} + +#undef toascii +int toascii(int c) +{ + return __inline_toascii(c); +} + +#undef tolower +int tolower(int c) +{ + return __inline_tolower(c); +} + +#undef toupper int toupper(int c) { - if (c >= 'a' && c <= 'z') - return c & ~0x20; - return c; + return __inline_toupper(c); } } diff --git a/Userland/Libraries/LibC/ctype.h b/Userland/Libraries/LibC/ctype.h index e49c7086d0..03d13c7e32 100644 --- a/Userland/Libraries/LibC/ctype.h +++ b/Userland/Libraries/LibC/ctype.h @@ -42,65 +42,122 @@ __BEGIN_DECLS extern const char _ctype_[256]; -int tolower(int); -int toupper(int); - -static inline int isalnum(int c) +static inline int __inline_isalnum(int c) { - return (_ctype_[(unsigned char)(c)] & (_U | _L | _N)); + return _ctype_[(unsigned char)(c)] & (_U | _L | _N); } -static inline int isalpha(int c) +static inline int __inline_isalpha(int c) { - return (_ctype_[(unsigned char)(c)] & (_U | _L)); + return _ctype_[(unsigned char)(c)] & (_U | _L); } -static inline int iscntrl(int c) +static inline int __inline_isascii(int c) { - return (_ctype_[(unsigned char)(c)] & (_C)); + return (unsigned)c <= 127; } -static inline int isdigit(int c) +static inline int __inline_iscntrl(int c) { - return (_ctype_[(unsigned char)(c)] & (_N)); + return _ctype_[(unsigned char)(c)] & (_C); } -static inline int isxdigit(int c) +static inline int __inline_isdigit(int c) { - return (_ctype_[(unsigned char)(c)] & (_N | _X)); + return _ctype_[(unsigned char)(c)] & (_N); } -static inline int isspace(int c) +static inline int __inline_isxdigit(int c) { - return (_ctype_[(unsigned char)(c)] & (_S)); + return _ctype_[(unsigned char)(c)] & (_N | _X); } -static inline int ispunct(int c) +static inline int __inline_isspace(int c) { - return (_ctype_[(unsigned char)(c)] & (_P)); + return _ctype_[(unsigned char)(c)] & (_S); } -static inline int isprint(int c) +static inline int __inline_ispunct(int c) { - return (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N | _B)); + return _ctype_[(unsigned char)(c)] & (_P); } -static inline int isgraph(int c) +static inline int __inline_isprint(int c) { - return (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N)); + return _ctype_[(unsigned char)(c)] & (_P | _U | _L | _N | _B); } -static inline int islower(int c) +static inline int __inline_isgraph(int c) { - return ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _L); + return _ctype_[(unsigned char)(c)] & (_P | _U | _L | _N); } -static inline int isupper(int c) +static inline int __inline_islower(int c) { - return ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _U); + return _ctype_[(unsigned char)(c)] & (_L); } -#define isascii(c) ((unsigned)c <= 127) -#define toascii(c) ((c)&127) +static inline int __inline_isupper(int c) +{ + return _ctype_[(unsigned char)(c)] & (_U); +} + +static inline int __inline_toascii(int c) +{ + return c & 127; +} + +static inline int __inline_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return c | 0x20; + return c; +} + +static inline int __inline_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return c & ~0x20; + return c; +} + +#ifdef __cplusplus +extern "C" { +#endif + +int isalnum(int c); +int isalpha(int c); +int isascii(int c); +int iscntrl(int c); +int isdigit(int c); +int isxdigit(int c); +int isspace(int c); +int ispunct(int c); +int isprint(int c); +int isgraph(int c); +int islower(int c); +int isupper(int c); +int toascii(int c); +int tolower(int c); +int toupper(int c); + +#ifdef __cplusplus +} +#endif +#define isalnum __inline_isalnum +#define isalpha __inline_isalpha +#define isascii __inline_isascii +#define iscntrl __inline_iscntrl +#define isdigit __inline_isdigit +#define isxdigit __inline_isxdigit +#define isspace __inline_isspace +#define ispunct __inline_ispunct +#define isprint __inline_isprint +#define isgraph __inline_isgraph +#define islower __inline_islower +#define isupper __inline_isupper +#define toascii __inline_toascii +#define tolower __inline_tolower +#define toupper __inline_toupper __END_DECLS