lash_tree2_dump.c (1637B)
1 #include "liblash/lash_tree2_dump.h" 2 #include "liblash/lash_tree2.h" 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 struct lash_tree_dump_monitor { 7 lash_tree_t **tree; 8 char **name; 9 } lash_tree_dump_monitor; 10 11 unsigned int lash_tree_dump_monitor_capacity; 12 unsigned int lash_tree_dump_monitor_count; 13 14 void lash_treeDump(lash_tree_t *dumptree, char *comment) { 15 int i; 16 int j; 17 18 lash_tree_t *currenttree; 19 20 for (i = 0; i < lash_tree_dump_monitor_count; i++) { 21 currenttree = *(lash_tree_dump_monitor.tree + i); 22 if (dumptree != NULL) 23 if (dumptree != currenttree) 24 continue; 25 26 printf("'%s' size %d", *(lash_tree_dump_monitor.name + i), currenttree->count); 27 if (comment != NULL) 28 printf(" (%s)", comment); 29 printf(": "); 30 31 for (j = 0; j < currenttree->count; j++) { 32 printf("i:%2d v:%3li, ", j, *(currenttree->val + currenttree->shiftpos + j)); 33 } 34 printf("\n"); 35 } 36 } 37 38 int lash_treeDumpInit(unsigned int count) { 39 40 lash_tree_dump_monitor.tree = (lash_tree_t*)malloc(sizeof(lash_tree_t*) * count); 41 if (lash_tree_dump_monitor.tree == NULL) 42 return -1; 43 44 lash_tree_dump_monitor.name = (char*)malloc(sizeof(char) * 128 * count); 45 if (lash_tree_dump_monitor.name == NULL) 46 return -1; 47 48 lash_tree_dump_monitor_capacity = count; 49 lash_tree_dump_monitor_count = 0; 50 51 return 0; 52 } 53 54 int lash_treeDumpAdd(lash_tree_t *dumptree, char *name) { 55 if (lash_tree_dump_monitor_count == lash_tree_dump_monitor_capacity) 56 return -1; 57 58 *(lash_tree_dump_monitor.tree + lash_tree_dump_monitor_count) = dumptree; 59 *(lash_tree_dump_monitor.name + lash_tree_dump_monitor_count) = name; 60 61 lash_tree_dump_monitor_count++; 62 63 return 0; 64 }