The actual implementation of raxShow(). */
| 1851 | |
| 1852 | /* The actual implementation of raxShow(). */ |
| 1853 | void raxRecursiveShow(int level, int lpad, raxNode *n) { |
| 1854 | char s = n->iscompr ? '"' : '['; |
| 1855 | char e = n->iscompr ? '"' : ']'; |
| 1856 | |
| 1857 | int numchars = printf("%c%.*s%c", s, n->size, n->data, e); |
| 1858 | if (n->iskey) { |
| 1859 | numchars += printf("=%p",raxGetData(n)); |
| 1860 | } |
| 1861 | |
| 1862 | int numchildren = n->iscompr ? 1 : n->size; |
| 1863 | /* Note that 7 and 4 magic constants are the string length |
| 1864 | * of " `-(x) " and " -> " respectively. */ |
| 1865 | if (level) { |
| 1866 | lpad += (numchildren > 1) ? 7 : 4; |
| 1867 | if (numchildren == 1) lpad += numchars; |
| 1868 | } |
| 1869 | raxNode **cp = raxNodeFirstChildPtr(n); |
| 1870 | for (int i = 0; i < numchildren; i++) { |
| 1871 | char *branch = " `-(%c) "; |
| 1872 | if (numchildren > 1) { |
| 1873 | printf("\n"); |
| 1874 | for (int j = 0; j < lpad; j++) putchar(' '); |
| 1875 | printf(branch,n->data[i]); |
| 1876 | } else { |
| 1877 | printf(" -> "); |
| 1878 | } |
| 1879 | raxNode *child; |
| 1880 | memcpy(&child,cp,sizeof(child)); |
| 1881 | raxRecursiveShow(level+1,lpad,child); |
| 1882 | cp++; |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | /* Show a tree, as outlined in the comment above. */ |
| 1887 | void raxShow(rax *rax) { |