From: Martin Mares Date: Tue, 2 Dec 1997 09:56:19 +0000 (+0000) Subject: New pattern matching code -- simplified and debugged. X-Git-Tag: holmes-import~1686 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=fab01e0b82bb1678b168fe56940aaa555c3360d5;p=libucw.git New pattern matching code -- simplified and debugged. --- diff --git a/lib/patimatch.c b/lib/patimatch.c index 8a0c8851..fa651b06 100644 --- a/lib/patimatch.c +++ b/lib/patimatch.c @@ -10,34 +10,7 @@ #include "lib.h" #include "string.h" -int -match_pattern_nocase(byte *p, byte *s) -{ - while (*p) - { - if (*p == '?' && *s) - p++, s++; - else if (*p == '*') - { - int z = p[1]; +#define Convert(x) Cupcase(x) +#define MATCH_FUNC_NAME match_pattern_nocase - if (!z) - return 1; - while (s = strchr(s, z)) - { - if (match_pattern_nocase(p+1, s)) - return 1; - s++; - } - return 0; - } - else - { - if (*p == '\\' && p[1]) - p++; - if (Cupcase(*p++) != Cupcase(*s++)) - return 0; - } - } - return !*s; -} +#include "patmatch.h" diff --git a/lib/patmatch.c b/lib/patmatch.c index c1d60932..53a0710a 100644 --- a/lib/patmatch.c +++ b/lib/patmatch.c @@ -9,34 +9,7 @@ #include "lib.h" -int -match_pattern(byte *p, byte *s) -{ - while (*p) - { - if (*p == '?' && *s) - p++, s++; - else if (*p == '*') - { - int z = p[1]; +#define Convert(x) (x) +#define MATCH_FUNC_NAME match_pattern - if (!z) - return 1; - while (s = strchr(s, z)) - { - if (match_pattern(p+1, s)) - return 1; - s++; - } - return 0; - } - else - { - if (*p == '\\' && p[1]) - p++; - if (*p++ != *s++) - return 0; - } - } - return !*s; -} +#include "patmatch.h" diff --git a/lib/patmatch.h b/lib/patmatch.h new file mode 100644 index 00000000..6d51216b --- /dev/null +++ b/lib/patmatch.h @@ -0,0 +1,42 @@ +/* + * Sherlock Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*') + * + * (c) 1997 Martin Mares, + */ + +int +MATCH_FUNC_NAME(byte *p, byte *s) +{ + while (*p) + { + if (*p == '?' && *s) + p++, s++; + else if (*p == '*') + { + int z = p[1]; + + if (!z) + return 1; + if (z == '\\' && p[2]) + z = p[2]; + z = Convert(z); + while (*s) + { + while (*s && Convert(*s) != z) + s++; + if (*s && match_pattern(p+1, s)) + return 1; + s++; + } + return 0; + } + else + { + if (*p == '\\' && p[1]) + p++; + if (Convert(*p++) != Convert(*s++)) + return 0; + } + } + return !*s; +}