globmatch: Add globmatch to wrap fnmatch
[src/app-framework-binder.git] / src / globset.c
index 2bad449..0ea448b 100644 (file)
@@ -22,8 +22,7 @@
 #include <errno.h>
 
 #include "globset.h"
-
-#define GLOB '*'
+#include "globmatch.h"
 
 /*************************************************************************
  * internal types
@@ -62,49 +61,6 @@ struct globset
        unsigned count;
 };
 
-/**
- * Matches whether the string 'str' matches the pattern 'pat'
- * and returns its matching score.
- *
- * @param pat the glob pattern
- * @param str the string to match
- * @return 0 if no match or number representing the matching score
- */
-static unsigned match(const char *pat, const char *str)
-{
-       unsigned r, rs, rr;
-       char c;
-
-       /* scan the prefix without glob */
-       r = 1;
-       while ((c = *pat++) != GLOB) {
-               if (c != *str++)
-                       return 0; /* no match */
-               if (!c)
-                       return r; /* match up to end */
-               r++;
-       }
-
-       /* glob found */
-       c = *pat++;
-       if (!c)
-               return r; /* not followed by pattern */
-
-       /* evaluate the best score for following pattern */
-       rs = 0;
-       while (*str) {
-               if (*str++ == c) {
-                       /* first char matches, check remaining string */
-                       rr = match(pat, str);
-                       if (rr > rs)
-                               rs = rr;
-               }
-       }
-
-       /* best score or not match if rs == 0 */
-       return rs ? rs + r : 0;
-}
-
 /**
  * Normalize the string 'from' to the string 'to' and computes the hash code.
  * The normalization translates upper characters to lower characters.
@@ -235,13 +191,6 @@ static struct pathndl *search(
        return ph;
 }
 
-
-
-
-
-
-
-
 /**
  * Allocates a new set of handlers
  *
@@ -436,7 +385,7 @@ const struct globset_handler *globset_match(
                s = 0;
                iph = set->globs;
                while(iph) {
-                       g = match(iph->handler.pattern, txt);
+                       g = globmatch(iph->handler.pattern, txt);
                        if (g > s) {
                                s = g;
                                ph = iph;