That will be useful to search for a specific node name.

Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org>
---
 tree.c |   17 +++++++++++++++++
 tree.h |    2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/tree.c b/tree.c
index e681f4f..7466e31 100644
--- a/tree.c
+++ b/tree.c
@@ -223,3 +223,20 @@ int tree_for_each(struct tree *tree, tree_cb_t cb, void 
*data)
 
        return tree_for_each(tree->next, cb, data);
 }
+
+struct tree *tree_find(struct tree *tree, const char *name)
+{
+       struct tree *t;
+
+       if (!tree)
+               return NULL;
+
+       if (!strcmp(tree->name, name))
+               return tree;
+
+       t = tree_find(tree->child, name);
+       if (t)
+               return t;
+
+       return tree_find(tree->next, name);
+}
diff --git a/tree.h b/tree.h
index 57c70f8..7be3fc4 100644
--- a/tree.h
+++ b/tree.h
@@ -42,4 +42,6 @@ typedef int (*tree_filter_t)(const char *name);
 
 extern struct tree *tree_load(const char *path, tree_filter_t filter);
 
+extern struct tree *tree_find(struct tree *tree, const char *name);
+
 extern int tree_for_each(struct tree *tree, tree_cb_t cb, void *data);
-- 
1.7.1


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to