diff options
author | Max Horn | 2011-05-23 18:32:42 +0200 |
---|---|---|
committer | Max Horn | 2011-05-23 19:12:25 +0200 |
commit | 8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2 (patch) | |
tree | 63038cba9ad4d0dd72a65749ee7ac7410ac76edc /common | |
parent | 3931e1dc50ad773aa3f9d95b2810857a3e7ce943 (diff) | |
download | scummvm-rg350-8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2.tar.gz scummvm-rg350-8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2.tar.bz2 scummvm-rg350-8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2.zip |
COMMON: Provide our own implementations for scumm_str(n)icmp
This takes up a tiny little bit of extra binary size, but gets
rid of some awful #ifdef hackery.
Diffstat (limited to 'common')
-rw-r--r-- | common/scummsys.h | 24 | ||||
-rw-r--r-- | common/str.cpp | 33 |
2 files changed, 42 insertions, 15 deletions
diff --git a/common/scummsys.h b/common/scummsys.h index 2420349245..5cf3ba4dad 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -107,21 +107,6 @@ #include "config.h" #endif -// -// Define scumm_stricmp and scumm_strnicmp -// -#if defined(_WIN32_WCE) || defined(_MSC_VER) - #define scumm_stricmp stricmp - #define scumm_strnicmp _strnicmp - #define snprintf _snprintf -#elif defined(__MINGW32__) || defined(__GP32__) || defined(__DS__) - #define scumm_stricmp stricmp - #define scumm_strnicmp strnicmp -#else - #define scumm_stricmp strcasecmp - #define scumm_strnicmp strncasecmp -#endif - // In the following we configure various targets, in particular those // which can't use our "configure" tool and hence don't use config.h. @@ -404,6 +389,15 @@ #endif +// +// Define scumm_stricmp and scumm_strnicmp +// +extern int scumm_stricmp(const char *s1, const char *s2); +extern int scumm_strnicmp(const char *s1, const char *s2, uint n); +#if defined(_WIN32_WCE) || defined(_MSC_VER) + // FIXME: Why is this necessary? + #define snprintf _snprintf +#endif // diff --git a/common/str.cpp b/common/str.cpp index 08a6cb6822..740e7b6a06 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -833,3 +833,36 @@ size_t strlcat(char *dst, const char *src, size_t size) { } } // End of namespace Common + +// Portable implementation of stricmp / strcasecmp / strcmpi. +// TODO: Rename this to Common::strcasecmp +int scumm_stricmp(const char *s1, const char *s2) { + byte l1, l2; + do { + // Don't use ++ inside tolower, in case the macro uses its + // arguments more than once. + l1 = (byte)*s1++; + l1 = tolower(l1); + l2 = (byte)*s2++; + l2 = tolower(l2); + } while (l1 == l2 && l1 != 0); + return l1 - l2; +} + +// Portable implementation of strnicmp / strncasecmp / strncmpi. +// TODO: Rename this to Common::strncasecmp +int scumm_strnicmp(const char *s1, const char *s2, uint n) { + byte l1, l2; + do { + if (n-- == 0) + return 0; // no difference found so far -> signal equality + + // Don't use ++ inside tolower, in case the macro uses its + // arguments more than once. + l1 = (byte)*s1++; + l1 = tolower(l1); + l2 = (byte)*s2++; + l2 = tolower(l2); + } while (l1 == l2 && l1 != 0); + return l1 - l2; +} |