return cnt;
}
-void parse_args(GVC_t *gvc, int argc, char** argv)
+int gvParseArgs(GVC_t *gvc, int argc, char** argv)
{
argc = neato_extra_args(gvc, argc, argv);
argc = fdp_extra_args(gvc, argc, argv);
argc = memtest_extra_args(gvc, argc, argv);
dotneato_initialize(gvc, argc, argv);
+ return 0;
}
extern gvevent_key_binding_t gvevent_key_binding[];
extern int gvevent_key_binding_size;
-void emit_jobs (GVC_t * gvc, graph_t * g)
+int gvRenderJobs (GVC_t * gvc, graph_t * g)
{
GVJ_t *job;
job->output_lang = gvrender_select(job, job->output_langname);
if (job->output_lang == NO_SUPPORT) {
fprintf(stderr,"renderer for %s is unavailable\n", job->output_langname);
- return;
+ return 1;
}
emit_job(job, g);
- /* last job, after all input graphs are processed, is finalized from dotneato_terminate() */
-
+ /* the last job, after all input graphs are processed,
+ * is finalized from gvFreeContext()
+ */
}
+ return 0;
}
}
}
}
-
-void dotneato_terminate(GVC_t * gvc)
-{
- if (gvc->active_jobs)
- gvdevice_finalize(gvc);
- emit_jobs_eof(gvc);
- exit(graphviz_errors + agerrors());
-}
extern void dotneato_usage(int);
extern void dotneato_postprocess(Agraph_t *, nodesizefn_t);
extern void dotneato_set_margins(GVC_t * gvc, Agraph_t *);
- extern void dotneato_terminate(GVC_t * gvc);
extern void dotneato_write(GVC_t * gvc, graph_t *g);
extern void dotneato_write_one(GVC_t * gvc, graph_t *g);
extern double elapsed_sec(void);
extern void emit_graph(GVJ_t * job, graph_t * g);
extern void emit_label(GVJ_t * job, textlabel_t *, void *obj);
extern int emit_once(char *message);
- extern void emit_jobs(GVC_t * gvc, graph_t *g);
extern void emit_jobs_eof(GVC_t * gvc);
extern void emit_textlines(GVJ_t*, int, textline_t*, pointf,
double, char*, double, char*);
extern bezier *new_spline(edge_t * e, int sz);
extern Agraph_t *next_input_graph(void);
extern void osize_label(textlabel_t *, int *, int *, int *, int *);
- extern void parse_args(GVC_t *gvc, int argc, char** argv);
extern char **parse_style(char *s);
extern void place_graph_label(Agraph_t *);
extern void place_portlabel(edge_t * e, boolean head_p);
g = g->root;
if (GD_drawing(g)) { /* only cleanup once between layouts */
- gvlayout_cleanup(gvc, g);
+ gvFreeLayout(gvc, g);
GD_drawing(g) = NULL;
}
rc = gvlayout_select(gvc, engine);
return -1;
}
- gvlayout_layout(gvc, g);
+ gvLayoutJobs(gvc, g);
/* set bb attribute for basic layout.
* doesn't yet include margins, scaling or page sizes because
}
job->output_file = out;
- emit_jobs(gvc, g);
+ gvRenderJobs(gvc, g);
gvrender_delete_jobs(gvc);
return 0;
}
-
-
-void gvCleanup(GVC_t *gvc)
-{
- gvFREEcontext(gvc);
-}
extern "C" {
#endif
+#define dotneato_initialize dotneato_initialize_DEPRECATED_BY_gvParseArgs
+#define parse_args parse_args_DEPRECATED_BY_gvParseArgs
+
+#define dot_layout dot_layout_DEPRECATED_BY_gvLayout
+#define neato_layout dot_layout_DEPRECATED_BY_gvLayout
+#define fdp_layout dot_layout_DEPRECATED_BY_gvLayout
+#define circo_layout dot_layout_DEPRECATED_BY_gvLayout
+#define twopi_layout dot_layout_DEPRECATED_BY_gvLayout
+#define gvBindContext gvBindContext_DEPRECATED_BY_gvLayout
+#define gvlayout_layout gvlayout_layout_DEPRECATED_BY_gvLayoutJobs
+
+#define emit_jobs emit_jobs_DEPRECATED_BY_gvRenderJobs
+#define dotneato_write dotneato_write_DEPRECATED_BY_gvRenderJobs
+
+#define dot_cleanup dot_cleanup_DEPRECATED_BY_gvFreeLayout
+#define neato_cleanup dot_cleanup_DEPRECATED_BY_gvFreeLayout
+#define fdp_cleanup dot_cleanup_DEPRECATED_BY_gvFreeLayout
+#define circo_cleanup dot_cleanup_DEPRECATED_BY_gvFreeLayout
+#define twopi_cleanup dot_cleanup_DEPRECATED_BY_gvFreeLayout
+#define gvlayout_cleanup gvlayout_cleanup_DEPRECATED_BY_gvFreeLayout
+
+#define gvCleanup gvCleanup_DEPRECATED_BY_gvFreeContext
+#define dotneato_terminate dotneato_terminate_DEPRECATED_BY_gvFreeContext
+
+
+/* set up a graphviz context */
extern GVC_t *gvContext(void);
+
+/* parse command line args - minimally argv[0] sets layout engine */
+extern int gvParseArgs(GVC_t *gvc, int argc, char **argv);
+
+
+/* Compute a layout using a specified engine */
extern int gvLayout(GVC_t *gvc, graph_t *g, char *engine);
+
+/* Compute a layout using layout engine from command line args */
+extern int gvLayoutJobs(GVC_t *gvc, graph_t *g);
+
+/* Render layout in a specified format to a specified output file */
extern int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out);
-extern void gvCleanup(GVC_t *gvc);
+
+/* Render layout according to -T and -o options found by gvParseArgs */
+extern int gvRenderJobs(GVC_t *gvc, graph_t *g);
+
+/* Clean up layout data structures - layouts are not nestable (yet) */
+extern int gvFreeLayout(GVC_t *gvc, graph_t *g);
+
+/* Clean up graphviz context */
+extern int gvFreeContext(GVC_t *gvc);
#ifdef __cplusplus
}
/* from common/utils.c */
extern void *zmalloc(size_t);
+/* from common/emit.c */
+extern void emit_jobs_eof(GVC_t *gvc);
+
+/* from common/globals.c */
+extern int graphviz_errors;
+
GVC_t *gvNEWcontext(char **info, char *user)
{
GVC_t *gvc = zmalloc(sizeof(GVC_t));
return gvc;
}
-void gvFREEcontext(GVC_t * gvc)
+int gvFreeContext(GVC_t * gvc)
{
+ if (gvc->active_jobs)
+ gvdevice_finalize(gvc);
+ emit_jobs_eof(gvc);
gvrender_delete_jobs(gvc);
free(gvc);
+ return (graphviz_errors + agerrors());
}
extern "C" {
#endif
+/* these are intended to be private entry points - see gvc.h for the public ones */
+
/* context */
extern GVC_t *gvNEWcontext(char **info, char *user);
- extern void gvFREEcontext(GVC_t * gvc);
/* configuration */
/* layout */
extern int gvlayout_select(GVC_t * gvc, char *str);
- extern void gvlayout_layout(GVC_t * gvc, graph_t * g);
- extern void gvlayout_cleanup(GVC_t * gvc, graph_t * g);
#ifdef __cplusplus
}
return NO_SUPPORT;
}
-void gvlayout_layout(GVC_t * gvc, graph_t * g)
+int gvLayoutJobs(GVC_t * gvc, graph_t * g)
{
gvlayout_engine_t *gvle = gvc->layout.engine;
graph_init(g, gvc->layout.features->flags & LAYOUT_USES_RANKDIR);
GD_gvc(g) = gvc;
-
if (gvle && gvle->layout)
gvle->layout(g);
+ return 0;
}
-void gvlayout_cleanup(GVC_t * gvc, graph_t * g)
+int gvFreeLayout(GVC_t * gvc, graph_t * g)
{
gvlayout_engine_t *gvle = gvc->layout.engine;
+ g = g->root;
+ if (gvc->active_jobs)
+ gvdevice_finalize(gvc);
if (gvle && gvle->cleanup)
gvle->cleanup(g);
-
graph_cleanup(g);
+ return 0;
}
{
g = g->root;
if (GD_drawing(g)) { /* only cleanup once between layouts */
- gvlayout_cleanup(gvc, g);
+ gvFreeLayout(gvc, g);
GD_drawing(g) = NULL;
}
}
void layout(Agraph_t *g, char *engine)
{
- char buf[256];
- Agsym_t *a;
- int rc;
-
- g = g->root;
- reset_layout(g); /* in case previously drawn */
-
- rc = gvlayout_select(gvc, engine);
- if (rc == NO_SUPPORT) {
- fprintf(stderr, "Layout type: \"%s\" not recognized. Use one of:%s\n",
- engine, gvplugin_list(gvc, API_layout, engine));
- return;
- }
+ int err;
- gvlayout_layout(gvc, g);
-
-/* set bb attribute for basic layout.
- * doesn't yet include margins, scaling or page sizes because
- * those depend on the renderer being used. */
- if (GD_drawing(g)->landscape)
- sprintf(buf, "%d %d %d %d",
- ROUND(GD_bb(g).LL.y), ROUND(GD_bb(g).LL.x),
- ROUND(GD_bb(g).UR.y), ROUND(GD_bb(g).UR.x));
- else
- sprintf(buf, "%d %d %d %d",
- ROUND(GD_bb(g).LL.x), ROUND(GD_bb(g).LL.y),
- ROUND(GD_bb(g).UR.x), ROUND(GD_bb(g).UR.y));
- if (!(a = agfindattr(g, "bb"))) {
- a = agraphattr(g, "bb", "");
+ err = gvLayout(gvc, g, engine);
+ if (err) {
+ fprintf(stderr, "Layout type: \"%s\" not recognized. Use one of:%s\n", engine, gvplugin_list(gvc, API_layout, engine));
+ return;
}
- agxset(g, a->index, buf);
}
void writegraph(Agraph_t *g, char *filename, char *format)
{
- int rc;
+ int err;
GVJ_t *job;
g = g->root;
/* create a job for the required format */
- rc = gvrender_output_langname_job(gvc, format);
- if (rc == NO_SUPPORT) {
+ err = gvrender_output_langname_job(gvc, format);
+ if (err == NO_SUPPORT) {
fprintf(stderr, "Renderer type: \"%s\" not recognized. Use one of:%s\n",
format, gvplugin_list(gvc, API_render, format));
return;
}
gvrender_output_filename_job(gvc, filename);
- emit_jobs(gvc, g);
+ gvRenderJobs(gvc, g);
gvrender_delete_jobs(gvc);
}
Agraph_t *g = sg->root;
if (GD_drawing(g)) { /* only cleanup once between layouts */
- gvlayout_cleanup(gvc, g);
+ gvFreeLayout(gvc, g);
GD_drawing(g) = NULL;
}
}
engine, gvplugin_list(gvc, API_layout, engine));
return;
}
- gvlayout_layout(gvc, g);
+ gvLayoutJobs(gvc, g);
/* set bb attribute for basic layout.
* doesn't yet include margins, scaling or page sizes because
tcldot_layout (gvc, g, (argc > 3) ? argv[3] : (char *) NULL);
/* render graph TK canvas commands */
- emit_jobs(gvc, g);
+ gvLayoutJobs(gvc, g);
gvrender_delete_jobs(gvc);
return TCL_OK;
if (!GD_drawing(g) || argc > 4)
tcldot_layout(gvc, g, (argc > 4) ? argv[4] : (char *) NULL);
- emit_jobs(gvc, g);
+ gvRenderJobs(gvc, g);
gvrender_delete_jobs(gvc);
Tcl_AppendResult(interp, argv[2], (char *) NULL);
tcldot_layout(gvc, g, (argc > 4) ? argv[4] : (char *) NULL);
}
- emit_jobs(gvc, g);
+ gvRenderJobs(gvc, g);
gvrender_delete_jobs(gvc);
return TCL_OK;