This commit is contained in:
c9s 2014-06-01 14:53:12 +08:00
parent 6e6de35fd0
commit 7d69e79535
5 changed files with 22 additions and 18 deletions

View file

@ -115,9 +115,6 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
void r3_tree_dump(const node * n, int level);
int r3_tree_render_file(const node * tree, const char * format, const char * filename);
int r3_tree_render_dot(node * tree);
edge * r3_node_find_edge_str(const node * n, const char * str, int str_len);

View file

@ -9,6 +9,10 @@
#include <gvc.h>
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, node * n, int node_cnt);
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt);
int r3_tree_render_dot(node * tree);
int r3_tree_render_file(const node * tree, const char * format, const char * filename);
#endif /* !R3_GVC_H */

View file

@ -12,14 +12,7 @@
#include "r3_gvc.h"
#include "zmalloc.h"
static char * node_id_str(int id) {
char * name = zmalloc(sizeof(char) * 20);
sprintf(name, "#%d", id);
return name;
}
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, node * n, int node_cnt) {
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt) {
edge * e;
Agnode_t *agn_child;
Agedge_t *agn_edge;
@ -28,7 +21,15 @@ void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, node * n, i
e = n->edges[i];
node_cnt++;
agn_child = agnode(g, node_id_str(node_cnt) , 1);
char *nodename = NULL;
if ( n->combined_pattern ) {
asprintf(&nodename,"%s", n->combined_pattern);
} else {
asprintf(&nodename,"#%d", node_cnt);
}
agn_child = agnode(g, nodename, 1);
agn_edge = agedge(g, ag_parent_node, agn_child, 0, 1);
agsafeset(agn_edge, "label", e->pattern, "");
if (e->child && e->child->endpoint) {

View file

@ -48,7 +48,10 @@ START_TEST (test_gvc_render_file)
r3_tree_insert_path(n, "/user/{id}", NULL);
r3_tree_insert_path(n, "/post/{title:\\w+}", NULL);
r3_tree_compile(n, NULL);
char *errstr = NULL;
int errcode;
errcode = r3_tree_compile(n, &errstr);
r3_tree_render_file(n, "png", "check_gvc.png");
r3_tree_free(n);
}

View file

@ -33,7 +33,6 @@ START_TEST (test_r3_node_find_edge)
node * child = r3_tree_create(3);
fail_if( r3_node_connect(n, zstrdup("/add") , child) == FALSE );
fail_if( r3_node_find_edge(n, "/add") == NULL );
fail_if( r3_node_find_edge(n, "/bar") != NULL );
@ -108,9 +107,9 @@ START_TEST (test_pcre_patterns_insert)
char *errstr = NULL;
int errno;
errno = r3_tree_compile(n, &errstr);
ck_assert(errno == 0); // no error
int errcode;
errcode = r3_tree_compile(n, &errstr);
ck_assert(errcode == 0); // no error
// r3_tree_dump(n, 0);