1 | /***************************************
2 | $Revision: 1.10 $
3 |
4 | Radix tree (rx). rx_print.c - functions to print a forest/tree/node
5 | (mainly for debugging purposes)
6 |
7 | Status: NOT REVUED, TESTED, INCOMPLETE
8 |
9 | Design and implementation by: Marek Bukowy
10 |
11 | ******************/ /******************
12 | Copyright (c) 1999 RIPE NCC
13 |
14 | All Rights Reserved
15 |
16 | Permission to use, copy, modify, and distribute this software and its
17 | documentation for any purpose and without fee is hereby granted,
18 | provided that the above copyright notice appear in all copies and that
19 | both that copyright notice and this permission notice appear in
20 | supporting documentation, and that the name of the author not be
21 | used in advertising or publicity pertaining to distribution of the
22 | software without specific, written prior permission.
23 |
24 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
26 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
27 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
28 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
29 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 | ***************************************/
31 |
32 | #define RX_IMPL
33 | #include <rxroutines.h>
34 | #include "socket.h"
35 |
36 | er_ret_t
37 | rx_walk_hook_printnode(rx_node_t *node, int level, int nodecounter, void *con)
38 | {
39 | sk_conn_st *condat = (sk_conn_st *) con;
40 | char line[200]="", buf[1024];
41 |
42 | int i;
43 |
44 | /* indent*/
45 | for(i=0;i<level;i++) strcat(line," ");
46 |
47 | sprintf( line+strlen(line) ,"** level %d ** ", level);
48 | /* @ %p; parent %p, child[0]=%p, child[1]=%p\n", */
49 | /* node, node->parent_ptr, node->child_ptr[0], node->child_ptr[1] );*/
50 |
51 | rx_nod_print(node, buf, 1024);
52 |
53 | SK_cd_puts(condat, line);
54 | SK_cd_puts(condat, buf);
55 | SK_cd_puts(condat, "\n");
56 | return RX_OK;
57 | }
58 |
59 | /***************************************************************************/
60 |
61 | er_ret_t
62 | rx_tree_print( sk_conn_st *condat, rx_tree_t *tree )
63 | {
64 | int cnt;
65 | er_ret_t err;
66 | char line[200]="";
67 |
68 | if( tree->top_ptr != NULL ) {
69 | cnt = rx_walk_tree(tree->top_ptr, rx_walk_hook_printnode,
70 | RX_WALK_CNTGLU, /* print also glue nodes*/
71 | 255, 0, 0, condat, &err);
72 | sprintf(line,"Traversed %d nodes\n", cnt);
73 | SK_cd_puts(condat,line);
74 | }
75 | else {
76 | SK_cd_puts(condat,"The tree is empty!\n");
77 | }
78 |
79 | return err;
80 | }
81 |
82 |
83 | /***************************************************************************/
84 |
85 | void
86 | rx_space_printone(void *voptr, void *condat)
87 | {
88 | rx_tree_t *ptr = voptr;
89 | char aout[1024];
90 | char prstr[IP_PREFSTR_MAX];
91 |
92 | *aout=0;
93 |
94 | sprintf(aout+strlen(aout), "%50s:%d\n", "space", ptr->space );
95 | sprintf(aout+strlen(aout), "%50s:%d\n", "family", ptr->family );
96 | sprintf(aout+strlen(aout), "%50s:%d\n", "subtrees", ptr->subtrees);
97 | sprintf(aout+strlen(aout), "%50s:%d\n", "mem_mode", ptr->mem_mode);
98 | sprintf(aout+strlen(aout), "%50s:%d\n", "num_nodes",ptr->num_nodes);
99 | sprintf(aout+strlen(aout), "%50s:%08x\n", "top_ptr", (int) ptr->top_ptr);
100 | sprintf(aout+strlen(aout), "%50s:%d\n", "maxbits", ptr->maxbits);
101 |
102 | if( IP_pref_b2a( &(ptr->prefix), prstr, IP_PREFSTR_MAX) != IP_OK )
103 | die; /* program error.*/
104 |
105 | sprintf(aout+strlen(aout), "%50s:%s\n", "prefix", prstr);
106 | SK_cd_puts( (sk_conn_st *)condat,aout);
107 | }
108 |
109 |
110 |
111 | /***************************************************************************/
112 |
113 | void
114 | rx_nod_print( rx_node_t *node, char *buf, int maxchar )
115 | {
116 | char pref[IP_PREFSTR_MAX];
117 |
118 | if( IP_pref_b2a( &(node->prefix), pref, IP_PREFSTR_MAX) != IP_OK ) {
119 | die;
120 | }
121 |
122 | snprintf(buf, maxchar, "%s%s",
123 | ( node->glue ) ? "++glue++" : "", pref);
124 | }
125 | /***************************************************************************/
126 |
127 | void
128 | rx_stk_print( rx_nodcpy_t stack[], /* stack==array of node_copies*/
129 | int stackdepth )
130 | {
131 | int i;
132 | rx_node_t *node;
133 | char buf[1024];
134 |
135 | ER_dbg_va(FAC_RX, ASP_RX_STKBLD_DET,
136 | "stack dump: %d elements", stackdepth);
137 |
138 | for(i = 0; i < stackdepth; i++) {
139 | node = & stack[i].cpy;
140 |
141 | rx_nod_print(node, buf, 1024);
142 |
143 | ER_dbg_va(FAC_RX, ASP_RX_STKBLD_DET, "position %d: %s", i, buf);
144 | }
145 | }