X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Ftree.c;h=3b6c3603b0f0770ff5fc0d761f9dced6c757c762;hb=5903c6ff59527362e869fedb565c56935ce8dd68;hp=791ac79b87f6bf831e2ba4f993408cdc39405d71;hpb=c988f1f4faa9f679f79beddf3c14676c5dcb8e28;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/tree.c b/src/src/tree.c index 791ac79b8..3b6c3603b 100644 --- a/src/src/tree.c +++ b/src/src/tree.c @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/src/tree.c,v 1.2 2005/01/04 10:00:42 ph10 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2005 */ +/* Copyright (c) University of Cambridge 1995 - 2015 */ /* See the file NOTICE for conditions of use and distribution. */ /* Functions for maintaining binary balanced trees and some associated @@ -330,16 +328,38 @@ Returns: pointer to node, or NULL if not found */ tree_node * -tree_search(tree_node *p, uschar *name) +tree_search(tree_node *p, const uschar *name) { -while (p != NULL) +while (p) { int c = Ustrcmp(name, p->name); if (c == 0) return p; - p = (c < 0)? p->left : p->right; + p = c < 0 ? p->left : p->right; } return NULL; } + +/************************************************* +* Walk tree recursively and execute function * +*************************************************/ + +/* +Arguments: + p root of the tree + f function to execute for each name-value-pair + ctx context data for f +*/ + +void +tree_walk(tree_node *p, void (*f)(uschar*, uschar*, void*), void *ctx) +{ +if (!p) return; +f(p->name, p->data.ptr, ctx); +tree_walk(p->left, f, ctx); +tree_walk(p->right, f, ctx); +} + + /* End of tree.c */