modules/rx/rx_print.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. RX_text_srch_mode
  2. rx_walk_hook_printnode
  3. rx_tree_print
  4. rx_space_printone
  5. rx_nod_print
  6. rx_stk_print

   1 /***************************************
   2   $Revision: 1.13 $
   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 #define RX_IMPL_PRINT
  34 #include <rxroutines.h>
  35 #include "sk.h"
  36 
  37 const char *
  38 RX_text_srch_mode(rx_srch_mt mode) 
     /* [<][>][^][v][top][bottom][index][help] */
  39 {
  40   return rx_srch_mode_text[mode];
  41 }
  42 
  43 er_ret_t
  44 rx_walk_hook_printnode(rx_node_t *node, int level, int nodecounter, void *con)
     /* [<][>][^][v][top][bottom][index][help] */
  45 {
  46   sk_conn_st *condat = (sk_conn_st *) con;
  47   char line[200]="", buf[1024];
  48 
  49   int i;
  50 
  51   /* indent*/
  52   for(i=0;i<level;i++) strcat(line,"  ");
  53 
  54   sprintf( line+strlen(line) ,"** level %d ** ", level);
  55   /* @ %p; parent %p, child[0]=%p, child[1]=%p\n", */
  56   /*  node, node->parent_ptr, node->child_ptr[0], node->child_ptr[1] );*/
  57 
  58   rx_nod_print(node, buf, 1024);
  59   
  60   SK_cd_puts(condat, line);
  61   SK_cd_puts(condat, buf);
  62   SK_cd_puts(condat, "\n");
  63   return RX_OK;
  64 }
  65 
  66 /***************************************************************************/
  67 
  68 er_ret_t
  69 rx_tree_print( sk_conn_st *condat, rx_tree_t *tree ) 
     /* [<][>][^][v][top][bottom][index][help] */
  70 {
  71 int cnt;
  72 er_ret_t err;
  73 char line[200]="";
  74 
  75  if( tree->top_ptr != NULL ) {
  76    cnt = rx_walk_tree(tree->top_ptr, rx_walk_hook_printnode, 
  77                       RX_WALK_CNTGLU,  /* print also glue nodes*/
  78                       255, 0, 0, condat, &err);
  79    sprintf(line,"Traversed %d nodes\n", cnt);
  80    SK_cd_puts(condat,line);
  81  }
  82  else {
  83    SK_cd_puts(condat,"The tree is empty!\n");
  84  }
  85 
  86  return err;
  87 }
  88 
  89 
  90 /***************************************************************************/
  91 
  92 void
  93 rx_space_printone(void *voptr, void *condat)
     /* [<][>][^][v][top][bottom][index][help] */
  94 {
  95   rx_tree_t *ptr = voptr;
  96   char aout[1024];
  97   char prstr[IP_PREFSTR_MAX];
  98   
  99   *aout=0;
 100 
 101   sprintf(aout+strlen(aout), "%50s:%d\n", "space",    ptr->space );
 102   sprintf(aout+strlen(aout), "%50s:%d\n", "family",   ptr->family );
 103   sprintf(aout+strlen(aout), "%50s:%d\n", "subtrees", ptr->subtrees);
 104   sprintf(aout+strlen(aout), "%50s:%d\n", "mem_mode", ptr->mem_mode);
 105   sprintf(aout+strlen(aout), "%50s:%d\n", "num_nodes",ptr->num_nodes);
 106   sprintf(aout+strlen(aout), "%50s:%08x\n", "top_ptr", (int) ptr->top_ptr);
 107   sprintf(aout+strlen(aout), "%50s:%d\n", "maxbits",  ptr->maxbits);
 108 
 109   if( IP_pref_b2a(  &(ptr->prefix), prstr, IP_PREFSTR_MAX) != IP_OK )
 110     die; /* program error.*/
 111 
 112   sprintf(aout+strlen(aout), "%50s:%s\n", "prefix", prstr);
 113   SK_cd_puts( (sk_conn_st *)condat,aout);
 114 }
 115 
 116 
 117 
 118 /***************************************************************************/
 119 
 120 void
 121 rx_nod_print( rx_node_t *node, char *buf, unsigned maxchar )
     /* [<][>][^][v][top][bottom][index][help] */
 122 {
 123   char pref[IP_PREFSTR_MAX];
 124   
 125   if( IP_pref_b2a(  &(node->prefix), pref, IP_PREFSTR_MAX) != IP_OK ) {
 126     die;
 127   }
 128   
 129   snprintf(buf, maxchar, "%s%s", 
 130            ( node->glue ) ? "++glue++" : "", pref);
 131 }
 132 /***************************************************************************/
 133 
 134 void 
 135 rx_stk_print( rx_nodcpy_t   stack[],         /* stack==array of node_copies*/
     /* [<][>][^][v][top][bottom][index][help] */
 136               int           stackdepth )
 137 {
 138   int i;
 139   rx_node_t *node;
 140   char buf[1024];
 141 
 142   ER_dbg_va(FAC_RX, ASP_RX_STKBLD_DET, 
 143             "stack dump: %d elements", stackdepth);
 144 
 145   for(i = 0; i < stackdepth; i++) {
 146     node = & stack[i].cpy;
 147 
 148     rx_nod_print(node, buf, 1024);
 149 
 150     ER_dbg_va(FAC_RX, ASP_RX_STKBLD_DET, "position %d: %s", i, buf);
 151   }
 152 }

/* [<][>][^][v][top][bottom][index][help] */