From 0caabbdf529cf2dbcea4587ecae7f69fe01a4628 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 2 May 1997 17:20:39 +0000 Subject: [PATCH] match_pattern_nocase --- lib/lib.h | 3 ++- lib/patimatch.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lib/patimatch.c diff --git a/lib/lib.h b/lib/lib.h index 929fa9bf..5ece34a6 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -114,9 +114,10 @@ FILE *create_obj_file(byte *, ulg); int wordsplit(byte *, byte **, uns); -/* patmatch.c */ +/* pat(i)match.c */ int match_pattern(byte *, byte *); +int match_pattern_nocase(byte *, byte *); /* md5hex.c */ diff --git a/lib/patimatch.c b/lib/patimatch.c new file mode 100644 index 00000000..5458d323 --- /dev/null +++ b/lib/patimatch.c @@ -0,0 +1,38 @@ +/* + * Sherlock Library -- Shell-Like Case-Insensitive Pattern Matching (currently only '?' and '*') + * + * (c) 1997 Martin Mares, + */ + +#include +#include + +#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]; + + if (!z) + return 1; + while (s = strchr(s, z)) + { + if (match_pattern_nocase(p+1, s)) + return 1; + s++; + } + return 0; + } + else if (Cupcase(*p++) != Cupcase(*s++)) + return 0; + } + return !*s; +} -- 2.39.2