]> mj.ucw.cz Git - libucw.git/blobdiff - lib/kmp.c
IP parsing code moved to lib/conf.c, closes Bug #2375.
[libucw.git] / lib / kmp.c
index 70f1be27dd4f9d97566cb29eb5227f5b9ede11ce..95a709d4fbe161eb3c93d108fbf5e3501634407b 100644 (file)
--- a/lib/kmp.c
+++ b/lib/kmp.c
@@ -5,17 +5,16 @@
  */
 
 #include "lib/lib.h"
+#include "lib/bitops.h"
 #include "lib/mempool.h"
 #include "lib/lists.h"
-#include "sherlock/tagged-text.h"
 #include "lib/unicode.h"
 
-#define KMP_GET_CHAR KMP_GET_RAW
+#define KMP_GET_CHAR(pos, c, flags) ASSERT(0)
 #include "lib/kmp.h"
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <alloca.h>
 
 #define        TRACE(level, mask...)   if (0) fprintf(stderr, mask)
@@ -33,7 +32,7 @@ kmp_new(struct mempool *mp, int words_len, uns modify_flags)
        kmp->g.sons = mp_alloc_zero(mp, size * sizeof(struct list));
        init_list(kmp->g.sons + 0);
        if (words_len > 1)
-               size = words_len * fls(words_len);
+               size = words_len * bit_fls(words_len);
        else
                size = 1;
        kmp->g.hash_size = size;
@@ -66,16 +65,15 @@ new_output(struct kmp *kmp, uns id, uns len)
 }
  
 void
-kmp_enter_raw_string(struct kmp *kmp, const byte *str, uns id)
+kmp_enter_raw_string(struct kmp *kmp, kmp_char_t *str, uns id)
 {
        struct kmp_transition tr = { .next=NULL, .from=0 }, **prev;
        struct kmp_output *new_out;
-       const byte *orig_str = str;
        uns len = 0;
        kmp_char_t c = 'a';
 
-       TRACE(20, "kmp.c: Entering string %s", str);
-       kmp_get_char(&str, &c, 0);
+       TRACE(20, "kmp.c: Entering string");
+       c = *str++;
        len++;
        if (!c)
                return;
@@ -86,7 +84,7 @@ kmp_enter_raw_string(struct kmp *kmp, const byte *str, uns id)
                if (!*prev)
                        break;
                tr.from = (*prev)->to;
-               kmp_get_char(&str, &c, 0);
+               c = *str++;
                len++;
        }
        while (c)
@@ -96,7 +94,7 @@ kmp_enter_raw_string(struct kmp *kmp, const byte *str, uns id)
                **prev = tr;
                add_tail(kmp->g.sons + tr.from, &(*prev)->n);
                init_list(kmp->g.sons + tr.to);
-               kmp_get_char(&str, &c, 0);
+               c = *str++;
                len++;
                tr.from = tr.to;
                tr.c = c;
@@ -104,7 +102,7 @@ kmp_enter_raw_string(struct kmp *kmp, const byte *str, uns id)
                ASSERT(!*prev);
        }
        if (kmp->out[tr.from])
-               TRACE(5, "kmp.c: string %s is inserted more than once", orig_str);
+               TRACE(5, "kmp.c: string is inserted more than once");
        new_out = new_output(kmp, id, len-1);
        merge_output(kmp->out + tr.from, new_out);
 }