From: ellson Date: Wed, 27 Jul 2005 19:55:28 +0000 (+0000) Subject: Cleanup and extend the API in gvc.h X-Git-Tag: LAST_LIBGRAPH~32^2~7374 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8be86f427d46de2a9f411d9c9bf07b800300e8d7;p=graphviz Cleanup and extend the API in gvc.h Add #defines to give compile warnings for old API entry points Update: dot, tcldot, script bindings, and dot.demo/ to use the modified API --- diff --git a/lib/common/args.c b/lib/common/args.c index 33f2b70eb..23ed8ae2b 100644 --- a/lib/common/args.c +++ b/lib/common/args.c @@ -217,10 +217,11 @@ fdp_extra_args (GVC_t *gvc, int argc, char** argv) 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; } diff --git a/lib/common/emit.c b/lib/common/emit.c index 0e91b3710..3f7594945 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1747,7 +1747,7 @@ static void init_bb(graph_t *g) 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; @@ -1772,7 +1772,7 @@ void emit_jobs (GVC_t * gvc, graph_t * g) 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; } @@ -1789,7 +1789,9 @@ void emit_jobs (GVC_t * gvc, graph_t * g) 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; } diff --git a/lib/common/input.c b/lib/common/input.c index e04e77546..266a4e026 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -740,11 +740,3 @@ void do_graph_label(graph_t * sg) } } } - -void dotneato_terminate(GVC_t * gvc) -{ - if (gvc->active_jobs) - gvdevice_finalize(gvc); - emit_jobs_eof(gvc); - exit(graphviz_errors + agerrors()); -} diff --git a/lib/common/renderprocs.h b/lib/common/renderprocs.h index 73066d5fa..9eb86c975 100644 --- a/lib/common/renderprocs.h +++ b/lib/common/renderprocs.h @@ -52,7 +52,6 @@ extern "C" { 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); @@ -62,7 +61,6 @@ extern "C" { 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*); @@ -99,7 +97,6 @@ extern "C" { 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); diff --git a/lib/gvc/gvc.c b/lib/gvc/gvc.c index 9c4a38218..51d085ba7 100644 --- a/lib/gvc/gvc.c +++ b/lib/gvc/gvc.c @@ -41,7 +41,7 @@ int gvLayout(GVC_t *gvc, graph_t *g, char *engine) 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); @@ -51,7 +51,7 @@ int gvLayout(GVC_t *gvc, graph_t *g, char *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 @@ -95,14 +95,8 @@ int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out) } job->output_file = out; - emit_jobs(gvc, g); + gvRenderJobs(gvc, g); gvrender_delete_jobs(gvc); return 0; } - - -void gvCleanup(GVC_t *gvc) -{ - gvFREEcontext(gvc); -} diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index f06e5ea39..b2d246f26 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -26,10 +26,55 @@ 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 } diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index b4e22d6f4..53ad3c154 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -39,6 +39,12 @@ /* 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)); @@ -51,8 +57,12 @@ GVC_t *gvNEWcontext(char **info, char *user) 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()); } diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index f847fd16e..f6a60b51e 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -23,10 +23,11 @@ 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 */ @@ -122,8 +123,6 @@ extern "C" { /* 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 } diff --git a/lib/gvc/gvlayout.c b/lib/gvc/gvlayout.c index f3a30d363..02e318b92 100644 --- a/lib/gvc/gvlayout.c +++ b/lib/gvc/gvlayout.c @@ -56,23 +56,26 @@ int gvlayout_select(GVC_t * gvc, char *layout) 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; } diff --git a/tclpkg/gv/gv.cpp b/tclpkg/gv/gv.cpp index 5645f63f5..7576af324 100644 --- a/tclpkg/gv/gv.cpp +++ b/tclpkg/gv/gv.cpp @@ -250,56 +250,32 @@ static void reset_layout(Agraph_t *g) { 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; @@ -313,6 +289,6 @@ void writegraph(Agraph_t *g, char *filename, char *format) } gvrender_output_filename_job(gvc, filename); - emit_jobs(gvc, g); + gvRenderJobs(gvc, g); gvrender_delete_jobs(gvc); } diff --git a/tclpkg/tcldot/tcldot.c b/tclpkg/tcldot/tcldot.c index 568fcd280..e3fc4d29d 100644 --- a/tclpkg/tcldot/tcldot.c +++ b/tclpkg/tcldot/tcldot.c @@ -57,7 +57,7 @@ static void reset_layout(GVC_t *gvc, Agraph_t * sg) 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; } } @@ -576,7 +576,7 @@ static void tcldot_layout(GVC_t *gvc, Agraph_t * g, char *engine) 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 @@ -1091,7 +1091,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, 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; @@ -1125,7 +1125,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, 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); @@ -1265,7 +1265,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp, tcldot_layout(gvc, g, (argc > 4) ? argv[4] : (char *) NULL); } - emit_jobs(gvc, g); + gvRenderJobs(gvc, g); gvrender_delete_jobs(gvc); return TCL_OK;