X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fq.c;fp=lib%2Fq.c;h=b1553b5a126af3f335ddb517199f538d388135e2;hp=942cfbb8ba4d4655e3b39964140b43d7edcb3691;hb=bb864e1a88e670c99d559c7dee4f74e9bf7d978b;hpb=763bcfebf188186f18f6bb35338317571c4d2d87 diff --git a/lib/q.c b/lib/q.c index 942cfbb..b1553b5 100644 --- a/lib/q.c +++ b/lib/q.c @@ -295,7 +295,7 @@ void trie_put(trie_t**t, unsigned const char*id) if(id[0]) { trie_put(&(*t)->row[id[0]], id+1); } else { - (*t)->rest = ""; + (*t)->rest = strdup(""); } } @@ -304,14 +304,28 @@ int trie_lookup(trie_t*t, unsigned const char*id) while(t) { if(t->rest && !strcmp(t->rest, id)) return 1; - t = t->row[id[0]]; if(!*id) return 0; - id++; + t = t->row[*id++]; } return 0; } +char trie_remove(trie_t*t, unsigned const char*id) +{ + while(t) { + if(t->rest && !strcmp(t->rest, id)) { + free(t->rest); + t->rest = 0; + return 1; + } + if(!*id) + return 0; + t = t->row[*id++]; + } +} + + // ------------------------------- crc32 -------------------------------------- static unsigned int*crc32 = 0; static void crc32_init(void)