All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Masami Hiramatsu <mhiramat@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, acme@redhat.com,
	hpa@zytor.com, mingo@redhat.com, efault@gmx.de,
	peterz@infradead.org, fweisbec@gmail.com,
	dle-develop@lists.sourceforge.net, tglx@linutronix.de,
	mhiramat@redhat.com, mingo@elte.hu, systemtap@sources.redhat.com
Subject: [tip:perf/core] perf tools: Enhance glob string matching
Date: Wed, 13 Jan 2010 10:35:15 GMT	[thread overview]
Message-ID: <tip-6964cd2c8efe6e048401f1fe3952a06c563c34c1@git.kernel.org> (raw)
In-Reply-To: <20100105224724.19431.56271.stgit@dhcp-100-2-132.bos.redhat.com>

Commit-ID:  6964cd2c8efe6e048401f1fe3952a06c563c34c1
Gitweb:     http://git.kernel.org/tip/6964cd2c8efe6e048401f1fe3952a06c563c34c1
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 5 Jan 2010 17:47:24 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 13 Jan 2010 10:09:14 +0100

perf tools: Enhance glob string matching

Enhance strglobmatch() for supporting character classes([CHARS],
complementation and ranges are also supported) and escaped
special characters (\*, \? etc).

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <20100105224724.19431.56271.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/string.c |   65 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 5352d7d..c397d4f 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -227,16 +227,73 @@ fail:
 	return NULL;
 }
 
-/* Glob expression pattern matching */
+/* Character class matching */
+static bool __match_charclass(const char *pat, char c, const char **npat)
+{
+	bool complement = false, ret = true;
+
+	if (*pat == '!') {
+		complement = true;
+		pat++;
+	}
+	if (*pat++ == c)	/* First character is special */
+		goto end;
+
+	while (*pat && *pat != ']') {	/* Matching */
+		if (*pat == '-' && *(pat + 1) != ']') {	/* Range */
+			if (*(pat - 1) <= c && c <= *(pat + 1))
+				goto end;
+			if (*(pat - 1) > *(pat + 1))
+				goto error;
+			pat += 2;
+		} else if (*pat++ == c)
+			goto end;
+	}
+	if (!*pat)
+		goto error;
+	ret = false;
+
+end:
+	while (*pat && *pat != ']')	/* Searching closing */
+		pat++;
+	if (!*pat)
+		goto error;
+	*npat = pat + 1;
+	return complement ? !ret : ret;
+
+error:
+	return false;
+}
+
+/**
+ * strglobmatch - glob expression pattern matching
+ * @str: the target string to match
+ * @pat: the pattern string to match
+ *
+ * This returns true if the @str matches @pat. @pat can includes wildcards
+ * ('*','?') and character classes ([CHARS], complementation and ranges are
+ * also supported). Also, this supports escape character ('\') to use special
+ * characters as normal character.
+ *
+ * Note: if @pat syntax is broken, this always returns false.
+ */
 bool strglobmatch(const char *str, const char *pat)
 {
 	while (*str && *pat && *pat != '*') {
-		if (*pat == '?') {
+		if (*pat == '?') {	/* Matches any single character */
 			str++;
 			pat++;
-		} else
-			if (*str++ != *pat++)
+			continue;
+		} else if (*pat == '[')	/* Character classes/Ranges */
+			if (__match_charclass(pat + 1, *str, &pat)) {
+				str++;
+				continue;
+			} else
 				return false;
+		else if (*pat == '\\') /* Escaped char match as normal char */
+			pat++;
+		if (*str++ != *pat++)
+			return false;
 	}
 	/* Check wild card */
 	if (*pat == '*') {

  reply	other threads:[~2010-01-13 10:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-05 22:46 [PATCH -tip 0/8] perf-probe updates Masami Hiramatsu
2010-01-05 22:46 ` [PATCH -tip 1/8] tracing/kprobe: Update example output in documentation Masami Hiramatsu
2010-01-06 18:40   ` Steven Rostedt
2010-01-13 10:33   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-01-05 22:46 ` [PATCH -tip 2/8] tracing/kprobe: Drop function argument access syntax Masami Hiramatsu
2010-01-05 22:46   ` Masami Hiramatsu
2010-01-13 10:33   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-01-05 22:46 ` [PATCH -tip 3/8] x86/ptrace: Remove unused regs_get_argument_nth API Masami Hiramatsu
2010-01-05 22:46   ` Masami Hiramatsu
2010-01-13 10:34   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-01-05 22:47 ` [PATCH -tip 4/8] [CLEANUP] perf probe: Remove newline from die() Masami Hiramatsu
2010-01-13 10:34   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-01-05 22:47 ` [PATCH -tip 5/8] perf probe: Show probe list in pager Masami Hiramatsu
2010-01-13 10:34   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-01-05 22:47 ` [PATCH -tip 6/8] perf tools: Support tracepoint glob matching Masami Hiramatsu
2010-01-13 10:34   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-01-05 22:47 ` [PATCH -tip 7/8] perf tools: Enhance glob string matching Masami Hiramatsu
2010-01-13 10:35   ` tip-bot for Masami Hiramatsu [this message]
2010-01-05 22:47 ` [PATCH -tip 8/8] perf probe: Support --line option to show probable source-code lines Masami Hiramatsu
2010-01-06 14:33   ` Masami Hiramatsu
2010-01-06 14:45     ` [PATCH -tip] " Masami Hiramatsu
2010-01-13 10:35       ` [tip:perf/core] " tip-bot for Masami Hiramatsu

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=tip-6964cd2c8efe6e048401f1fe3952a06c563c34c1@git.kernel.org \
    --to=mhiramat@redhat.com \
    --cc=acme@redhat.com \
    --cc=dle-develop@lists.sourceforge.net \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=systemtap@sources.redhat.com \
    --cc=tglx@linutronix.de \
    /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.