X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.c;h=b1553b5a126af3f335ddb517199f538d388135e2;hb=cf2ede9f5b6da1f0d143c3fb825b88a3bb183811;hp=942cfbb8ba4d4655e3b39964140b43d7edcb3691;hpb=153afec3db7438e41baaed4df4aa1bc79ee785a5;p=swftools.git 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)