linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Changbin Du <changbin.du@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: Jason Baron <jbaron@akamai.com>,
	"linux-kernel@vger.kernel.org list"
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] dynamic_debug: add wildcard support to filter files/functions/modules
Date: Wed, 30 Oct 2013 21:57:44 +0800	[thread overview]
Message-ID: <CABgQ-TjqiALfieAz8+6nt6TVxy93dJRv1UzkGMRMVO1CgfwXNg@mail.gmail.com> (raw)
In-Reply-To: <CABgQ-TisBA4+re7veEyK+F_jfG-mmuXT-R+hdHd1duqsx0qYLQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]

2013/10/30 Changbin Du <changbin.du@gmail.com>:
> 2013/10/30 Joe Perches <joe@perches.com>:
>> On Tue, 2013-10-29 at 21:33 +0800, Du, Changbin wrote:
>>> This patch add wildcard '*'(matches zero or more characters) and '?'
>>> (matches one character) support when qurying debug flags.
>>
>> Hi again.  Some trivial notes and a possible logic error:
>>
>> Maybe nicer with an if/else, I think you're still
>> missing a reset of "star = false;" and I also think
>> it's better to use a break here too.
>>
>>                 if (*s == *p) {
>>                         s++;
>>                         p++;
>>                         star = false;
>>                 } else {
>>                         if (!star)
>>                                 return false;
>>                         string++;
>>                         s = string;
>>                         p = pattern;
>>                 }
>>                 break;
>
> I have run loss of test before sending patch. all case passed. But I
> will double check if need reset star flag. really thanks!

Hi, Joe. I checked this. The "star = false;" can not have here.
Attachment is a test program that I use it to test the algorithm. it will
compare this non-recursion and old recursion if they are equal.

Now I will send the v3 patch, please help to review. Thanks!

