1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-10 12:16:12 +02:00

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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2012-10-15 13:25:58 +07:00 committed by Junio C Hamano
parent 3ae5396cf7
commit 9b4edc0a49
3 changed files with 8 additions and 20 deletions

View File

@ -4,9 +4,9 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (!strcmp(argv[1], "wildmatch")) if (!strcmp(argv[1], "wildmatch"))
return !!wildmatch(argv[3], argv[2]); return !!wildmatch(argv[3], argv[2], 0);
else if (!strcmp(argv[1], "iwildmatch")) else if (!strcmp(argv[1], "iwildmatch"))
return !!iwildmatch(argv[3], argv[2]); return !!wildmatch(argv[3], argv[2], FNM_CASEFOLD);
else if (!strcmp(argv[1], "fnmatch")) else if (!strcmp(argv[1], "fnmatch"))
return !!fnmatch(argv[3], argv[2], FNM_PATHNAME); return !!fnmatch(argv[3], argv[2], FNM_PATHNAME);
else else

View File

@ -59,10 +59,8 @@ typedef unsigned char uchar;
#define ISUPPER(c) (ISASCII(c) && isupper(c)) #define ISUPPER(c) (ISASCII(c) && isupper(c))
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c)) #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
static int force_lower_case = 0;
/* Match pattern "p" against "text" */ /* Match pattern "p" against "text" */
static int dowild(const uchar *p, const uchar *text) static int dowild(const uchar *p, const uchar *text, int force_lower_case)
{ {
uchar p_ch; uchar p_ch;
@ -106,7 +104,7 @@ static int dowild(const uchar *p, const uchar *text)
while (1) { while (1) {
if (t_ch == '\0') if (t_ch == '\0')
break; break;
if ((matched = dowild(p, text)) != NOMATCH) { if ((matched = dowild(p, text, force_lower_case)) != NOMATCH) {
if (!special || matched != ABORT_TO_STARSTAR) if (!special || matched != ABORT_TO_STARSTAR)
return matched; return matched;
} else if (!special && t_ch == '/') } else if (!special && t_ch == '/')
@ -214,17 +212,8 @@ static int dowild(const uchar *p, const uchar *text)
} }
/* Match the "pattern" against the "text" string. */ /* Match the "pattern" against the "text" string. */
int wildmatch(const char *pattern, const char *text) int wildmatch(const char *pattern, const char *text, int flags)
{ {
return dowild((const uchar*)pattern, (const uchar*)text); return dowild((const uchar*)pattern, (const uchar*)text,
} flags & FNM_CASEFOLD ? 1 :0);
/* Match the "pattern" against the forced-to-lower-case "text" string. */
int iwildmatch(const char *pattern, const char *text)
{
int ret;
force_lower_case = 1;
ret = dowild((const uchar*)pattern, (const uchar*)text);
force_lower_case = 0;
return ret;
} }

View File

@ -1,4 +1,3 @@
/* wildmatch.h */ /* wildmatch.h */
int wildmatch(const char *pattern, const char *text); int wildmatch(const char *pattern, const char *text, int flags);
int iwildmatch(const char *pattern, const char *text);