From patchwork Thu Jun 16 20:29:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2007 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 4532D23E54 for ; Thu, 16 Jun 2011 20:31:56 +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 15765A18621 for ; Thu, 16 Jun 2011 20:31:55 +0000 (UTC) Received: by mail-vw0-f50.google.com with SMTP id 14so1756035vws.37 for ; Thu, 16 Jun 2011 13:31:55 -0700 (PDT) Received: by 10.52.168.65 with SMTP id zu1mr1893660vdb.207.1308256315443; Thu, 16 Jun 2011 13:31:55 -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 em2cs211224vdc; Thu, 16 Jun 2011 13:31:55 -0700 (PDT) Received: by 10.227.134.72 with SMTP id i8mr1329462wbt.76.1308256309118; Thu, 16 Jun 2011 13:31:49 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by mx.google.com with ESMTP id es17si1358310wbb.55.2011.06.16.13.31.48; Thu, 16 Jun 2011 13:31:49 -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 wkXf1g0031hMfSL03kXoKF; Thu, 16 Jun 2011 22:31:48 +0200 From: Daniel Lezcano To: patches@linaro.org Subject: [PATCH 22/28] add a function to browse at reverse order the tree Date: Thu, 16 Jun 2011 22:29:51 +0200 Message-Id: <1308256197-29155-22-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> Signed-off-by: Daniel Lezcano --- tree.c | 14 ++++++++++++++ tree.h | 2 ++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/tree.c b/tree.c index 0a9c119..516e832 100644 --- a/tree.c +++ b/tree.c @@ -224,6 +224,20 @@ int tree_for_each(struct tree *tree, tree_cb_t cb, void *data) return tree_for_each(tree->next, cb, data); } +int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data) +{ + if (!tree) + return 0; + + if (cb(tree, data)) + return -1; + + if (tree_for_each_reverse(tree->prev, cb, data)) + return -1; + + return tree_for_each_reverse(tree->parent, cb, data); +} + int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data) { if (!tree) diff --git a/tree.h b/tree.h index 176dd23..2af4a5a 100644 --- a/tree.h +++ b/tree.h @@ -46,4 +46,6 @@ 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); +extern int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data); + extern int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data);