r3_tree_render_dot(const node * tree, FILE *fp); support

This commit is contained in:
c9s 2014-06-03 18:37:36 +08:00
parent 67366bf688
commit b68e14dd66
3 changed files with 5 additions and 4 deletions

View file

@ -7,11 +7,12 @@
#ifndef R3_GVC_H #ifndef R3_GVC_H
#define R3_GVC_H #define R3_GVC_H
#include <stdio.h>
#include <gvc.h> #include <gvc.h>
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const 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(const node * tree); int r3_tree_render_dot(const node * tree, FILE *fp);
int r3_tree_render_file(const node * tree, const char * format, const char * filename); int r3_tree_render_file(const node * tree, const char * format, const char * filename);

View file

@ -45,7 +45,7 @@ void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node
/** /**
* Render a tree to tree graph image via graphviz (dot) * Render a tree to tree graph image via graphviz (dot)
*/ */
int r3_tree_render_dot(const node * tree) int r3_tree_render_dot(const node * tree, FILE *fp)
{ {
Agraph_t *g; Agraph_t *g;
/* set up a graphviz context - but only once even for multiple graphs */ /* set up a graphviz context - but only once even for multiple graphs */
@ -61,7 +61,7 @@ int r3_tree_render_dot(const node * tree)
Agnode_t *ag_root = agnode(g, "{root}", 1); Agnode_t *ag_root = agnode(g, "{root}", 1);
r3_tree_build_ag_nodes(g, ag_root, tree, 0); r3_tree_build_ag_nodes(g, ag_root, tree, 0);
gvLayout(gvc, g, "dot"); gvLayout(gvc, g, "dot");
gvRender(gvc, g, "dot", stdout); gvRender(gvc, g, "dot", fp);
gvFreeLayout(gvc, g); gvFreeLayout(gvc, g);
agclose(g); agclose(g);
return 0; return 0;

View file

@ -27,7 +27,7 @@ START_TEST (test_gvc_render_dot)
r3_tree_compile(n, NULL); r3_tree_compile(n, NULL);
r3_tree_render_dot(n); r3_tree_render_dot(n, stderr);
r3_tree_free(n); r3_tree_free(n);
} }