bugfix non-case-sensitive ct_find

This commit is contained in:
Enno Rehling 2004-01-15 22:29:41 +00:00
parent 7ced18cfef
commit 4349ce9456
1 changed files with 16 additions and 2 deletions

View File

@ -46,6 +46,7 @@
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <ctype.h>
/* spells includes */
#include <spells/regioncurse.h>
@ -228,10 +229,22 @@ typedef struct cursetype_list {
#define CMAXHASH 63
cursetype_list * cursetypes[CMAXHASH];
static char *
strlower(const char * str)
{
static char result[128];
char * pos = result;
while (*str) {
*pos++ = (char)tolower(*(unsigned char*)str++);
}
*pos=0;
return result;
}
void
ct_register(const curse_type * ct)
{
unsigned int hash = hashstring(ct->cname) % CMAXHASH;
unsigned int hash = hashstring(strlower(ct->cname)) % CMAXHASH;
cursetype_list ** ctlp = &cursetypes[hash];
while (*ctlp) {
cursetype_list * ctl = *ctlp;
@ -245,7 +258,8 @@ ct_register(const curse_type * ct)
const curse_type *
ct_find(const char *c)
{
unsigned int hash = hashstring(c) % CMAXHASH;
char * lower = strlower(c);
unsigned int hash = hashstring(lower) % CMAXHASH;
cursetype_list * ctl = cursetypes[hash];
while (ctl) {
int k = min(strlen(c), strlen(ctl->type->cname));