Use regex.[ch] from msysGit's /git
[cvsps/4msysgit.git] / tsearch / twalk.c
blob2bcc2b2887b65d07be949ac882e8b56d8b18ee2b
1 /* $NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */
3 /*
4 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
5 * the AT&T man page says.
7 * The node_t structure is for internal use only, lint doesn't grok it.
9 * Written by reading the System V Interface Definition, not the code.
11 * Totally public domain.
14 #include <assert.h>
15 #define _SEARCH_PRIVATE
16 #include <tsearch/search.h>
17 #include <stdlib.h>
19 static void trecurse (const node_t *, void (*action)(const void *, VISIT, int),
20 int level) __MINGW_ATTRIB_NONNULL (1)
21 __MINGW_ATTRIB_NONNULL (2);
22 /* Walk the nodes of a tree */
23 static void
24 trecurse( const node_t *root, /* Root of the tree to be walked */
25 void (*action)(const void *, VISIT, int),
26 int level)
28 if (root->llink == NULL && root->rlink == NULL)
29 (*action)(root, leaf, level);
30 else {
31 (*action)(root, preorder, level);
32 if (root->llink != NULL)
33 trecurse(root->llink, action, level + 1);
34 (*action)(root, postorder, level);
35 if (root->rlink != NULL)
36 trecurse(root->rlink, action, level + 1);
37 (*action)(root, endorder, level);
41 /* Walk the nodes of a tree */
42 void
43 twalk( const void *vroot, /* Root of the tree to be walked */
44 void (*action) (const void *, VISIT, int))
46 if (vroot != NULL && action != NULL)
47 trecurse(vroot, action, 0);