From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752578AbbKCMP2 (ORCPT ); Tue, 3 Nov 2015 07:15:28 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:36581 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751288AbbKCMPZ (ORCPT ); Tue, 3 Nov 2015 07:15:25 -0500 Date: Tue, 3 Nov 2015 21:15:14 +0900 From: Namhyung Kim To: Taeung Song Cc: Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org, jolsa@redhat.com, Ingo Molnar Subject: Re: [PATCH v9 4/9] perf config: Add comparing name treating '_' and '-' as being the same thing. Message-ID: <20151103121514.GG5733@danjae.kornet> References: <1446515420-22681-1-git-send-email-treeze.taeung@gmail.com> <1446515420-22681-5-git-send-email-treeze.taeung@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1446515420-22681-5-git-send-email-treeze.taeung@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 03, 2015 at 10:50:15AM +0900, Taeung Song wrote: > The comparing name functionality is that > two config name are compared treating '-' or '_' as > being the same thing. For example, both 'print_percent' > and 'print-percent' in 'call-graph' section > are regarded as the same thing. Hmm.. but this code only does it for 'perf config' command, right? What we want is treating them in all other commands which use perf_config() callbacks. I think it'd be better to convert the character when parsing the config files.. Thanks, Namhyung > > Signed-off-by: Taeung Song > --- > tools/perf/builtin-config.c | 23 ++++++++++++++++++++++- > 1 file changed, 22 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c > index f99c39d..d4e2899 100644 > --- a/tools/perf/builtin-config.c > +++ b/tools/perf/builtin-config.c > @@ -32,6 +32,27 @@ static struct option config_options[] = { > OPT_END() > }; > > +static int compare_name(const char *name1, const char *name2) > +{ > + while (true) { > + /* > + * If two names have '-' or '_', them are treated > + * as being the same thing. > + */ > + if ((*name1 == '-' || *name1 == '_') > + && (*name2 == '-' || *name2 == '_')) { > + name1++, name2++; > + continue; > + } > + > + if (*name1 && (*name1 == *name2)) > + name1++, name2++; > + else > + break; > + } > + return *(const unsigned char *)name1-*(const unsigned char *)name2; > +} > + > static struct config_section *find_section(struct list_head *sections, > const char *section_name) > { > @@ -50,7 +71,7 @@ static struct config_element *find_element(const char *name, > struct config_element *element; > > list_for_each_entry(element, §ion->element_head, list) > - if (!strcmp(element->name, name)) > + if (!compare_name(element->name, name)) > return element; > > return NULL; > -- > 1.9.1 >