#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) do{ s->u.count = 0; }while(0)
-#define KMPS_FOUND(kmp,src,s) do{ s->u.count++; }while(0)
+#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
#define KMP_ONLYALPHA
#define KMP_STATE_VARS byte *str; uns id;
#define KMP_ADD_EXTRA_ARGS uns id
-#define KMP_ADD_EXTRA_VAR byte *
-#define KMP_ADD_INIT(kmp,src,v) do{ v = src; }while(0)
-#define KMP_ADD_NEW(kmp,src,v,s) do{ TRACE("Inserting string %s with id %d", v, id); \
- s->u.str = v; s->u.id = id; }while(0)
-#define KMP_ADD_DUP(kmp,src,v,s) do{ TRACE("String %s already inserted", v); }while(0)
+#define KMP_VARS byte *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); \
+ 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_WANT_CLEANUP
#define KMP_WANT_SEARCH
#define KMPS_ADD_CONTROLS
#define KMPS_MERGE_CONTROLS
#define KMPS_WANT_BEST
-#define KMPS_FOUND(kmp,src,s) do{ TRACE("String %s with id %d found", s->out->u.str, s->out->u.id); }while(0)
-#define KMPS_STEP(kmp,src,s) do{ TRACE("Got to state %p after reading %d", s->s, s->c); }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);
#define KMPS_EXIT(kmp,src,s) do{ if (s->best->len) TRACE("Best match is %s", s->best->u.str); } while(0)
#include "lib/kmp.h"
#define KMP_PREFIX(x) GLUE_(kmp3,x)
#define KMP_STATE_VARS uns index;
#define KMP_ADD_EXTRA_ARGS uns index
-#define KMP_ADD_EXTRA_VAR byte *
-#define KMP_ADD_INIT(kmp,src,v) do{ v = src; }while(0)
-#define KMP_ADD_NEW(kmp,src,v,s) do{ s->u.index = index; }while(0)
-#define KMP_ADD_DUP(kmp,src,v,s) do{ *v = 0; }while(0)
+#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_WANT_CLEANUP
#define KMP_WANT_SEARCH
#define KMPS_VARS uns sum, *cnt;
*
* Parameters controlling add():
* KMP_ADD_EXTRA_ARGS extra arguments
- * KMP_ADD_EXTRA_VAR structure with extra local variables
- * KMP_ADD_INIT(kmp,src,v)
- * KMP_ADD_NEW(kmp,src,v,s)
- * KMP_ADD_DUP(kmp,src,v,s)
+ * KMP_ADD_INIT(kmp,src)
+ * KMP_ADD_NEW(kmp,src,s)
+ * KMP_ADD_DUP(kmp,src,s)
*
* Parameters to build():
* KMP_BUILD_STATE(kmp,s) called for all states (including null) in order of non-decreasing tree depth
# endif
)
{
-# ifdef KMP_ADD_EXTRA_VAR
- KMP_ADD_EXTRA_VAR v;
-# endif
# ifdef KMP_ADD_INIT
- { KMP_ADD_INIT(kmp, src, v); }
+ { KMP_ADD_INIT(kmp, src); }
# endif
P(char_t) c;
len++;
}
while (P(get_char)(kmp, &src, &c));
-# ifdef KMP_NO_DUPS
- ASSERT(!s->len);
-# else
if (s->len)
{
# ifdef KMP_ADD_DUP
- { KMP_ADD_DUP(kmp, src, v, s); }
+ { KMP_ADD_DUP(kmp, src, s); }
# endif
return s;
}
-# endif
enter_new:
s->len = len;
# ifdef KMP_ADD_NEW
- { KMP_ADD_NEW(kmp, src, v, s); }
+ { KMP_ADD_NEW(kmp, src, s); }
# endif
return s;
}
#undef KMP_ONLYALPHA
#undef KMP_CONTROL_CHAR
#undef KMP_ADD_EXTRA_ARGS
-#undef KMP_ADD_EXTRA_VAR
#undef KMP_ADD_INIT
#undef KMP_ADD_NEW
#undef KMP_ADD_DUP