From: Pavel Charvat Date: Thu, 20 Apr 2006 11:36:42 +0000 (+0200) Subject: Removed KMP_ADD_EXTRA_VAR and some useless parenteses. X-Git-Tag: holmes-import~645^2~16 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=e1ccb1a25eae9368b00589d948cc0e23718f2fbb;p=libucw.git Removed KMP_ADD_EXTRA_VAR and some useless parenteses. --- diff --git a/lib/kmp-search.h b/lib/kmp-search.h index a2fc9864..e5049993 100644 --- a/lib/kmp-search.h +++ b/lib/kmp-search.h @@ -24,7 +24,7 @@ * KMPS_GET_CHAR(kmp,src,s) * * KMPS_ADD_CONTROLS add control characters at both ends of the input string - * KMPS_MERGE_CONTROLS merge adjacent control characters to a single onei + * KMPS_MERGE_CONTROLS merge adjacent control characters to a single one * * KMPS_VARS * @@ -47,7 +47,7 @@ typedef KP(source_t) P(search_source_t); #endif #ifndef KMPS_GET_CHAR -#define KMPS_GET_CHAR(kmp,src,s) ({ KP(get_char)(kmp, &src, &s->c); }) +#define KMPS_GET_CHAR(kmp,src,s) (KP(get_char)(kmp, &src, &s->c)) #endif struct P(search) { diff --git a/lib/kmp-test.c b/lib/kmp-test.c index 6156edbf..4f8890ae 100644 --- a/lib/kmp-test.c +++ b/lib/kmp-test.c @@ -26,8 +26,8 @@ #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 @@ -58,18 +58,18 @@ test1(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" @@ -96,10 +96,10 @@ test2(void) #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; diff --git a/lib/kmp.h b/lib/kmp.h index f061e337..d4836988 100644 --- a/lib/kmp.h +++ b/lib/kmp.h @@ -39,10 +39,9 @@ * * 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 @@ -274,11 +273,8 @@ P(add) (struct P(struct) *kmp, P(source_t) src # 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; @@ -302,21 +298,17 @@ P(add) (struct P(struct) *kmp, P(source_t) src 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; } @@ -401,7 +393,6 @@ P(build) (struct P(struct) *kmp) #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