OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [search/] [twalk.c] - Blame information for rev 207

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*      $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos 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 <sys/cdefs.h>
15
#if 0
16
#if defined(LIBC_SCCS) && !defined(lint)
17
__RCSID("$NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $");
18
#endif /* LIBC_SCCS and not lint */
19
#endif
20
 
21
#include <assert.h>
22
#define _SEARCH_PRIVATE
23
#include <search.h>
24
#include <stdlib.h>
25
 
26
static void trecurse(const node_t *,
27
    void (*action)(const void *, VISIT, int), int level);
28
 
29
/* Walk the nodes of a tree */
30
static void
31
trecurse(root, action, level)
32
        const node_t *root;     /* Root of the tree to be walked */
33
        void (*action)(const void *, VISIT, int);
34
        int level;
35
{
36
 
37
        if (root->llink == NULL && root->rlink == NULL)
38
                (*action)(root, leaf, level);
39
        else {
40
                (*action)(root, preorder, level);
41
                if (root->llink != NULL)
42
                        trecurse(root->llink, action, level + 1);
43
                (*action)(root, postorder, level);
44
                if (root->rlink != NULL)
45
                        trecurse(root->rlink, action, level + 1);
46
                (*action)(root, endorder, level);
47
        }
48
}
49
 
50
/* Walk the nodes of a tree */
51
void
52
_DEFUN(twalk, (vroot, action),
53
        const void *vroot _AND  /* Root of the tree to be walked */
54
        void (*action)(const void *, VISIT, int))
55
{
56
        if (vroot != NULL && action != NULL)
57
                trecurse(vroot, action, 0);
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.