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);
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);

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 print_indent(int level);
void print_indent(int level, char *out);
#ifndef HAVE_STRDUP
char *strdup(const char *s);

10075
libtool

File diff suppressed because it is too large Load diff

View file

@ -501,30 +501,59 @@ bool r3_node_has_slug_edges(node *n) {
void r3_tree_dump(node * n, int level) {
print_indent(level);
if ( n->combined_pattern ) {
printf(" regexp:%s", n->combined_pattern);
void r3_tree_dump(node * n, int level, char *out) {
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 ) {
printf(" regexp:%s", n->combined_pattern);
}
printf(" endpoint:%d", n->endpoint);
printf(" endpoint:%d", n->endpoint);
if (n->data) {
printf(" data:%p", n->data);
}
printf("\n");
if (n->data) {
printf(" data:%p", n->data);
}
printf("\n");
for ( int i = 0 ; i < n->edge_len ; i++ ) {
edge * e = n->edges[i];
print_indent(level + 1);
printf("|-\"%s\"", e->pattern);
for ( int i = 0 ; i < n->edge_len ; i++ ) {
edge * e = n->edges[i];
print_indent(level + 1, out);
printf("|-\"%s\"", e->pattern);
if ( e->child ) {
printf("\n");
r3_tree_dump( e->child, level + 1);
}
printf("\n");
}
if ( e->child ) {
printf("\n");
r3_tree_dump(e->child, level + 1, out);
}
printf("\n");
}
}
}

View file

@ -248,10 +248,16 @@ 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;
while(len--) {
printf(" ");
if (out) {
while(len--) {
sprintf(out, " ");
}
}
else
{
printf(" ");
}
}