diff --git a/make/source.mk b/make/source.mk index 36f16c3b51..c766d6e518 100644 --- a/make/source.mk +++ b/make/source.mk @@ -13,6 +13,7 @@ COMMON_SRC = \ common/maths.c \ common/printf.c \ common/streambuf.c \ + common/string_light.c \ common/time.c \ common/typeconversion.c \ config/config_eeprom.c \ diff --git a/src/main/common/string_light.c b/src/main/common/string_light.c index 1546f733c4..b60e3cdb6e 100755 --- a/src/main/common/string_light.c +++ b/src/main/common/string_light.c @@ -16,46 +16,52 @@ */ #include +#include +#include -#include "string_light.h" #include "typeconversion.h" -int sl_isalnum(int c) +int isalnum(int c) { - return sl_isdigit(c) || sl_isupper(c) || sl_islower(c); + return isdigit(c) || isupper(c) || islower(c); } -int sl_isdigit(int c) +int isdigit(int c) { return (c >= '0' && c <= '9'); } -int sl_isupper(int c) +int isupper(int c) { return (c >= 'A' && c <= 'Z'); } -int sl_islower(int c) +int islower(int c) { return (c >= 'a' && c <= 'z'); } -int sl_tolower(int c) +int isspace(int c) { - return sl_isupper(c) ? (c) - 'A' + 'a' : c; + return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'); } -int sl_toupper(int c) +int tolower(int c) { - return sl_islower(c) ? (c) - 'a' + 'A' : c; + return isupper(c) ? (c) - 'A' + 'a' : c; } -int sl_strcasecmp(const char * s1, const char * s2) +int toupper(int c) { - return sl_strncasecmp(s1, s2, INT_MAX); + return islower(c) ? (c) - 'a' + 'A' : c; } -int sl_strncasecmp(const char * s1, const char * s2, int n) +int strcasecmp(const char * s1, const char * s2) +{ + return strncasecmp(s1, s2, (size_t)-1); +} + +int strncasecmp(const char * s1, const char * s2, size_t n) { const unsigned char * ucs1 = (const unsigned char *) s1; const unsigned char * ucs2 = (const unsigned char *) s2; @@ -63,8 +69,8 @@ int sl_strncasecmp(const char * s1, const char * s2, int n) int d = 0; for ( ; n != 0; n--) { - const int c1 = sl_tolower(*ucs1++); - const int c2 = sl_tolower(*ucs2++); + const int c1 = tolower(*ucs1++); + const int c2 = tolower(*ucs2++); if (((d = c1 - c2) != 0) || (c2 == '\0')) { break; } diff --git a/src/main/common/string_light.h b/src/main/common/string_light.h deleted file mode 100755 index 005a6c6b12..0000000000 --- a/src/main/common/string_light.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of Cleanflight. - * - * Cleanflight is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Cleanflight is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cleanflight. If not, see . - */ - -#pragma once - -int sl_isalnum(int c); -int sl_isdigit(int c); -int sl_isupper(int c); -int sl_islower(int c); -int sl_tolower(int c); -int sl_toupper(int c); - -int sl_strcasecmp(const char * s1, const char * s2); -int sl_strncasecmp(const char * s1, const char * s2, int n); diff --git a/src/main/ctype.h b/src/main/ctype.h new file mode 100644 index 0000000000..a2dde62e3d --- /dev/null +++ b/src/main/ctype.h @@ -0,0 +1,33 @@ +/* + * Replacemnet for system header file to avoid macro definitions + * Functions are implemented in common/string_light.c + */ + +#ifdef __cplusplus +// use original implementation for C++ +# include_next +#endif + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#ifndef _EXFUN +# define _EXFUN(name,proto) name proto +#endif + +int _EXFUN(isalnum, (int __c)); +int _EXFUN(isalpha, (int __c)); +int _EXFUN(iscntrl, (int __c)); +int _EXFUN(isdigit, (int __c)); +int _EXFUN(isgraph, (int __c)); +int _EXFUN(islower, (int __c)); +int _EXFUN(isprint, (int __c)); +int _EXFUN(ispunct, (int __c)); +int _EXFUN(isspace, (int __c)); +int _EXFUN(isupper, (int __c)); +int _EXFUN(isxdigit,(int __c)); +int _EXFUN(tolower, (int __c)); +int _EXFUN(toupper, (int __c)); +int _EXFUN(isblank, (int __c)); + +#endif /* _CTYPE_H_ */