lkml.org 
[lkml]   [2015]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v9 4/9] perf config: Add comparing name treating '_' and '-' as being the same thing.
Date
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.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
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, &section->element_head, list)
- if (!strcmp(element->name, name))
+ if (!compare_name(element->name, name))
return element;

return NULL;
--
1.9.1


\
 
 \ /
  Last update: 2015-11-03 03:01    [W:0.078 / U:1.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site