From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 98A8BA0352; Wed, 6 May 2020 03:34:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EDD611D62A; Wed, 6 May 2020 03:34:38 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id A86731D629 for ; Wed, 6 May 2020 03:34:36 +0200 (CEST) IronPort-SDR: xci6YrXHvaBfKykVq6l7j0SXcrX9okrgr2eSqjuAB6uLKlAuW7QAIZxiYwtXiDODBNtocsKJeV FWcSwNljSszg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2020 18:34:35 -0700 IronPort-SDR: pFYvrl3mUl5Q6Qml/xykYkab8a8zVUCtRH28XnGUT5Bz5EhtQ1TBWnDGRPp9opYUHA94SyUo0T DVyNPo63wY5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,357,1583222400"; d="scan'208";a="369640660" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.75]) by fmsmga001.fm.intel.com with ESMTP; 05 May 2020 18:34:34 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: ranjit.menon@intel.com, dmitry.kozliuk@gmail.com, Narcisa.Vasile@microsoft.com, tbashar@mellanox.com, Harini.Ramakrishnan@microsoft.com, pallavi.kadam@intel.com Date: Tue, 5 May 2020 18:30:31 -0700 Message-Id: <20200506013032.7668-2-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20200506013032.7668-1-pallavi.kadam@intel.com> References: <20200429232427.7112-1-pallavi.kadam@intel.com> <20200506013032.7668-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH v2 1/2] eal: add fnmatch implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fnmatch implementation is required on Windows to support log level arguments specified with a globbing pattern. The source file is with BSD-3-Clause license. https://github.com/lattera/freebsd/blob/master/usr.bin/csup/fnmatch.c Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Tasnim Bashar Tested-by: Dmitry Kozlyuk --- lib/librte_eal/windows/fnmatch.c | 172 +++++++++++++++++++++++ lib/librte_eal/windows/include/fnmatch.h | 16 +-- lib/librte_eal/windows/meson.build | 1 + 3 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 lib/librte_eal/windows/fnmatch.c diff --git a/lib/librte_eal/windows/fnmatch.c b/lib/librte_eal/windows/fnmatch.c new file mode 100644 index 000000000..f622bf54c --- /dev/null +++ b/lib/librte_eal/windows/fnmatch.c @@ -0,0 +1,172 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; +#endif /* LIBC_SCCS and not lint */ + +/* + * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. + * Compares a filename or pathname to a pattern. + */ + +#include +#include +#include + +#include "fnmatch.h" + +#define EOS '\0' + +static const char *rangematch(const char *, char, int); + +int +fnmatch(const char *pattern, const char *string, int flags) +{ + const char *stringstart; + char c, test; + + for (stringstart = string;;) + switch (c = *pattern++) { + case EOS: + if ((flags & FNM_LEADING_DIR) && *string == '/') + return (0); + return (*string == EOS ? 0 : FNM_NOMATCH); + case '?': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + ++string; + break; + case '*': + c = *pattern; + /* Collapse multiple stars. */ + while (c == '*') + c = *++pattern; + + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + /* Optimize for pattern with * at end or before /. */ + if (c == EOS) + if (flags & FNM_PATHNAME) + return ((flags & FNM_LEADING_DIR) || + strchr(string, '/') == NULL ? + 0 : FNM_NOMATCH); + else + return (0); + else if (c == '/' && flags & FNM_PATHNAME) { + string = strchr(string, '/'); + if (string == NULL) + return (FNM_NOMATCH); + break; + } + + /* General case, use recursion. */ + while ((test = *string) != EOS) { + if (!fnmatch(pattern, string, + flags & ~FNM_PERIOD)) + return (0); + if (test == '/' && flags & FNM_PATHNAME) + break; + ++string; + } + return (FNM_NOMATCH); + case '[': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && flags & FNM_PATHNAME) + return (FNM_NOMATCH); + pattern = rangematch(pattern, *string, flags); + if (pattern == NULL) + return (FNM_NOMATCH); + ++string; + break; + case '\\': + if (!(flags & FNM_NOESCAPE)) { + c = *pattern++; + if (c == EOS) { + c = '\\'; + --pattern; + } + } + /* FALLTHROUGH */ + default: + if (c == *string) + ; + else if ((flags & FNM_CASEFOLD) && + (tolower((unsigned char)c) == + tolower((unsigned char)*string))) + ; + else if ((flags & FNM_PREFIX_DIRS) && *string == EOS && + ((c == '/' && string != stringstart) || + (string == stringstart+1 && *stringstart == '/'))) + return (0); + else + return (FNM_NOMATCH); + string++; + break; + } + /* NOTREACHED */ +} + +static const char * +rangematch(const char *pattern, char test, int flags) +{ + int negate, ok; + char c, c2; + + /* + * A bracket expression starting with an unquoted circumflex + * character produces unspecified results (IEEE 1003.2-1992, + * 3.13.2). This implementation treats it like '!', for + * consistency with the regular expression syntax. + * J.T. Conklin (conklin@ngai.kaleida.com) + */ + negate = (*pattern == '!' || *pattern == '^'); + if (negate) + ++pattern; + + if (flags & FNM_CASEFOLD) + test = tolower((unsigned char)test); + + for (ok = 0; (c = *pattern++) != ']';) { + if (c == '\\' && !(flags & FNM_NOESCAPE)) + c = *pattern++; + if (c == EOS) + return (NULL); + + if (flags & FNM_CASEFOLD) + c = tolower((unsigned char)c); + + c2 = *(pattern + 1); + if (*pattern == '-' && c2 != EOS && c2 != ']') { + pattern += 2; + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + c2 = *pattern++; + if (c2 == EOS) + return (NULL); + + if (flags & FNM_CASEFOLD) + c2 = tolower((unsigned char)c2); + + if ((unsigned char)c <= (unsigned char)test && + (unsigned char)test <= (unsigned char)c2) + ok = 1; + } else if (c == test) + ok = 1; + } + return (ok == negate ? NULL : pattern); +} diff --git a/lib/librte_eal/windows/include/fnmatch.h b/lib/librte_eal/windows/include/fnmatch.h index d0159f07a..142753c35 100644 --- a/lib/librte_eal/windows/include/fnmatch.h +++ b/lib/librte_eal/windows/include/fnmatch.h @@ -18,6 +18,13 @@ extern "C" { #define FNM_NOMATCH 1 +#define FNM_NOESCAPE 0x01 +#define FNM_PATHNAME 0x02 +#define FNM_PERIOD 0x04 +#define FNM_LEADING_DIR 0x08 +#define FNM_CASEFOLD 0x10 +#define FNM_PREFIX_DIRS 0x20 + /** * This function is used for searhing a given string source * with the given regular expression pattern. @@ -34,14 +41,7 @@ extern "C" { * @return * if the pattern is found then return 0 or else FNM_NOMATCH */ -static inline int fnmatch(__rte_unused const char *pattern, - __rte_unused const char *string, - __rte_unused int flags) -{ - /* TODO */ - /* This is a stub, not the expected result */ - return FNM_NOMATCH; -} +int fnmatch(const char *pattern, const char *string, int flags); #ifdef __cplusplus } diff --git a/lib/librte_eal/windows/meson.build b/lib/librte_eal/windows/meson.build index 09dd4ab2f..8829407c4 100644 --- a/lib/librte_eal/windows/meson.build +++ b/lib/librte_eal/windows/meson.build @@ -8,5 +8,6 @@ sources += files( 'eal_debug.c', 'eal_lcore.c', 'eal_thread.c', + 'fnmatch.c', 'getopt.c', ) -- 2.18.0.windows.1