]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/kmp-test.c
tableprinter: update of xtypes for tableprinter
[libucw.git] / ucw / kmp-test.c
index cb18d03229234f6db7ffe44f24cb491eeeaf0633..39d06cf2ab0bdf2009ae6b6c583df77192ec5014 100644 (file)
@@ -4,8 +4,8 @@
  *      (c) 2006, Pavel Charvat <pchar@ucw.cz>
  */
 
  *      (c) 2006, Pavel Charvat <pchar@ucw.cz>
  */
 
-#include "ucw/lib.h"
-#include "ucw/mempool.h"
+#include <ucw/lib.h>
+#include <ucw/mempool.h>
 #include <string.h>
 
 #if 0
 #include <string.h>
 
 #if 0
 
 #define KMP_PREFIX(x) kmp1_##x
 #define KMP_WANT_CLEANUP
 
 #define KMP_PREFIX(x) kmp1_##x
 #define KMP_WANT_CLEANUP
-#include "ucw/kmp.h"
+#include <ucw/kmp.h>
 #define KMPS_PREFIX(x) kmp1s1_##x
 #define KMPS_KMP_PREFIX(x) kmp1_##x
 #define KMPS_WANT_BEST
 #define KMPS_EXIT(kmp,src,s) TRACE("Best match has %d characters", s->best->len)
 #define KMPS_PREFIX(x) kmp1s1_##x
 #define KMPS_KMP_PREFIX(x) kmp1_##x
 #define KMPS_WANT_BEST
 #define KMPS_EXIT(kmp,src,s) TRACE("Best match has %d characters", s->best->len)
-#include "ucw/kmp-search.h"
+#include <ucw/kmp-search.h>
 #define KMPS_PREFIX(x) kmp1s2_##x
 #define KMPS_KMP_PREFIX(x) kmp1_##x
 #define KMPS_PREFIX(x) kmp1s2_##x
 #define KMPS_KMP_PREFIX(x) kmp1_##x
-#define KMPS_VARS uns count;
+#define KMPS_VARS uint count;
 #define KMPS_INIT(kmp,src,s) s->u.count = 0
 #define KMPS_FOUND(kmp,src,s) s->u.count++
 #define KMPS_INIT(kmp,src,s) s->u.count = 0
 #define KMPS_FOUND(kmp,src,s) s->u.count++
-#include "ucw/kmp-search.h"
+#include <ucw/kmp-search.h>
 
 static void
 test1(void)
 
 static void
 test1(void)
@@ -50,7 +50,7 @@ test1(void)
   kmp1_cleanup(&kmp);
 }
 
   kmp1_cleanup(&kmp);
 }
 
-#ifndef CONFIG_UCW_ONLY                /* This one depends on LIBCHARSET */
+#ifdef CONFIG_CHARSET          /* This one depends on libucw-charset */
 
 /* TEST2 - various tracing */
 
 
 /* TEST2 - various tracing */
 
@@ -58,8 +58,8 @@ test1(void)
 #define KMP_USE_UTF8
 #define KMP_TOLOWER
 #define KMP_ONLYALPHA
 #define KMP_USE_UTF8
 #define KMP_TOLOWER
 #define KMP_ONLYALPHA
-#define KMP_STATE_VARS char *str; uns id;
-#define KMP_ADD_EXTRA_ARGS uns id
+#define KMP_STATE_VARS char *str; uint id;
+#define KMP_ADD_EXTRA_ARGS uint id
 #define KMP_VARS char *start;
 #define KMP_ADD_INIT(kmp,src) kmp->u.start = src
 #define KMP_ADD_NEW(kmp,src,s) do{ TRACE("Inserting string %s with id %d", kmp->u.start, id); \
 #define KMP_VARS char *start;
 #define KMP_ADD_INIT(kmp,src) kmp->u.start = src
 #define KMP_ADD_NEW(kmp,src,s) do{ TRACE("Inserting string %s with id %d", kmp->u.start, id); \
@@ -71,7 +71,7 @@ test1(void)
 #define KMPS_MERGE_CONTROLS
 #define KMPS_FOUND(kmp,src,s) TRACE("String %s with id %d found", s->out->u.str, s->out->u.id)
 #define KMPS_STEP(kmp,src,s) TRACE("Got to state %p after reading %d", s->s, s->c)
 #define KMPS_MERGE_CONTROLS
 #define KMPS_FOUND(kmp,src,s) TRACE("String %s with id %d found", s->out->u.str, s->out->u.id)
 #define KMPS_STEP(kmp,src,s) TRACE("Got to state %p after reading %d", s->s, s->c)
-#include "ucw/kmp.h"
+#include <ucw/kmp.h>
 
 static void
 test2(void)
 
 static void
 test2(void)
@@ -96,56 +96,56 @@ test2(void)
 /* TEST3 - random tests */
 
 #define KMP_PREFIX(x) kmp3_##x
 /* TEST3 - random tests */
 
 #define KMP_PREFIX(x) kmp3_##x
-#define KMP_STATE_VARS uns index;
-#define KMP_ADD_EXTRA_ARGS uns index
+#define KMP_STATE_VARS uint index;
+#define KMP_ADD_EXTRA_ARGS uint index
 #define KMP_VARS char *start;
 #define KMP_ADD_INIT(kmp,src) kmp->u.start = src
 #define KMP_ADD_NEW(kmp,src,s) s->u.index = index
 #define KMP_ADD_DUP(kmp,src,s) *(kmp->u.start) = 0
 #define KMP_WANT_CLEANUP
 #define KMP_WANT_SEARCH
 #define KMP_VARS char *start;
 #define KMP_ADD_INIT(kmp,src) kmp->u.start = src
 #define KMP_ADD_NEW(kmp,src,s) s->u.index = index
 #define KMP_ADD_DUP(kmp,src,s) *(kmp->u.start) = 0
 #define KMP_WANT_CLEANUP
 #define KMP_WANT_SEARCH
