# ifdef KMPS_WANT_BEST
s->best = &kmp->null;
# endif
-# ifdef KMPS_ADD_CONTROLS
+# ifdef KMPS_ADD_CONTROLS
s->c = KP(control)();
s->eof = 0;
# else
s->c = 0;
-# endif
+# endif
# ifdef KMPS_INIT
{ KMPS_INIT(kmp, src, s); }
# endif
-# ifndef KMPS_ADD_CONTROLS
+# ifndef KMPS_ADD_CONTROLS
goto start_read;
-#endif
+#endif
for (;;)
{
for (struct KP(state) *t = s->s; t && !(s->s = KP(hash_find)(&kmp->hash, t, s->c)); t = t->back);
s->out = s->s->len ? s->s : s->s->next;
if (s->out)
{
-# ifdef KMPS_WANT_BEST
+# ifdef KMPS_WANT_BEST
if (s->out->len > s->best->len)
s->best = s->out;
-# endif
- #ifdef KMPS_FOUND_CHAIN
+# endif
+# ifdef KMPS_FOUND_CHAIN
{ KMPS_FOUND_CHAIN(kmp, src, s); }
# endif
# ifdef KMPS_FOUND
do
{ KMPS_FOUND(kmp, src, s); }
while (s->out = s->out->next);
-# endif
+# endif
}
# endif
-# ifdef KMPS_ADD_CONTROLS
+# ifdef KMPS_ADD_CONTROLS
if (s->eof)
break;
-# endif
+# endif
-# ifndef KMPS_ADD_CONTROLS
+# ifndef KMPS_ADD_CONTROLS
start_read: ;
-# endif
+# endif
# ifdef KMPS_MERGE_CONTROLS
KP(char_t) last_c = s->c;
# endif
#undef KMPS_EXIT
#undef KMPS_FOUND
#undef KMPS_FOUND_CHAIN
-#undef KMPS_STEP
#undef KMPS_WANT_BEST
+#undef KMPS_STEP
#define KMPS_PREFIX(x) GLUE_(kmp1s1,x)
#define KMPS_KMP_PREFIX(x) GLUE_(kmp1,x)
#define KMPS_WANT_BEST
+#define KMPS_EXIT(kmp,src,s) TRACE("Best match has %d characters", s->best->len)
#include "lib/kmp-search.h"
#define KMPS_PREFIX(x) GLUE_(kmp1s2,x)
#define KMPS_KMP_PREFIX(x) GLUE_(kmp1,x)
#define KMPS_VARS uns 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 "lib/kmp-search.h"
static void
kmp1_build(&kmp);
struct kmp1s1_search s1;
kmp1s1_search(&kmp, &s1, "asjlahslhalahosjkjhojsas");
- TRACE("Best match has %d characters", s1.best->len);
ASSERT(s1.best->len == 3);
struct kmp1s2_search s2;
kmp1s2_search(&kmp, &s2, "asjlahslhalahojsjkjhojsas");
#define KMP_STATE_VARS byte *str; uns id;
#define KMP_ADD_EXTRA_ARGS uns id
#define KMP_VARS byte *start;
-#define KMP_ADD_INIT(kmp,src) kmp->u.start = src;
+#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); \
s->u.str = kmp->u.start; s->u.id = id; }while(0)
-#define KMP_ADD_DUP(kmp,src,s) TRACE("String %s already inserted", kmp->u.start);
+#define KMP_ADD_DUP(kmp,src,s) TRACE("String %s already inserted", kmp->u.start)
#define KMP_WANT_CLEANUP
#define KMP_WANT_SEARCH
#define KMPS_ADD_CONTROLS
#define KMPS_MERGE_CONTROLS
-#define KMPS_WANT_BEST
-#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_EXIT(kmp,src,s) do{ if (s->best->len) TRACE("Best match is %s", s->best->u.str); } while(0)
+#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 "lib/kmp.h"
static void
#define KMP_STATE_VARS uns index;
#define KMP_ADD_EXTRA_ARGS uns index
#define KMP_VARS byte *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_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 KMP_GIVE_EQ
#define KMP_WANT_CLEANUP
#define KMP_WANT_SEARCH
-#define KMPS_FOUND(kmp,src,s) do{ TRACE("found"); }while(0)
+#define KMPS_FOUND(kmp,src,s) TRACE("found")
#define KMPS_ADD_CONTROLS
#define KMPS_MERGE_CONTROLS
#include "lib/kmp.h"