OSDN Git Service

More rationalization of CRT_INLINE function implementations.
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / twalk.c
1 /*      $NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $  */
2
3 /*
4  * Tree search generalized from Knuth (6.2.2) Algorithm T just like
5  * the AT&T man page says.
6  *
7  * The node_t structure is for internal use only, lint doesn't grok it.
8  *
9  * Written by reading the System V Interface Definition, not the code.
10  *
11  * Totally public domain.
12  */
13
14 #include <assert.h>
15 #define _SEARCH_PRIVATE
16 #include <search.h>
17 #include <stdlib.h>
18
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)
27 {
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);
38         }
39 }
40
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))
45 {
46         if (vroot != NULL && action != NULL)
47                 trecurse(vroot, action, 0);
48 }