Author: mladen.turk(a)jboss.com
Date: 2007-09-20 02:14:06 -0400 (Thu, 20 Sep 2007)
New Revision: 1033
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/share/jnu.c
Log:
Add wildchar matching function
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-09-19 09:21:52 UTC (rev 1032)
+++ trunk/sight/native/include/sight_local.h 2007-09-20 06:14:06 UTC (rev 1033)
@@ -151,6 +151,7 @@
const char *, int);
char *sight_strdup(JNIEnv *, const char *,
const char *, int);
+int sight_wmatch(const char *, const char *);
/* Array prototypes */
sight_arr_t *sight_arr_new(jsize);
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-19 09:21:52 UTC (rev 1032)
+++ trunk/sight/native/share/jnu.c 2007-09-20 06:14:06 UTC (rev 1033)
@@ -963,3 +963,32 @@
memcpy(dst, tmp, size);
return len;
}
+
+/* Match = 0, NoMatch = 1, Abort = -1
+ * Based loosely on sections of wildmat.c by Rich Salz
+ */
+int sight_wmatch(const char *str, const char *exp)
+{
+ int x, y;
+
+ for (x = 0, y = 0; exp[y]; ++y, ++x) {
+ if (!str[x] && exp[y] != '*')
+ return -1;
+ if (exp[y] == '*') {
+ while (exp[++y] == '*');
+ if (!exp[y])
+ return 0;
+ while (str[x]) {
+ int ret;
+ if ((ret = sight_wmatch(&str[x++], &exp[y])) != 1)
+ return ret;
+ }
+ return -1;
+ }
+ else if (exp[y] != '?') {
+ if (str[x] != exp[y])
+ return 1;
+ }
+ }
+ return (str[x] != '\0');
+}
Show replies by date