X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fwildmatch.c;h=5fcef8220f09e1d4ca6570531421bdaa89a33e97;hb=2e2adfa5d7ac912434bef5b8a9b25cfb14d4a4a6;hp=545487ce91a517a82f43fffa6a777087f49f7b4a;hpb=98890a92740cbfc0c5ddab9844f1ffe8d715ac8a;p=libucw.git diff --git a/lib/wildmatch.c b/lib/wildmatch.c index 545487ce..5fcef822 100644 --- a/lib/wildmatch.c +++ b/lib/wildmatch.c @@ -6,13 +6,13 @@ * (c) 1999 Martin Mares */ +#include "lib/lib.h" +#include "lib/pools.h" +#include "lib/wildmatch.h" + #include #include -#include "lib.h" -#include "pools.h" -#include "wildmatch.h" - #define MAX_STATES 32 /* Must be <= 32, state 0 is reserved, state 1 is initial */ #define MAX_CACHED 256 /* Maximum number of cached DFA states */ #define HASH_SIZE 512 /* Number of entries in DFA hash table (at least MAX_CACHED+MAX_STATES) */ @@ -39,8 +39,8 @@ struct wildpatt { struct nfa_state nfa[MAX_STATES]; struct dfa_state *hash[HASH_SIZE]; struct dfa_state *dfa_start; - int nfa_states; - int dfa_cache_counter; + uns nfa_states; + uns dfa_cache_counter; struct mempool *pool; struct dfa_state *free_states; }; @@ -70,7 +70,7 @@ wp_new_state(struct wildpatt *w, u32 set) if (d = w->free_states) w->free_states = d->next; else - d = pool_alloc(w->pool, sizeof(*d)); + d = mp_alloc(w->pool, sizeof(*d)); w->hash[h] = d; bzero(d, sizeof(*d)); d->nfa_set = set; @@ -103,8 +103,7 @@ wp_compile(byte *p, struct mempool *pool) if (strlen(p) >= MAX_STATES) /* Too long */ return NULL; - w = pool_alloc(pool, sizeof(*w)); - bzero(w, sizeof(w)); + w = mp_alloc_zero(pool, sizeof(*w)); w->pool = pool; for(i=1; *p; p++) { @@ -172,6 +171,17 @@ wp_match(struct wildpatt *w, byte *s) return d->final; } +int +wp_min_size(byte *p) +{ + int s = 0; + + while (*p) + if (*p++ != '*') + s++; + return s; +} + #ifdef TEST void @@ -198,7 +208,7 @@ int main(int argc, char **argv) char buf[1024]; if (argc != 2) return 1; - w = wp_compile(argv[1], new_pool(65536)); + w = wp_compile(argv[1], mp_new(65536)); if (!w) { puts("Compile error");