All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 4/8] wildmatch: remove static variable force_lower_case
Date: Tue,  9 Oct 2012 10:09:03 +0700	[thread overview]
Message-ID: <1349752147-13314-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1349752147-13314-1-git-send-email-pclouds@gmail.com>

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>
---
 test-wildmatch.c |  4 ++--
 wildmatch.c      | 23 ++++++-----------------
 wildmatch.h      |  3 +--
 3 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/test-wildmatch.c b/test-wildmatch.c
index 08962d5..5c18cf8 100644
--- a/test-wildmatch.c
+++ b/test-wildmatch.c
@@ -4,9 +4,9 @@
 int main(int argc, char **argv)
 {
 	if (!strcmp(argv[1], "wildmatch"))
-		return wildmatch(argv[3], argv[2]) ? 0 : 1;
+		return wildmatch(argv[3], argv[2], 0) ? 0 : 1;
 	else if (!strcmp(argv[1], "iwildmatch"))
-		return iwildmatch(argv[3], argv[2]) ? 0 : 1;
+		return wildmatch(argv[3], argv[2], FNM_CASEFOLD) ? 0 : 1;
 	else if (!strcmp(argv[1], "fnmatch"))
 		return fnmatch(argv[3], argv[2], FNM_PATHNAME);
 	else
diff --git a/wildmatch.c b/wildmatch.c
index 7b64a6b..2382873 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -11,8 +11,8 @@
 
 #include <stddef.h>
 #include <ctype.h>
-#include <string.h>
 
+#include "cache.h"
 #include "wildmatch.h"
 
 typedef unsigned char uchar;
@@ -59,11 +59,9 @@ typedef unsigned char uchar;
 #define ISUPPER(c) (ISASCII(c) && isupper(c))
 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
 
-static int force_lower_case = 0;
-
 /* Match pattern "p" against the a virtually-joined string consisting
  * of "text" and any strings in array "a". */
-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;
 
@@ -107,7 +105,7 @@ static int dowild(const uchar *p, const uchar *text)
 	    while (1) {
 		if (t_ch == '\0')
 		    break;
-		if ((matched = dowild(p, text)) != FALSE) {
+		if ((matched = dowild(p, text, force_lower_case)) != FALSE) {
 		    if (!special || matched != ABORT_TO_STARSTAR)
 			return matched;
 		} else if (!special && t_ch == '/')
@@ -215,17 +213,8 @@ static int dowild(const uchar *p, const uchar *text)
 }
 
 /* Match the "pattern" against the "text" string. */
-int wildmatch(const char *pattern, const char *text)
-{
-    return dowild((const uchar*)pattern, (const uchar*)text) == TRUE;
-}
-
-/* Match the "pattern" against the forced-to-lower-case "text" string. */
-int iwildmatch(const char *pattern, const char *text)
+int wildmatch(const char *pattern, const char *text, int flags)
 {
-    int ret;
-    force_lower_case = 1;
-    ret = dowild((const uchar*)pattern, (const uchar*)text) == TRUE;
-    force_lower_case = 0;
-    return ret;
+    return dowild((const uchar*)pattern, (const uchar*)text,
+		  flags & FNM_CASEFOLD ? 1 : 0) == TRUE;
 }
diff --git a/wildmatch.h b/wildmatch.h
index 562faa3..e974f9a 100644
--- a/wildmatch.h
+++ b/wildmatch.h
@@ -1,4 +1,3 @@
 /* wildmatch.h */
 
-int wildmatch(const char *pattern, const char *text);
-int iwildmatch(const char *pattern, const char *text);
+int wildmatch(const char *pattern, const char *text, int flags);
-- 
1.8.0.rc0.29.g1fdd78f

  parent reply	other threads:[~2012-10-09  3:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-09  3:08 [PATCH 0/8] wildmatch take 3 Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` [PATCH 1/8] Import wildmatch from rsync Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` [PATCH 2/8] wildmatch: remove unnecessary functions Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` [PATCH 3/8] Integrate wildmatch to git Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` Nguyễn Thái Ngọc Duy [this message]
2012-10-09 20:47   ` [PATCH 4/8] wildmatch: remove static variable force_lower_case Junio C Hamano
2012-10-10  5:14     ` Nguyen Thai Ngoc Duy
2012-10-10  5:31       ` Junio C Hamano
2012-10-10  5:47         ` Nguyen Thai Ngoc Duy
2012-10-09  3:09 ` [PATCH 5/8] wildmatch: fix case-insensitive matching Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` [PATCH 6/8] wildmatch: adjust "**" behavior Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` [PATCH 7/8] wildmatch: make /**/ match zero or more directories Nguyễn Thái Ngọc Duy
2012-10-09  3:09 ` [PATCH 8/8] Support "**" wildcard in .gitignore and .gitattributes Nguyễn Thái Ngọc Duy
2012-10-09  7:57   ` Michael Haggerty
2012-10-10  5:40     ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1349752147-13314-5-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.