-#define KMPS_VARS uns sum, *cnt;
+#define KMPS_VARS uint sum, *cnt;
 #define KMPS_FOUND(kmp,src,s) do{ ASSERT(s->u.cnt[s->out->u.index]); s->u.cnt[s->out->u.index]--; s->u.sum--; }while(0)
 #define KMPS_FOUND(kmp,src,s) do{ ASSERT(s->u.cnt[s->out->u.index]); s->u.cnt[s->out->u.index]--; s->u.sum--; }while(0)
-#include "ucw/kmp.h"
+#include <ucw/kmp.h>
 
 static void
 test3(void)
 {
   TRACE("Running test3");
   struct mempool *pool = mp_new(1024);
 
 static void
 test3(void)
 {
   TRACE("Running test3");
   struct mempool *pool = mp_new(1024);
-  for (uns testn = 0; testn < 100; testn++)
+  for (uint testn = 0; testn < 100; testn++)
   {
     mp_flush(pool);
   {
     mp_flush(pool);
-    uns n = random_max(100);
+    uint n = random_max(100);
     char *s[n];
     struct kmp3_struct kmp;
     kmp3_init(&kmp);
     char *s[n];
     struct kmp3_struct kmp;
     kmp3_init(&kmp);
-    for (uns i = 0; i < n; i++)
+    for (uint i = 0; i < n; i++)
       {
       {
-        uns m = random_max(10);
+        uint m = random_max(10);
         s[i] = mp_alloc(pool, m + 1);
         s[i] = mp_alloc(pool, m + 1);
-        for (uns j = 0; j < m; j++)
+        for (uint j = 0; j < m; j++)
          s[i][j] = 'a' + random_max(3);
         s[i][m] = 0;
         kmp3_add(&kmp, s[i], i);
       }
     kmp3_build(&kmp);
          s[i][j] = 'a' + random_max(3);
         s[i][m] = 0;
         kmp3_add(&kmp, s[i], i);
       }
     kmp3_build(&kmp);
-    for (uns i = 0; i < 10; i++)
+    for (uint i = 0; i < 10; i++)
       {
       {
-        uns m = random_max(100);
+        uint m = random_max(100);
         byte b[m + 1];
         byte b[m + 1];
-        for (uns j = 0; j < m; j++)
+        for (uint j = 0; j < m; j++)
          b[j] = 'a' + random_max(4);
         b[m] = 0;
          b[j] = 'a' + random_max(4);
         b[m] = 0;
-        uns cnt[n];
+        uint cnt[n];
        struct kmp3_search search;
        search.u.sum = 0;
        search.u.cnt = cnt;
        struct kmp3_search search;
        search.u.sum = 0;
        search.u.cnt = cnt;
-        for (uns j = 0; j < n; j++)
+        for (uint j = 0; j < n; j++)
           {
            cnt[j] = 0;
            if (*s[j])
           {
            cnt[j] = 0;
            if (*s[j])
-             for (uns k = 0; k < m; k++)
+             for (uint k = 0; k < m; k++)
                if (!strncmp(b + k, s[j], strlen(s[j])))
                  cnt[j]++, search.u.sum++;
          }
                if (!strncmp(b + k, s[j], strlen(s[j])))
                  cnt[j]++, search.u.sum++;
          }
@@ -168,10 +168,10 @@ kmp4_eq(struct kmp4_struct *kmp UNUSED, byte *a, byte *b)
   return (a == b) || (a && b && *a == *b);
 }
 
   return (a == b) || (a && b && *a == *b);
 }
 
-static inline uns
+static inline uint
 kmp4_hash(struct kmp4_struct *kmp UNUSED, struct kmp4_state *s, byte *c)
 {
 kmp4_hash(struct kmp4_struct *kmp UNUSED, struct kmp4_state *s, byte *c)
 {
-  return (c ? (*c << 16) : 0) + (uns)(uintptr_t)s;
+  return (c ? (*c << 16) : 0) + (uint)(uintptr_t)s;
 }
 
 #define KMP_PREFIX(x) kmp4_##x
 }
 
 #define KMP_PREFIX(x) kmp4_##x
@@ -185,7 +185,7 @@ kmp4_hash(struct kmp4_struct *kmp UNUSED, struct kmp4_state *s, byte *c)
 #define KMPS_FOUND(kmp,src,s) TRACE("found")
 #define KMPS_ADD_CONTROLS
 #define KMPS_MERGE_CONTROLS
 #define KMPS_FOUND(kmp,src,s) TRACE("found")
 #define KMPS_ADD_CONTROLS
 #define KMPS_MERGE_CONTROLS
-#include "ucw/kmp.h"
+#include <ucw/kmp.h>
 
 static void
 test4(void)
 
 static void
 test4(void)
@@ -203,7 +203,7 @@ int
 main(void)
 {
   test1();
 main(void)
 {
   test1();
-#ifndef CONFIG_UCW_ONLY
+#ifdef CONFIG_CHARSET
   test2();
 #endif
   test3();
   test2();
 #endif
   test3();