implemented a case insensitive strncmp

This commit is contained in:
aap 2016-02-25 00:30:26 +01:00
parent 41226ef0c6
commit cb40fd1555
4 changed files with 21 additions and 2 deletions

View File

@ -227,7 +227,7 @@ UVAnimDictionary::find(const char *name)
FORLIST(lnk, this->animations){ FORLIST(lnk, this->animations){
Animation *anim = UVAnimDictEntry::fromDict(lnk)->anim; Animation *anim = UVAnimDictEntry::fromDict(lnk)->anim;
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData; 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 anim;
} }
return NULL; return NULL;

View File

@ -53,7 +53,7 @@ TexDictionary::find(const char *name)
{ {
FORLIST(lnk, this->textures){ FORLIST(lnk, this->textures){
Texture *tex = Texture::fromDict(lnk); Texture *tex = Texture::fromDict(lnk);
if(strncmp(tex->name, name, 32) == 0) if(strncmp_ci(tex->name, name, 32) == 0)
return tex; return tex;
} }
return NULL; return NULL;

View File

@ -3,6 +3,7 @@
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cctype>
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
@ -67,6 +68,22 @@ initialize(void)
Frame::dirtyList.init(); 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 Quat
mult(const Quat &q, const Quat &p) mult(const Quat &q, const Quat &p)
{ {

View File

@ -281,6 +281,8 @@ extern char *debugFile;
void initialize(void); void initialize(void);
int strncmp_ci(const char *s1, const char *s2, int n);
// 0x04000000 3.1 // 0x04000000 3.1
// 0x08000000 3.2 // 0x08000000 3.2
// 0x0C000000 3.3 // 0x0C000000 3.3