From patchwork Thu Jun 16 20:29:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2001 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DAD1F23E54 for ; Thu, 16 Jun 2011 20:31:51 +0000 (UTC) Received: from mail-vw0-f50.google.com (mail-vw0-f50.google.com [209.85.212.50]) by fiordland.canonical.com (Postfix) with ESMTP id AA37EA18585 for ; Thu, 16 Jun 2011 20:31:51 +0000 (UTC) Received: by mail-vw0-f50.google.com with SMTP id 14so1756184vws.37 for ; Thu, 16 Jun 2011 13:31:51 -0700 (PDT) Received: by 10.52.175.197 with SMTP id cc5mr1863327vdc.287.1308256311493; Thu, 16 Jun 2011 13:31:51 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs211217vdc; Thu, 16 Jun 2011 13:31:51 -0700 (PDT) Received: by 10.216.136.151 with SMTP id w23mr1367865wei.86.1308256306806; Thu, 16 Jun 2011 13:31:46 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by mx.google.com with ESMTP id d43si5074736wek.50.2011.06.16.13.31.46; Thu, 16 Jun 2011 13:31:46 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.130; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d16 with ME id wkXf1g0031hMfSL03kXlJw; Thu, 16 Jun 2011 22:31:46 +0200 From: Daniel Lezcano To: patches@linaro.org Subject: [PATCH 16/28] add 'find' function for the tree Date: Thu, 16 Jun 2011 22:29:45 +0200 Message-Id: <1308256197-29155-16-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> References: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> That will be useful to search for a specific node name. Signed-off-by: Daniel Lezcano --- 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);