r3_tree_dump can now optionally dump to a string. Fixes #15

This commit is contained in:
Omer Katz 2014-05-19 11:26:34 +03:00
parent 6ea4405ddf
commit b626dd374a
6 changed files with 59 additions and 12172 deletions

File diff suppressed because it is too large Load diff

View file

@ -118,7 +118,7 @@ node * r3_tree_insert_pathl(node *tree, char *path, int path_len, void * data);
*/ */
node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route, void * data); node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route, void * data);
void r3_tree_dump(node * n, int level); void r3_tree_dump(node * n, int level, char *out);
int r3_tree_render_file(node * tree, char * format, char * filename); int r3_tree_render_file(node * tree, char * format, char * filename);

View file

@ -32,7 +32,7 @@ char** str_split(char* a_str, const char a_delim);
void str_repeat(char *s, char *c, int len); void str_repeat(char *s, char *c, int len);
void print_indent(int level); void print_indent(int level, char *out);
#ifndef HAVE_STRDUP #ifndef HAVE_STRDUP
char *strdup(const char *s); char *strdup(const char *s);

10075
libtool

File diff suppressed because it is too large Load diff

View file

@ -501,8 +501,36 @@ bool r3_node_has_slug_edges(node *n) {
void r3_tree_dump(node * n, int level) { void r3_tree_dump(node * n, int level, char *out) {
print_indent(level); if (out)
{
print_indent(level, out);
if ( n->combined_pattern ) {
sprintf(out, " regexp:%s", n->combined_pattern);
}
sprintf(out, " endpoint:%d", n->endpoint);
if (n->data) {
sprintf(out, " data:%p", n->data);
}
sprintf(out, "\n");
for ( int i = 0 ; i < n->edge_len ; i++ ) {
edge * e = n->edges[i];
print_indent(level + 1, out);
sprintf(out, "|-\"%s\"", e->pattern);
if ( e->child ) {
sprintf(out, "\n");
r3_tree_dump(e->child, level + 1, out);
}
sprintf(out, "\n");
}
}
else
{
print_indent(level, out);
if ( n->combined_pattern ) { if ( n->combined_pattern ) {
printf(" regexp:%s", n->combined_pattern); printf(" regexp:%s", n->combined_pattern);
} }
@ -516,16 +544,17 @@ void r3_tree_dump(node * n, int level) {
for ( int i = 0 ; i < n->edge_len ; i++ ) { for ( int i = 0 ; i < n->edge_len ; i++ ) {
edge * e = n->edges[i]; edge * e = n->edges[i];
print_indent(level + 1); print_indent(level + 1, out);
printf("|-\"%s\"", e->pattern); printf("|-\"%s\"", e->pattern);
if ( e->child ) { if ( e->child ) {
printf("\n"); printf("\n");
r3_tree_dump( e->child, level + 1); r3_tree_dump(e->child, level + 1, out);
} }
printf("\n"); printf("\n");
} }
} }
}
/** /**

View file

@ -248,9 +248,15 @@ void str_repeat(char *s, char *c, int len) {
} }
} }
void print_indent(int level) { void print_indent(int level, char *out) {
int len = level * 2; int len = level * 2;
if (out) {
while(len--) { while(len--) {
sprintf(out, " ");
}
}
else
{
printf(" "); printf(" ");
} }
} }