From cb40fd155527783f1a45122165d2c0385a13332c Mon Sep 17 00:00:00 2001 From: aap Date: Thu, 25 Feb 2016 00:30:26 +0100 Subject: [PATCH] implemented a case insensitive strncmp --- src/anim.cpp | 2 +- src/image.cpp | 2 +- src/rwbase.cpp | 17 +++++++++++++++++ src/rwbase.h | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/anim.cpp b/src/anim.cpp index 2de9cae..bd647bb 100644 --- a/src/anim.cpp +++ b/src/anim.cpp @@ -227,7 +227,7 @@ UVAnimDictionary::find(const char *name) FORLIST(lnk, this->animations){ Animation *anim = UVAnimDictEntry::fromDict(lnk)->anim; UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData; - if(strncmp(custom->name, name, 32) == 0) // strncmp correct? + if(strncmp_ci(custom->name, name, 32) == 0) return anim; } return NULL; diff --git a/src/image.cpp b/src/image.cpp index 516a269..5362e1d 100755 --- a/src/image.cpp +++ b/src/image.cpp @@ -53,7 +53,7 @@ TexDictionary::find(const char *name) { FORLIST(lnk, this->textures){ Texture *tex = Texture::fromDict(lnk); - if(strncmp(tex->name, name, 32) == 0) + if(strncmp_ci(tex->name, name, 32) == 0) return tex; } return NULL; diff --git a/src/rwbase.cpp b/src/rwbase.cpp index bc95121..a00c084 100644 --- a/src/rwbase.cpp +++ b/src/rwbase.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "rwbase.h" #include "rwplugin.h" @@ -67,6 +68,22 @@ initialize(void) Frame::dirtyList.init(); } +// lazy implementation +int +strncmp_ci(const char *s1, const char *s2, int n) +{ + char c1, c2; + while(n--){ + c1 = tolower(*s1); + c2 = tolower(*s2); + if(c1 != c2) + return c1 - c2; + s1++; + s2++; + } + return 0; +} + Quat mult(const Quat &q, const Quat &p) { diff --git a/src/rwbase.h b/src/rwbase.h index 4b727d3..21782fa 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -281,6 +281,8 @@ extern char *debugFile; void initialize(void); +int strncmp_ci(const char *s1, const char *s2, int n); + // 0x04000000 3.1 // 0x08000000 3.2 // 0x0C000000 3.3