Added the r3_dump_tree_str function.
This commit is contained in:
parent
74dc283012
commit
132bd20361
5 changed files with 54 additions and 1 deletions
|
@ -63,6 +63,10 @@ r3_tree_compile(n);
|
||||||
// dump the compiled tree
|
// dump the compiled tree
|
||||||
r3_tree_dump(n, 0);
|
r3_tree_dump(n, 0);
|
||||||
|
|
||||||
|
// dump the compiled tree to a string
|
||||||
|
sds tree_dump = sdsempty();
|
||||||
|
tree_dump = r3_tree_dump_str(n, 0, tree_dump);
|
||||||
|
|
||||||
// match a route
|
// match a route
|
||||||
node *matched_node = r3_tree_match(n, "/foo/bar", strlen("/foo/bar"), NULL);
|
node *matched_node = r3_tree_match(n, "/foo/bar", strlen("/foo/bar"), NULL);
|
||||||
if (matched_node) {
|
if (matched_node) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "r3_define.h"
|
#include "r3_define.h"
|
||||||
#include "str_array.h"
|
#include "str_array.h"
|
||||||
|
#include "sds.h"
|
||||||
|
|
||||||
|
|
||||||
#define node_edge_pattern(node,i) node->edges[i]->pattern
|
#define node_edge_pattern(node,i) node->edges[i]->pattern
|
||||||
|
@ -77,7 +78,7 @@ typedef struct {
|
||||||
|
|
||||||
void * data; // route ptr
|
void * data; // route ptr
|
||||||
|
|
||||||
char * host; // the request host
|
char * host; // the request host
|
||||||
int host_len;
|
int host_len;
|
||||||
|
|
||||||
char * remote_addr;
|
char * remote_addr;
|
||||||
|
@ -129,6 +130,8 @@ node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route
|
||||||
|
|
||||||
void r3_tree_dump(node * n, int level);
|
void r3_tree_dump(node * n, int level);
|
||||||
|
|
||||||
|
sds r3_tree_dump_str(node *n, int level, sds output);
|
||||||
|
|
||||||
int r3_tree_render_file(node * tree, char * format, char * filename);
|
int r3_tree_render_file(node * tree, char * format, char * filename);
|
||||||
|
|
||||||
int r3_tree_render_dot(node * tree);
|
int r3_tree_render_dot(node * tree);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#define STR_H
|
#define STR_H
|
||||||
|
|
||||||
#include "r3.h"
|
#include "r3.h"
|
||||||
|
#include "sds.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
int slug_count(char * p, int len);
|
int slug_count(char * p, int len);
|
||||||
|
@ -28,6 +29,8 @@ void str_repeat(char *s, char *c, int len);
|
||||||
|
|
||||||
void print_indent(int level);
|
void print_indent(int level);
|
||||||
|
|
||||||
|
sds concat_indent(sds s, int level);
|
||||||
|
|
||||||
#ifndef HAVE_STRDUP
|
#ifndef HAVE_STRDUP
|
||||||
char *strdup(const char *s);
|
char *strdup(const char *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
34
src/node.c
34
src/node.c
|
@ -11,6 +11,7 @@
|
||||||
#include "r3.h"
|
#include "r3.h"
|
||||||
#include "r3_str.h"
|
#include "r3_str.h"
|
||||||
#include "str_array.h"
|
#include "str_array.h"
|
||||||
|
#include "sds.h"
|
||||||
#include "zmalloc.h"
|
#include "zmalloc.h"
|
||||||
|
|
||||||
// String value as the index http://judy.sourceforge.net/doc/JudySL_3x.htm
|
// String value as the index http://judy.sourceforge.net/doc/JudySL_3x.htm
|
||||||
|
@ -650,6 +651,39 @@ void r3_tree_dump(node * n, int level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sds r3_tree_dump_str(node *n, int level, sds output) {
|
||||||
|
output = concat_indent(output, level);
|
||||||
|
|
||||||
|
output = sdscatprintf(output, "(o)");
|
||||||
|
|
||||||
|
if ( n->combined_pattern ) {
|
||||||
|
output = sdscatprintf(output, " regexp:%s", n->combined_pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
output = sdscatprintf(output, " endpoint:%d", n->endpoint);
|
||||||
|
|
||||||
|
if (n->data) {
|
||||||
|
output = sdscatprintf(output, " data:%p", n->data);
|
||||||
|
}
|
||||||
|
output = sdscatprintf(output, "\n");
|
||||||
|
|
||||||
|
for ( int i = 0 ; i < n->edge_len ; i++ ) {
|
||||||
|
edge * e = n->edges[i];
|
||||||
|
print_indent(level + 1);
|
||||||
|
output = sdscatprintf(output, "|-\"%s\"", e->pattern);
|
||||||
|
|
||||||
|
if (e->opcode ) {
|
||||||
|
output = sdscatprintf(output, " opcode:%d", e->opcode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( e->child ) {
|
||||||
|
output = sdscatprintf(output, "\n");
|
||||||
|
r3_tree_dump_str( e->child, level + 1, output);
|
||||||
|
}
|
||||||
|
output = sdscatprintf(output, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return 0 == equal
|
* return 0 == equal
|
||||||
|
|
|
@ -219,6 +219,15 @@ void print_indent(int level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sds concat_indent(sds s, int level) {
|
||||||
|
int len = level * 2;
|
||||||
|
while(len--) {
|
||||||
|
s = sdscatprintf(s, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef HAVE_STRDUP
|
#ifndef HAVE_STRDUP
|
||||||
char *zstrdup(const char *s) {
|
char *zstrdup(const char *s) {
|
||||||
char *out;
|
char *out;
|
||||||
|
|
Loading…
Reference in a new issue