cursetype_list, another special-cased list type, bites the dust and is replaced by the quicklist.

This commit is contained in:
Enno Rehling 2011-02-25 07:56:00 -08:00
parent 5e21579036
commit c278a3b71f

View file

@ -275,44 +275,37 @@ attrib_type at_curse =
/* Spruch identifizieren */ /* Spruch identifizieren */
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/quicklist.h>
typedef struct cursetype_list { static quicklist * cursetypes[256];
struct cursetype_list * next;
const curse_type * type;
} cursetype_list;
cursetype_list * cursetypes[256];
void void
ct_register(const curse_type * ct) ct_register(const curse_type * ct)
{ {
unsigned int hash = tolower(ct->cname[0]); unsigned int hash = tolower(ct->cname[0]);
cursetype_list ** ctlp = &cursetypes[hash]; quicklist ** ctlp = &cursetypes[hash];
while (*ctlp) { ql_set_insert(ctlp, (void *)ct);
cursetype_list * ctl = *ctlp;
if (ctl->type==ct) return;
ctlp=&ctl->next;
}
*ctlp = calloc(1, sizeof(cursetype_list));
(*ctlp)->type = ct;
} }
const curse_type * const curse_type *
ct_find(const char *c) ct_find(const char *c)
{ {
unsigned int hash = tolower(c[0]); unsigned int hash = tolower(c[0]);
cursetype_list * ctl = cursetypes[hash]; quicklist * ctl = cursetypes[hash];
while (ctl) { int qi;
if (strcmp(c, ctl->type->cname)==0) {
return ctl->type; for (qi=0;ctl;ql_advance(&ctl, &qi, 1)) {
curse_type * type = (curse_type*)ql_get(ctl, qi);
if (strcmp(c, type->cname)==0) {
return type;
} else { } else {
size_t k = MIN(strlen(c), strlen(ctl->type->cname)); size_t k = MIN(strlen(c), strlen(type->cname));
if (!strncasecmp(c, ctl->type->cname, k)) { if (!strncasecmp(c, type->cname, k)) {
return ctl->type; return type;
} }
} }
ctl = ctl->next;
} }
return NULL; return NULL;
} }