From bb6724bf85974d21c2095815d7c932afac7acb97 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Mon, 22 Sep 2014 19:40:01 +0200
Subject: [PATCH] Removed unused util_wildmatch function.

This was only used to test the wildmatching, but the autocmd allow always to
match against list of patterns.
---
 src/autocmd.c     |  4 ++--
 src/util.c        | 38 +++++++++++++++++---------------------
 src/util.h        |  3 +--
 tests/test-util.c | 24 +++++++++++-------------
 4 files changed, 31 insertions(+), 38 deletions(-)

diff --git a/src/autocmd.c b/src/autocmd.c
index ea030fb..179c70d 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -204,7 +204,7 @@ gboolean autocmd_add(char *name, gboolean delete)
             }
             /* skip if pattern does not match - we check the pattern against
              * another pattern */
-            if (!util_wildmatch_multi(pattern, cmd->pattern)) {
+            if (!util_wildmatch(pattern, cmd->pattern)) {
                 continue;
             }
             /* remove the bits from the item */
@@ -274,7 +274,7 @@ gboolean autocmd_run(AuEvent event, const char *uri, const char *group)
             }
             /* check pattern only if uri was given */
             /* skip if pattern does not match */
-            if (uri && !util_wildmatch_multi(cmd->pattern, uri)) {
+            if (uri && !util_wildmatch(cmd->pattern, uri)) {
                 continue;
             }
             /* run the command */
diff --git a/src/util.c b/src/util.c
index e42fc57..516ed17 100644
--- a/src/util.c
+++ b/src/util.c
@@ -512,15 +512,22 @@ gboolean util_parse_expansion(const char **input, GString *str, int flags,
 }
 
 /**
- * Like util_wildmatch, but allow to use a list of patterns,
+ * Compares given string against also given list of patterns.
+ *
+ * *         Matches any sequence of characters.
+ * ?         Matches any single character except of '/'.
+ * {foo,bar} Matches foo or bar - '{', ',' and '}' within this pattern must be
+ *           escaped by '\'. '*' and '?' have no special meaning within the
+ *           curly braces.
+ * *?{}      these chars must always be escaped by '\' to match them literally
  */
-gboolean util_wildmatch_multi(const char *pattern, const char *subject)
+gboolean util_wildmatch(const char *pattern, const char *subject)
 {
     const char *end;
-    int braces, patlen;
+    int braces, patlen, count;
 
     /* loop through all pattens */
-    for (; *pattern; pattern = (*end == ',' ? end + 1 : end)) {
+    for (count = 0; *pattern; pattern = (*end == ',' ? end + 1 : end), count++) {
         /* find end of the pattern - but be careful with comma in curly braces */
         braces = 0;
         for (end = pattern; *end && (*end != ',' || braces || *(end - 1) == '\\'); ++end) {
@@ -543,23 +550,12 @@ gboolean util_wildmatch_multi(const char *pattern, const char *subject)
         }
     }
 
-    /* empty pattern matches only on empty subject */
-    return !*subject;
-}
-
-/**
- * Compares given string against also given pattern.
- *
- * *         Matches any sequence of characters.
- * ?         Matches any single character except of '/'.
- * {foo,bar} Matches foo or bar - '{', ',' and '}' within this pattern must be
- *           escaped by '\'. '*' and '?' have no special meaning within the
- *           curly braces.
- * *?{}      these chars must always be escaped by '\' to match them literally
- */
-gboolean util_wildmatch(const char *pattern, const char *subject)
-{
-    return match(pattern, strlen(pattern), subject);
+    if (!count) {
+        /* empty pattern matches only on empty subject */
+        return !*subject;
+    }
+    /* there where one or more patterns but none of them matched */
+    return false;
 }
 
 /**
diff --git a/src/util.h b/src/util.h
index 938d789..e21d7a0 100644
--- a/src/util.h
+++ b/src/util.h
@@ -49,8 +49,7 @@ char *util_build_path(const char *path, const char *dir);
 char *util_expand(const char *src, int expflags);
 gboolean util_parse_expansion(const char **input, GString *str, int flags,
     const char *quoteable);
-gboolean util_wildmatch_multi(const char *pattern, const char *subject);
-gboolean util_wildmatch(const char *pattern, const char *string);
+gboolean util_wildmatch(const char *pattern, const char *subject);
 gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src);
 
 #endif /* end of include guard: _UTIL_H */
diff --git a/tests/test-util.c b/tests/test-util.c
index b89d620..62b924c 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -250,19 +250,17 @@ static void test_wildmatch_complete(void)
 
 static void test_wildmatch_multi(void)
 {
-    /* check if sinlge pattern matching works */
-    g_assert_true(util_wildmatch_multi("", ""));
-    g_assert_true(util_wildmatch_multi("single", "single"));
-    g_assert_true(util_wildmatch_multi("s*e", "single"));
-
-    g_assert_true(util_wildmatch_multi("foo,b{a,o,}r,ba?", "foo"));
-    g_assert_true(util_wildmatch_multi("foo,b{a,o,}r,ba?", "bar"));
-    g_assert_true(util_wildmatch_multi("foo,b{a,o,}r,ba?", "bor"));
-    g_assert_true(util_wildmatch_multi("foo,b{a,o,}r,ba?", "br"));
-    g_assert_true(util_wildmatch_multi("foo,b{a,o,}r,ba?", "baz"));
-    g_assert_true(util_wildmatch_multi("foo,b{a,o,}r,ba?", "bat"));
-
-    g_assert_false(util_wildmatch_multi("foo,b{a,o,}r,ba?", "foo,"));
+    g_assert_true(util_wildmatch("foo,?", "foo"));
+    g_assert_true(util_wildmatch("foo,?", "f"));
+    g_assert_true(util_wildmatch("foo,b{a,o,}r,ba?", "foo"));
+    g_assert_true(util_wildmatch("foo,b{a,o,}r,ba?", "bar"));
+    g_assert_true(util_wildmatch("foo,b{a,o,}r,ba?", "bor"));
+    g_assert_true(util_wildmatch("foo,b{a,o,}r,ba?", "br"));
+    g_assert_true(util_wildmatch("foo,b{a,o,}r,ba?", "baz"));
+    g_assert_true(util_wildmatch("foo,b{a,o,}r,ba?", "bat"));
+
+    g_assert_false(util_wildmatch("foo,b{a,o,}r,ba?", "foo,"));
+    g_assert_false(util_wildmatch("foo,?", "fo"));
 }
 
 int main(int argc, char *argv[])
-- 
2.20.1