wildmatch: remove static variable force_lower_case
One place less to worry about thread safety. Also combine wildmatch and iwildmatch into one. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Oct 15, 2012 at 13:25 UTC
9b4edc0a49abd4b5c6505c63c8fa40d527df6ae8
3 files changed
+8
-20
test-wildmatch.c
+2
-2
@@ -4,9 +4,9 @@
4
int main(int argc, char **argv)
5
{
6
if (!strcmp(argv[1], "wildmatch"))
7
- return !!wildmatch(argv[3], argv[2]);
7
+ return !!wildmatch(argv[3], argv[2], 0);
8
else if (!strcmp(argv[1], "iwildmatch"))
9
- return !!iwildmatch(argv[3], argv[2]);
9
+ return !!wildmatch(argv[3], argv[2], FNM_CASEFOLD);
10
else if (!strcmp(argv[1], "fnmatch"))
11
return !!fnmatch(argv[3], argv[2], FNM_PATHNAME);
12
else
wildmatch.c
+5
-16
@@ -59,10 +59,8 @@ typedef unsigned char uchar;
59
#define ISUPPER(c) (ISASCII(c) && isupper(c))
60
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
61
62
-static int force_lower_case = 0;
63
-
62
/* Match pattern "p" against "text" */
65
-static int dowild(const uchar *p, const uchar *text)
63
+static int dowild(const uchar *p, const uchar *text, int force_lower_case)
64
{
65
uchar p_ch;
66
@@ -106,7 +104,7 @@ static int dowild(const uchar *p, const uchar *text)
104
while (1) {
105
if (t_ch == '\0')
106
break;
109
- if ((matched = dowild(p, text)) != NOMATCH) {
107
+ if ((matched = dowild(p, text, force_lower_case)) != NOMATCH) {
108
if (!special || matched != ABORT_TO_STARSTAR)
109
return matched;
110
} else if (!special && t_ch == '/')
@@ -214,17 +212,8 @@ static int dowild(const uchar *p, const uchar *text)
212
}
213
214
/* Match the "pattern" against the "text" string. */
217
-int wildmatch(const char *pattern, const char *text)
218
-{
219
- return dowild((const uchar*)pattern, (const uchar*)text);
220
-}
221
-
222
-/* Match the "pattern" against the forced-to-lower-case "text" string. */
223
-int iwildmatch(const char *pattern, const char *text)
215
+int wildmatch(const char *pattern, const char *text, int flags)
216
{
225
- int ret;
226
- force_lower_case = 1;
227
- ret = dowild((const uchar*)pattern, (const uchar*)text);
228
- force_lower_case = 0;
229
- return ret;
217
+ return dowild((const uchar*)pattern, (const uchar*)text,
218
+ flags & FNM_CASEFOLD ? 1 :0);
219
}
wildmatch.h
+1
-2
@@ -1,4 +1,3 @@
1
/* wildmatch.h */
2
3
-int wildmatch(const char *pattern, const char *text);
4
-int iwildmatch(const char *pattern, const char *text);
3
+int wildmatch(const char *pattern, const char *text, int flags);