X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fwildmatch.c;h=e0b5e2ecf6fd0ef42848b6609b737a9359d46d77;hb=ed4e86de76d1c3bfb685207fe00078950f67355a;hp=fbc9bdb3c547e33587b1fe674aab007f15affe7e;hpb=8886ac0aa8be3913ef1fbefcff5d970acce3010a;p=libucw.git diff --git a/lib/wildmatch.c b/lib/wildmatch.c index fbc9bdb3..e0b5e2ec 100644 --- a/lib/wildmatch.c +++ b/lib/wildmatch.c @@ -1,18 +1,21 @@ /* - * Fast Pattern Matcher for Short Wildcard Patterns (only `?' and `*' supported) + * UCW Library -- Fast Pattern Matcher for Short Wildcard Patterns (only `?' and `*' supported) * * Traditional NFA -> DFA method with on-the-fly DFA construction. * * (c) 1999 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ +#include "lib/lib.h" +#include "lib/mempool.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) */ @@ -26,7 +29,7 @@ struct nfa_state { }; struct dfa_state { - addr_int_t edge[256]; /* Outgoing DFA edges. Bit 0 is set for incomplete edges which + uintptr_t edge[256]; /* Outgoing DFA edges. Bit 0 is set for incomplete edges which * contain just state set and clear for complete ones which point * to other states. NULL means `no match'. */ @@ -70,7 +73,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; @@ -96,15 +99,14 @@ wp_new_state(struct wildpatt *w, u32 set) } struct wildpatt * -wp_compile(byte *p, struct mempool *pool) +wp_compile(const byte *p, struct mempool *pool) { struct wildpatt *w; uns i; 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++) { @@ -146,7 +148,7 @@ wp_prune_cache(struct wildpatt *w) } int -wp_match(struct wildpatt *w, byte *s) +wp_match(struct wildpatt *w, const byte *s) { struct dfa_state *d; @@ -155,12 +157,12 @@ wp_match(struct wildpatt *w, byte *s) d = w->dfa_start; while (*s) { - addr_int_t next = d->edge[*s]; + uintptr_t next = d->edge[*s]; if (next & 1) { /* Need to lookup/create the destination state */ struct dfa_state *new = wp_new_state(w, next & ~1); - d->edge[*s] = (addr_int_t) new; + d->edge[*s] = (uintptr_t) new; d = new; } else if (!next) @@ -173,7 +175,7 @@ wp_match(struct wildpatt *w, byte *s) } int -wp_min_size(byte *p) +wp_min_size(const byte *p) { int s = 0; @@ -209,7 +211,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");