]> git.sesse.net Git - vlc/blob - compat/twalk.c
Use HAS_QT47
[vlc] / compat / 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 #define _SEARCH_PRIVATE
15
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
19
20 #include <assert.h>
21 #include <stdlib.h>
22
23 static void trecurse (const node_t *,
24     void  (*action)(const void *, VISIT, int), int level);
25
26 /* Walk the nodes of a tree */
27 static void
28 trecurse(root, action, level)
29         const node_t *root;     /* Root of the tree to be walked */
30         void (*action) (const void *, VISIT, int);
31         int level;
32 {
33         assert(root != NULL);
34         assert(action != NULL);
35
36         if (root->llink == NULL && root->rlink == NULL)
37                 (*action)(root, leaf, level);
38         else {
39                 (*action)(root, preorder, level);
40                 if (root->llink != NULL)
41                         trecurse(root->llink, action, level + 1);
42                 (*action)(root, postorder, level);
43                 if (root->rlink != NULL)
44                         trecurse(root->rlink, action, level + 1);
45                 (*action)(root, endorder, level);
46         }
47 }
48
49 /* Walk the nodes of a tree */
50 void
51 twalk(vroot, action)
52         const void *vroot;      /* Root of the tree to be walked */
53         void (*action) (const void *, VISIT, int);
54 {
55         if (vroot != NULL && action != NULL)
56                 trecurse(vroot, action, 0);
57 }