diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-04-28 14:36:55 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-04-28 14:36:55 +0000 |
commit | b36751b7970a699f453da471261d258868741281 (patch) | |
tree | 3a40aa654aeedc66df3a4b16baca9301769b75e9 | |
parent | 48ec7a6f080c568c771c27c1ee92008174f10388 (diff) | |
download | hercules-b36751b7970a699f453da471261d258868741281.tar.gz hercules-b36751b7970a699f453da471261d258868741281.tar.bz2 hercules-b36751b7970a699f453da471261d258868741281.tar.xz hercules-b36751b7970a699f453da471261d258868741281.zip |
- Added function stristr to strlib.c, used by mob.c and item_db.c for case-insensitive seeks.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6345 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | Changelog-Trunk.txt | 5 | ||||
-rw-r--r-- | src/common/strlib.c | 35 | ||||
-rw-r--r-- | src/common/strlib.h | 1 | ||||
-rw-r--r-- | src/map/itemdb.c | 5 | ||||
-rw-r--r-- | src/map/mob.c | 5 |
5 files changed, 46 insertions, 5 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index de57bb940..bc1df1468 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -2,12 +2,15 @@ Date Added AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
-2006/04/27
+2006/04/28
+ * Added function stristr to strlib.c, used by mob.c and item_db.c for
+ case-insensitive seeks. [Skotlex]
* Removed the sending of the online guild list when you log-on, may fix the
"getting stuck" problem. [Skotlex]
* Added battle config default_skill_delay. Specifies the default skill
delay for most skills, it is also applied as a walkdelay (total skill
walkdelay is default_skill_delay + that skill's can't walk delay) [Skotlex]
+2006/04/27
* skill_castend_id and skill_castend_pos will trigger unit_stop_walking
with flag 1 (fix pos) rather than none. Should fix some skills making you
appear moving while doing them. [Skotlex]
diff --git a/src/common/strlib.c b/src/common/strlib.c index 94f815839..d62bf4f46 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -4,6 +4,7 @@ #include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "strlib.h"
#include "utils.h"
@@ -137,6 +138,40 @@ char *trim(char *str, const char *delim) return str;
}
+
+//stristr: Case insensitive version of strstr, code taken from
+//http://www.daniweb.com/code/snippet313.html, Dave Sinkula
+//
+const char *stristr(const char *haystack, const char *needle)
+{
+ if ( !*needle )
+ {
+ return haystack;
+ }
+ for ( ; *haystack; ++haystack )
+ {
+ if ( toupper(*haystack) == toupper(*needle) )
+ {
+ /*
+ * Matched starting char -- loop through remaining chars.
+ */
+ const char *h, *n;
+ for ( h = haystack, n = needle; *h && *n; ++h, ++n )
+ {
+ if ( toupper(*h) != toupper(*n) )
+ {
+ break;
+ }
+ }
+ if ( !*n ) /* matched all of 'needle' to null termination */
+ {
+ return haystack; /* return the start of the match */
+ }
+ }
+ }
+ return 0;
+}
+
#ifdef __WIN32
char *_strtok_r(char *s1, const char *s2, char **lasts)
{
diff --git a/src/common/strlib.h b/src/common/strlib.h index 51d865149..225228c74 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -20,4 +20,5 @@ char *_strtok_r(char *s1, const char *s2, char **lasts); // custom functions
int remove_control_chars(unsigned char *);
char *trim(char *str, const char *delim);
+const char *stristr(const char *haystack, const char *needle);
#endif
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 796712af3..4f6079f3a 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -9,6 +9,7 @@ #include "../common/malloc.h"
#include "../common/showmsg.h"
#include "../common/grfio.h"
+#include "../common/strlib.h"
#include "map.h"
#include "battle.h"
#include "itemdb.h"
@@ -75,9 +76,9 @@ static int itemdb_searchname_array_sub(DBKey key,void * data,va_list ap) str=va_arg(ap,char *);
if (item == dummy_item)
return 1; //Invalid item.
- if(strstr(item->jname,str))
+ if(stristr(item->jname,str))
return 0;
- if(strstr(item->name,str))
+ if(stristr(item->name,str))
return 0;
return strcmpi(item->jname,str);
}
diff --git a/src/map/mob.c b/src/map/mob.c index 6e2bc399f..15386ded0 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -14,6 +14,7 @@ #include "../common/malloc.h"
#include "../common/showmsg.h"
#include "../common/ers.h"
+#include "../common/strlib.h"
#include "map.h"
#include "clif.h"
@@ -84,9 +85,9 @@ static int mobdb_searchname_array_sub(struct mob_db* mob, const char *str) {
if (mob == mob_dummy)
return 1; //Invalid item.
- if(strstr(mob->jname,str))
+ if(stristr(mob->jname,str))
return 0;
- if(strstr(mob->name,str))
+ if(stristr(mob->name,str))
return 0;
return strcmpi(mob->jname,str);
}
|