From patchwork Fri Feb 10 07:59:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13135452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A50D7C05027 for ; Fri, 10 Feb 2023 07:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231438AbjBJH74 (ORCPT ); Fri, 10 Feb 2023 02:59:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231259AbjBJH7y (ORCPT ); Fri, 10 Feb 2023 02:59:54 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01628367C0 for ; Thu, 9 Feb 2023 23:59:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9ABEE61CCE for ; Fri, 10 Feb 2023 07:59:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA334C4339C; Fri, 10 Feb 2023 07:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676015993; bh=4u+CEUu4+EAp39zR3tPvywvv6LT92LeKzADwrVSgELI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xa3mvHIak7W/cwOkvSDTfL8qvOrNtWhFjV/QPtytwjQAF8Ndp12fzFRkUyroTxVzd FvcldrGxE7RiW2QXO8qpTmBeK5o1GucwruPT2Z6p9Bu/EKxg2BCFFeQYqwaE+tdC7f jK3bz3BbZ8Z09FEBlhjEwDSDmeBHAG59vMYDlZDIsTV5SbG+x2T+uIPyzkPOJKybkJ jWKbA9ZwKNVUxingDcAM/QNo0zfpkbJo4N9pu5Pui21ufU34ZnjuXKoeW4n5FyMG/6 Ph5mp/234gwPV8bNMNMi0c1aRBxyUEU3K21aODYzD6nxaeeCycU7CK19oYE93TBZVS iHs2glW9o2lRA== From: Masahiro Yamada To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , Masahiro Yamada Subject: [PATCH 1/5] git-compat-util: add isblank() and isgraph() Date: Fri, 10 Feb 2023 16:59:35 +0900 Message-Id: <20230210075939.44949-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210075939.44949-1-masahiroy@kernel.org> References: <20230210075939.44949-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org git-compat-util.h implements most of is*() macros. Add isblank() and isgraph(), which are useful to clean up wildmatch.c in a consistent way (in this and later commits). Use them with care because they are not robust against the pointer increment, like isblank(*s++). The same issue already exists for isspace(). Signed-off-by: Masahiro Yamada --- git-compat-util.h | 4 ++++ wildmatch.c | 14 ++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index 4f0028ce60..90b43b2bc9 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1212,10 +1212,12 @@ extern const unsigned char tolower_trans_tbl[256]; /* Sane ctype - no locale, and works with signed chars */ #undef isascii #undef isspace +#undef isblank #undef isdigit #undef isalpha #undef isalnum #undef isprint +#undef isgraph #undef islower #undef isupper #undef tolower @@ -1236,10 +1238,12 @@ extern const unsigned char sane_ctype[256]; #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) #define isascii(x) (((x) & ~0x7f) == 0) #define isspace(x) sane_istest(x,GIT_SPACE) +#define isblank(x) (isspace(x) || (x) == '\t') #define isdigit(x) sane_istest(x,GIT_DIGIT) #define isalpha(x) sane_istest(x,GIT_ALPHA) #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) #define isprint(x) ((x) >= 0x20 && (x) <= 0x7e) +#define isgraph(x) (isprint(x) && !isspace(x)) #define islower(x) sane_iscase(x, 1) #define isupper(x) sane_iscase(x, 0) #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) diff --git a/wildmatch.c b/wildmatch.c index 7e5a7ea1ea..85c4c7f8a7 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -28,18 +28,8 @@ typedef unsigned char uchar; # define ISASCII(c) isascii(c) #endif -#ifdef isblank -# define ISBLANK(c) (ISASCII(c) && isblank(c)) -#else -# define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif - -#ifdef isgraph -# define ISGRAPH(c) (ISASCII(c) && isgraph(c)) -#else -# define ISGRAPH(c) (ISASCII(c) && isprint(c) && !isspace(c)) -#endif - +#define ISBLANK(c) (ISASCII(c) && isblank(c)) +#define ISGRAPH(c) (ISASCII(c) && isgraph(c)) #define ISPRINT(c) (ISASCII(c) && isprint(c)) #define ISDIGIT(c) (ISASCII(c) && isdigit(c)) #define ISALNUM(c) (ISASCII(c) && isalnum(c)) From patchwork Fri Feb 10 07:59:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13135453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0D9CC636D3 for ; Fri, 10 Feb 2023 07:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbjBJH76 (ORCPT ); Fri, 10 Feb 2023 02:59:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbjBJH74 (ORCPT ); Fri, 10 Feb 2023 02:59:56 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEED36690 for ; Thu, 9 Feb 2023 23:59:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 65E5A61CC5 for ; Fri, 10 Feb 2023 07:59:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C14A8C433D2; Fri, 10 Feb 2023 07:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676015994; bh=QBeh0AjD35U+fbGt2LkueHP4CzO0EUrItIQSSHO5/7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LEU18huJdXQ6iXQG+VPFo8hjA9XdsYR+TS4UUgGcpLK/XA6Igx6Emu8cw6m6WmNm6 irjYj7jHLUQw7sM3YG0JCLYORVPv1e+azZWzW6RQcHhfH9mcAWIoFexgFKmMsZk7HE DSuor7G3FnDtEHqdyQ/K9qmVCPM06YkpFxpiB+ss50SsYB2N7uOOxRLOPWTZkwgd0k Ss0eJUDmqT3TeNloBifBHvbBkTx+sTTzbD195QzN1ATcYDi4cRmJvK8hzVVyMkqE0G YaPcg8CtXFW2vFlfp3VBDfyLOgF+L5R4a9tyW69sMOc4KpvVXSVMtAAvS2jk1N4nGI WLFsxyY0qjTVA== From: Masahiro Yamada To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , Masahiro Yamada Subject: [PATCH 2/5] wildmatch: remove IS*() macros Date: Fri, 10 Feb 2023 16:59:36 +0900 Message-Id: <20230210075939.44949-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210075939.44949-1-masahiroy@kernel.org> References: <20230210075939.44949-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This file was imported from rsync, which has some compatibility layer because it relies on in C standard library. In contrast, GIT has its own implementations in git-compat-util.h. [1] isprint, isgraph They check the given char range in an obvious way [2] isspace, isblank, isdigit, isalpha, isalnum, islower, isupper, iscntr, ispunct They look up sane_ctype[], which fills the range 0x80-0xff with 0. [3] isxdigit It looks up hexval_table[], which fills the range 0x80-0xff with -1. For all of these, ISACII() is a redundant check. Remove IS*() macros, and directly use is*() in dowild(). Signed-off-by: Masahiro Yamada --- wildmatch.c | 55 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/wildmatch.c b/wildmatch.c index 85c4c7f8a7..a510b3fd23 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -22,25 +22,6 @@ typedef unsigned char uchar; && *(class) == *(litmatch) \ && strncmp((char*)class, litmatch, len) == 0) -#if defined STDC_HEADERS || !defined isascii -# define ISASCII(c) 1 -#else -# define ISASCII(c) isascii(c) -#endif - -#define ISBLANK(c) (ISASCII(c) && isblank(c)) -#define ISGRAPH(c) (ISASCII(c) && isgraph(c)) -#define ISPRINT(c) (ISASCII(c) && isprint(c)) -#define ISDIGIT(c) (ISASCII(c) && isdigit(c)) -#define ISALNUM(c) (ISASCII(c) && isalnum(c)) -#define ISALPHA(c) (ISASCII(c) && isalpha(c)) -#define ISCNTRL(c) (ISASCII(c) && iscntrl(c)) -#define ISLOWER(c) (ISASCII(c) && islower(c)) -#define ISPUNCT(c) (ISASCII(c) && ispunct(c)) -#define ISSPACE(c) (ISASCII(c) && isspace(c)) -#define ISUPPER(c) (ISASCII(c) && isupper(c)) -#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c)) - /* Match pattern "p" against "text" */ static int dowild(const uchar *p, const uchar *text, unsigned int flags) { @@ -52,9 +33,9 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) uchar t_ch, prev_ch; if ((t_ch = *text) == '\0' && p_ch != '*') return WM_ABORT_ALL; - if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) + if ((flags & WM_CASEFOLD) && isupper(t_ch)) t_ch = tolower(t_ch); - if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) + if ((flags & WM_CASEFOLD) && isupper(p_ch)) p_ch = tolower(p_ch); switch (p_ch) { case '\\': @@ -133,11 +114,11 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) */ if (!is_glob_special(*p)) { p_ch = *p; - if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) + if ((flags & WM_CASEFOLD) && isupper(p_ch)) p_ch = tolower(p_ch); while ((t_ch = *text) != '\0' && (match_slash || t_ch != '/')) { - if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) + if ((flags & WM_CASEFOLD) && isupper(t_ch)) t_ch = tolower(t_ch); if (t_ch == p_ch) break; @@ -186,7 +167,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) } if (t_ch <= p_ch && t_ch >= prev_ch) matched = 1; - else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) { + else if ((flags & WM_CASEFOLD) && islower(t_ch)) { uchar t_ch_upper = toupper(t_ch); if (t_ch_upper <= p_ch && t_ch_upper >= prev_ch) matched = 1; @@ -208,42 +189,42 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) continue; } if (CC_EQ(s,i, "alnum")) { - if (ISALNUM(t_ch)) + if (isalnum(t_ch)) matched = 1; } else if (CC_EQ(s,i, "alpha")) { - if (ISALPHA(t_ch)) + if (isalpha(t_ch)) matched = 1; } else if (CC_EQ(s,i, "blank")) { - if (ISBLANK(t_ch)) + if (isblank(t_ch)) matched = 1; } else if (CC_EQ(s,i, "cntrl")) { - if (ISCNTRL(t_ch)) + if (iscntrl(t_ch)) matched = 1; } else if (CC_EQ(s,i, "digit")) { - if (ISDIGIT(t_ch)) + if (isdigit(t_ch)) matched = 1; } else if (CC_EQ(s,i, "graph")) { - if (ISGRAPH(t_ch)) + if (isgraph(t_ch)) matched = 1; } else if (CC_EQ(s,i, "lower")) { - if (ISLOWER(t_ch)) + if (islower(t_ch)) matched = 1; } else if (CC_EQ(s,i, "print")) { - if (ISPRINT(t_ch)) + if (isprint(t_ch)) matched = 1; } else if (CC_EQ(s,i, "punct")) { - if (ISPUNCT(t_ch)) + if (ispunct(t_ch)) matched = 1; } else if (CC_EQ(s,i, "space")) { - if (ISSPACE(t_ch)) + if (isspace(t_ch)) matched = 1; } else if (CC_EQ(s,i, "upper")) { - if (ISUPPER(t_ch)) + if (isupper(t_ch)) matched = 1; - else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) + else if ((flags & WM_CASEFOLD) && islower(t_ch)) matched = 1; } else if (CC_EQ(s,i, "xdigit")) { - if (ISXDIGIT(t_ch)) + if (isxdigit(t_ch)) matched = 1; } else /* malformed [:class:] string */ return WM_ABORT_ALL; From patchwork Fri Feb 10 07:59:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13135454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CFB4C636CD for ; Fri, 10 Feb 2023 08:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbjBJIAE (ORCPT ); Fri, 10 Feb 2023 03:00:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbjBJH76 (ORCPT ); Fri, 10 Feb 2023 02:59:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A2407AE32 for ; Thu, 9 Feb 2023 23:59:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CA93B61CCC for ; Fri, 10 Feb 2023 07:59:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7683EC4339C; Fri, 10 Feb 2023 07:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676015997; bh=JApj1QOA8VvnQjgKoJ8YKpkF4MuZES9jA41ffX5gdmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PE/uYyG9+pPRbODRf5hVw91jeit0fn2Xhi9DsZVYV9zg7oY059iEUClR7xSWLRM+N wION/6+G7QcM2IDzDnTxsr7lJwVmgRfCog6uxXZHKWuWgEm8noIYuRxX32NvyxcSCE bj0UwLnkwoHW85+uTKwi3Bi0zchV5ZHgStU2uLt6eqwmLlTCGuheAI0fxA/RiOfk3z 0OtmIDFR3d1Vk/peKKyaNrMqA1eZm1R1tSBuyWW7Du08uzA1EeO9qNwPtYNdSlIrdo Hk9axnTub1INpTZAZEsMkMIbxnaB4hbngDW6jHDSMY+Se01iMHVuR34lwy12SEh9qJ 8g+MHUamZsNuA== From: Masahiro Yamada To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , Masahiro Yamada Subject: [PATCH 3/5] wildmatch: remove NEGATE_CLASS and NEGATE_CLASS2 macros Date: Fri, 10 Feb 2023 16:59:37 +0900 Message-Id: <20230210075939.44949-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210075939.44949-1-masahiroy@kernel.org> References: <20230210075939.44949-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The other glob patterns are hard-coded in dowild(). Do likewise. Signed-off-by: Masahiro Yamada --- wildmatch.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/wildmatch.c b/wildmatch.c index a510b3fd23..93800b8eac 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -14,10 +14,6 @@ typedef unsigned char uchar; -/* What character marks an inverted character class? */ -#define NEGATE_CLASS '!' -#define NEGATE_CLASS2 '^' - #define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \ && *(class) == *(litmatch) \ && strncmp((char*)class, litmatch, len) == 0) @@ -137,12 +133,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) return WM_ABORT_ALL; case '[': p_ch = *++p; -#ifdef NEGATE_CLASS2 - if (p_ch == NEGATE_CLASS2) - p_ch = NEGATE_CLASS; -#endif /* Assign literal 1/0 because of "matched" comparison. */ - negated = p_ch == NEGATE_CLASS ? 1 : 0; + negated = p_ch == '!' || p_ch == '^' ? 1 : 0; if (negated) { /* Inverted character class. */ p_ch = *++p; From patchwork Fri Feb 10 07:59:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13135456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C7E9C05027 for ; Fri, 10 Feb 2023 08:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbjBJIAM (ORCPT ); Fri, 10 Feb 2023 03:00:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231518AbjBJIAE (ORCPT ); Fri, 10 Feb 2023 03:00:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCD4D7B3A2 for ; Fri, 10 Feb 2023 00:00:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 36B17B82363 for ; Fri, 10 Feb 2023 08:00:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9A33C433D2; Fri, 10 Feb 2023 07:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676015999; bh=rE6wm1oneRdufQEVVXdEtozNifnldSeApKYLiaYlgy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=khrIoVRVWe3AH3RSlmecvGJyP9mqrQKyBOJ7S6e5ctWHAzcdDxM5h9BufBzJ3UiQL mB1SN8R0ySJOfw+tSbPMyXNfN4CyWutsXEqDyFy8rpiHIvxFAD2qzMg3rD0kSbQ1LW XH+gTGfGDSmUJ5VpGUXIcpQ8lGzETXqtQrBTTbBJ2WuyTL8R+7LCT3EOJMzV0jdh4A 21VenrqxIrg3K1J5zxTDGpgd9Ruu7sqB8e7iUY5kh5KwU/VGqzcuXBy42W0Dpi/faS jJt6N2oj9aAdaS5cB3lhumgM4FC/47IAkIjFiBfU3OrFXYRvSFAXoKTYNxgPLSfi7c XItn375zV/s5Q== From: Masahiro Yamada To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , Masahiro Yamada Subject: [PATCH 4/5] wildmatch: use char instead of uchar Date: Fri, 10 Feb 2023 16:59:38 +0900 Message-Id: <20230210075939.44949-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210075939.44949-1-masahiroy@kernel.org> References: <20230210075939.44949-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org dowild() casts (char *) and (uchar *) back-and-forth, which is ugly. This file was imported from rsync, which started to use (unsigned char) since the following commit: | commit e11c42511903adc6d27cf1671cc76fa711ea37e5 | Author: Wayne Davison | Date: Sun Jul 6 04:33:54 2003 +0000 | | - Added [:class:] handling to the character-class code. | - Use explicit unsigned characters for proper set checks. | - Made the character-class code honor backslash escapes. | - Accept '^' as a class-negation character in addition to '!'. Perhaps, it was needed because rsync relies on is*() from . GIT has its own implementations, so the behavior is clear. In fact, commit 4546738b58a0 ("Unlocalized isspace and friends") says one of the motivations is "we want the right signed behaviour". sane_istest() casts the given character to (unsigned char) anyway before sane_ctype[] table lookup, so dowild() can use 'char'. Signed-off-by: Masahiro Yamada --- wildmatch.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/wildmatch.c b/wildmatch.c index 93800b8eac..7dffd783cb 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -12,21 +12,19 @@ #include "cache.h" #include "wildmatch.h" -typedef unsigned char uchar; - #define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \ && *(class) == *(litmatch) \ - && strncmp((char*)class, litmatch, len) == 0) + && strncmp(class, litmatch, len) == 0) /* Match pattern "p" against "text" */ -static int dowild(const uchar *p, const uchar *text, unsigned int flags) +static int dowild(const char *p, const char *text, unsigned int flags) { - uchar p_ch; - const uchar *pattern = p; + char p_ch; + const char *pattern = p; for ( ; (p_ch = *p) != '\0'; text++, p++) { int matched, match_slash, negated; - uchar t_ch, prev_ch; + char t_ch, prev_ch; if ((t_ch = *text) == '\0' && p_ch != '*') return WM_ABORT_ALL; if ((flags & WM_CASEFOLD) && isupper(t_ch)) @@ -50,7 +48,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) continue; case '*': if (*++p == '*') { - const uchar *prev_p = p - 2; + const char *prev_p = p - 2; while (*++p == '*') {} if (!(flags & WM_PATHNAME)) /* without WM_PATHNAME, '*' == '**' */ @@ -90,10 +88,10 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) * with WM_PATHNAME matches the next * directory */ - const char *slash = strchr((char*)text, '/'); + const char *slash = strchr(text, '/'); if (!slash) return WM_NOMATCH; - text = (const uchar*)slash; + text = slash; /* the slash is consumed by the top-level for loop */ break; } @@ -160,13 +158,13 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) if (t_ch <= p_ch && t_ch >= prev_ch) matched = 1; else if ((flags & WM_CASEFOLD) && islower(t_ch)) { - uchar t_ch_upper = toupper(t_ch); + char t_ch_upper = toupper(t_ch); if (t_ch_upper <= p_ch && t_ch_upper >= prev_ch) matched = 1; } p_ch = 0; /* This makes "prev_ch" get set to 0. */ } else if (p_ch == '[' && p[1] == ':') { - const uchar *s; + const char *s; int i; for (s = p += 2; (p_ch = *p) && p_ch != ']'; p++) {} /*SHARED ITERATOR*/ if (!p_ch) @@ -237,5 +235,5 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) /* Match the "pattern" against the "text" string. */ int wildmatch(const char *pattern, const char *text, unsigned int flags) { - return dowild((const uchar*)pattern, (const uchar*)text, flags); + return dowild(pattern, text, flags); } From patchwork Fri Feb 10 07:59:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13135455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC8AAC636CD for ; Fri, 10 Feb 2023 08:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbjBJIAL (ORCPT ); Fri, 10 Feb 2023 03:00:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbjBJIAE (ORCPT ); Fri, 10 Feb 2023 03:00:04 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7276BABD for ; Fri, 10 Feb 2023 00:00:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9B49461C30 for ; Fri, 10 Feb 2023 08:00:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E15FC4339C; Fri, 10 Feb 2023 07:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676016001; bh=Dbk/T8s5W42qTw0xjSTCY3wEmHNs22jwn8fu9tbEq80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RpsuCLn8otVL/6G3wo8lGPUW1NrL6zQ0WeDnDZO2UNV9gmKRFP9cUNqbNjOpHC3bE N94hOnjse3EX22o/3kgGS5Jv/vGnn2sfcsrxHvKIdDMS41MbCZxXAa12dP/91DvBwf q+Ddq0bjAuo6UsBlsF6L6MKbHTMINwGPnq6qn6XZTiai6UmaO0AGsohkpBK6OjtMON syDbrS8L6xxUN/KwY+P3I/+Gc8nChm/n2eLEWYJDhikkjKX6i42GtL2l9yKwKl3Kye 6WVd191dpveIhJK3i1AO4MVcC8QRI5q+9dpYOGYPgg0jXyT8aYa5dSgv6lZdWXKVKM VqnqvoQukLXwQ== From: Masahiro Yamada To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , Masahiro Yamada Subject: [PATCH 5/5] wildmatch: more cleanups after killing uchar Date: Fri, 10 Feb 2023 16:59:39 +0900 Message-Id: <20230210075939.44949-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210075939.44949-1-masahiroy@kernel.org> References: <20230210075939.44949-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the local function dowild(), which is now equivalent to wildmatch(). Remove the local variable, slash. Signed-off-by: Masahiro Yamada --- wildmatch.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/wildmatch.c b/wildmatch.c index 7dffd783cb..24577e9b8e 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -17,7 +17,7 @@ && strncmp(class, litmatch, len) == 0) /* Match pattern "p" against "text" */ -static int dowild(const char *p, const char *text, unsigned int flags) +int wildmatch(const char *p, const char *text, unsigned int flags) { char p_ch; const char *pattern = p; @@ -66,7 +66,7 @@ static int dowild(const char *p, const char *text, unsigned int flags) * both foo/bar and foo/a/bar. */ if (p[0] == '/' && - dowild(p + 1, text, flags) == WM_MATCH) + wildmatch(p + 1, text, flags) == WM_MATCH) return WM_MATCH; match_slash = 1; } else /* WM_PATHNAME is set */ @@ -88,10 +88,9 @@ static int dowild(const char *p, const char *text, unsigned int flags) * with WM_PATHNAME matches the next * directory */ - const char *slash = strchr(text, '/'); - if (!slash) + text = strchr(text, '/'); + if (!text) return WM_NOMATCH; - text = slash; /* the slash is consumed by the top-level for loop */ break; } @@ -121,7 +120,7 @@ static int dowild(const char *p, const char *text, unsigned int flags) if (t_ch != p_ch) return WM_NOMATCH; } - if ((matched = dowild(p, text, flags)) != WM_NOMATCH) { + if ((matched = wildmatch(p, text, flags)) != WM_NOMATCH) { if (!match_slash || matched != WM_ABORT_TO_STARSTAR) return matched; } else if (!match_slash && t_ch == '/') @@ -231,9 +230,3 @@ static int dowild(const char *p, const char *text, unsigned int flags) return *text ? WM_NOMATCH : WM_MATCH; } - -/* Match the "pattern" against the "text" string. */ -int wildmatch(const char *pattern, const char *text, unsigned int flags) -{ - return dowild(pattern, text, flags); -}