[-- Attachment #2: wildcard_alg.c --]
[-- Type: text/x-csrc, Size: 3230 bytes --]

#include <stdio.h>
#include <stdlib.h>

#define bool int
#define false 0
#define true  1

static int match_pattern1(char *pat, char *str)
{
	switch (*pat) {
	case '\0':
		return !*str;
	case '*':
		return  match_pattern1(pat+1, str) ||
		        (*str && match_pattern1(pat, str+1));
	case '?':
		return *str && match_pattern1(pat+1, str+1);
	default:
		return *pat == *str && match_pattern1(pat+1, str+1);
	}
}

static bool match_pattern2(const char *pattern, const char *string)
{
	const char *s;
	const char *p;
	bool star = false;

loop:
	for (s = string, p = pattern; *s; ++s, ++p) {
		switch (*p) {
		case '?':
			break;
		case '*':
			star = true;
			string = s;
			pattern = p;
			if (!*++pattern)
				return 1;
			goto loop;
		default:
			if (*s != *p)
				goto star_check;
			break;
		}
	}
	if (*p == '*')
		++p;
	return (!*p);

star_check:
	if (!star)
		return 0;
	string++;
	goto loop;
}

static bool match_pattern3(const char *pattern, const char *string)
{
	const char *s = string;
	const char *p = pattern;
	bool star = false;

	while (*s) {
		switch (*p) {
		case '?':
			s++;
			p++;
			break;
		case '*':
			star = true;
			string = s;
			if (!*++p)
				return true;
			pattern = p;
			break;
		default:
			if (*s == *p) {
				s++;
				p++;
			} else {
				if (!star)
					return false;
				string++;
				s = string;
				p = pattern;
			}
			break;
		}
	}

	if (*p == '*')
		++p;
	return !*p;
}



/* return 0 if all the result of three function is same, else return 1. */
static int test_match()
{
	char *Str[] = { "ZIP",
	                ".ZIP",
	                "ZIP.",
	                "afdZfdaZIP"
	                "adfsafZfdsadfIfdafdsPfdasdf",
	                "accbddcrrfddhuulggnffphhqggyyyrnnvhgflllmmnnnnkpi.iuuuiyt",
	                "A.bkdfadfasfa.faskfa.sfaf?kl.A.ZIP",
	                "Asdhgerlthwegjsdklgjsdgjsdkgjsdgjsdg.ZIP",
	                "AAgsdjtweoruterjtertweiutwejtwejtwetwoejtwejtrwleAA.ZIP",
	                "Agjsdgjdsjgsdkjgsdjgsjd?gjsd?gjsd?gj?sdgj.A.ZIdgjsdkjglsdjgPPO",
	                "fasdfe323rerteter55rtrewtrwwe"
	              };
	char *Patt[] = { "?ZIP", "*ZIP", "ZIP.", "*ZIP", "*?ZIP", "?*?ZIP", "*?*?ZIP", "*Z*I*P*",
	                 "*?*?*ZIP", "a*?*?*ZIP", "*ZI?", "*ZI?", "*ZI*", "*ZI*",
	                 "a*?*?", "?*?*","ZIP", "ZIP", "AAZIP", "AZIP", "AAAAZIP", "AAZIPPO"
	               };
	int i = 0, j = 0, ret = 0;

	for (i = 0 ; i < sizeof(Patt)/sizeof(Patt[0]); i++) {
		for (j = 0; j < sizeof(Str)/sizeof(Str[0]); j++) {
			char *pat = Patt[i];
			char *str = Str[j];
			bool match1 = match_pattern1(pat, str);
			bool match2 = match_pattern2(pat, str);
			bool match3 = match_pattern3(pat, str);

			printf("\"%s\" =?= \"%s\"\n", pat, str);
			if (match1 == match2 && match2 == match3)
				printf("All three result is same: %d\n", match1);
			else {
				printf("****\n"
				       "****Someone is wrong: match1=%d match2=%d match3=%d\n"
				       "****\n",
				       match1, match2, match3);
				ret = 1;
			}
			printf("\n");
		}
		printf("\n");
	}
	return ret;
}

int main()
{
	return test_match();
}

  reply	other threads:[~2013-10-30 13:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25 13:02 [PATCH] dynamic_debug: add wildcard support to filter files/functions/modules Du, Changbin
2013-07-25 16:47 ` Joe Perches
2013-07-30  3:59   ` Jason Baron
2013-10-28 15:29     ` [PATCH v2] " Du, Changbin
2013-10-28 16:30       ` Joe Perches
2013-10-29  8:04         ` Changbin Du
2013-10-29 13:33           ` [PATCH v3] " Du, Changbin
2013-10-29 16:20             ` Joe Perches
2013-10-30  6:58               ` Changbin Du
2013-10-30 13:57                 ` Changbin Du [this message]
2013-10-30 14:21                   ` [PATCH v4 1/2] " Du, Changbin
2013-10-30 14:21                   ` [PATCH v4 2/2] dynamic-debug-howto.txt: update since new wildcard support Du, Changbin
2013-10-29 20:21             ` [PATCH v3] dynamic_debug: add wildcard support to filter files/functions/modules Marcel Holtmann
2013-10-30  6:24               ` Changbin Du
2013-10-31 22:52       ` [PATCH v2] " Andrew Morton
2013-10-31 23:30         ` Joe Perches
2013-11-07  3:04           ` Changbin Du
2013-11-07  3:11           ` Changbin Du
2013-11-07  6:12             ` Joe Perches
2013-11-15  4:01               ` Changbin Du
2013-11-16  8:24                 ` [PATCH v5 0/3] add wildcard support for dynamic debug Du, Changbin
2013-11-16  8:24                 ` [PATCH v5 1/3] lib/parser.c: add match_wildcard function Du, Changbin
2013-11-16  8:24                 ` [PATCH v5 2/3] dynamic_debug: add wildcard support to filter files/functions/modules Du, Changbin
2013-11-16  8:24                 ` [PATCH v5 3/3] dynamic-debug-howto.txt: update since new wildcard support Du, Changbin

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=CABgQ-TjqiALfieAz8+6nt6TVxy93dJRv1UzkGMRMVO1CgfwXNg@mail.gmail.com \
    --to=changbin.du@gmail.com \
    --cc=jbaron@akamai.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).