The actual implementation of raxShow(). */
| 2638 | |
| 2639 | /* The actual implementation of raxShow(). */ |
| 2640 | void raxRecursiveShow(int level, int lpad, raxNode *n) { |
| 2641 | char s = n->iscompr ? '"' : '['; |
| 2642 | char e = n->iscompr ? '"' : ']'; |
| 2643 | |
| 2644 | int numchars = printf("%c%.*s%c", s, n->size, n->data, e); |
| 2645 | if (n->iskey) { |
| 2646 | numchars += printf("=%p",raxGetData(n)); |
| 2647 | } |
| 2648 | |
| 2649 | int numchildren = n->iscompr ? 1 : n->size; |
| 2650 | /* Note that 7 and 4 magic constants are the string length |
| 2651 | * of " `-(x) " and " -> " respectively. */ |
| 2652 | if (level) { |
| 2653 | lpad += (numchildren > 1) ? 7 : 4; |
| 2654 | if (numchildren == 1) lpad += numchars; |
| 2655 | } |
| 2656 | raxNode **cp = raxNodeFirstChildPtr(n); |
| 2657 | for (int i = 0; i < numchildren; i++) { |
| 2658 | char *branch = " `-(%c) "; |
| 2659 | if (numchildren > 1) { |
| 2660 | printf("\n"); |
| 2661 | for (int j = 0; j < lpad; j++) putchar(' '); |
| 2662 | printf(branch,n->data[i]); |
| 2663 | } else { |
| 2664 | printf(" -> "); |
| 2665 | } |
| 2666 | if (raxIsInlineLeaf(n,i)) { |
| 2667 | void *val; |
| 2668 | memcpy(&val,cp,sizeof(val)); |
| 2669 | printf("[]=%p",val); |
| 2670 | } else { |
| 2671 | raxNode *child; |
| 2672 | memcpy(&child,cp,sizeof(child)); |
| 2673 | raxRecursiveShow(level+1,lpad,child); |
| 2674 | } |
| 2675 | cp++; |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | /* Show a tree, as outlined in the comment above. */ |
| 2680 | void raxShow(rax *rax) { |
no test coverage detected