10 the original, recursive function. Needs replacing, but with exactly
13 static int fnmatch_orig(const char *p, const char *n)
26 if (! n[1] && fnmatch_orig(p, n+1) == 0) return 0;
27 if (fnmatch_orig(p, n) == 0) return 0;
30 if (! *n) return fnmatch_orig(p, n);
36 if (fnmatch_orig(p, n) == 0) return 0;
42 if (fnmatch_orig(p, n) == 0) return 0;
43 if (*n == '.' && !strchr(n+1,'.')) {
51 if (*n == 0 && fnmatch_orig(p, n) == 0) return 0;
52 if (*n != '.') return -1;
57 if (c != *n && toupper(c) != toupper(*n)) return -1;
69 the new, hopefully better function. Fiddle this until it works and is fast
71 static int fnmatch_test(const char *p, const char *n)
84 if (! n[1] && fnmatch_test(p, n+1) == 0) return 0;
85 if (fnmatch_test(p, n) == 0) return 0;
88 if (! *n) return fnmatch_test(p, n);
94 if (fnmatch_test(p, n) == 0) return 0;
100 if (fnmatch_test(p, n) == 0) return 0;
101 if (*n == '.' && !strchr(n+1,'.')) {
109 if (*n == 0 && fnmatch_test(p, n) == 0) return 0;
110 if (*n != '.') return -1;
115 if (c != *n && toupper(c) != toupper(*n)) return -1;
126 static void randstring(char *s, int len, const char *chars)
129 *s++ = chars[random() % strlen(chars)];
134 static void sig_alrm(int sig)
136 printf("Too slow!!\n");
145 signal(SIGALRM, sig_alrm);
148 fnmatch_test("********************************************.dat", "foobar.txt");
149 fnmatch_test("*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<*<.dat", "foobar.txt");
152 for (i=0;i<100000;i++) {
153 int len1 = random() % 20;
154 int len2 = random() % 20;
155 char *p = malloc(len1+1);
156 char *n = malloc(len2+1);
159 randstring(p, len1, "*?<>\".abc");
160 randstring(n, len2, "abc.");
162 ret1 = fnmatch_orig(p, n);
163 ret2 = fnmatch_test(p, n);
166 printf("mismatch: ret1=%d ret2=%d pattern='%s' string='%s'\n",