From: ellson Date: Mon, 13 Oct 2008 21:15:32 +0000 (+0000) Subject: add framework for "dot -P" X-Git-Tag: LAST_LIBGRAPH~32^2~3154 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42f29324b672de133e1c4d135f0a2d3b0a3f8084;p=graphviz add framework for "dot -P" --- diff --git a/cmd/dot/dot.c b/cmd/dot/dot.c index 4c17da1a6..97fee1279 100644 --- a/cmd/dot/dot.c +++ b/cmd/dot/dot.c @@ -167,11 +167,13 @@ int main(int argc, char **argv) /* Perform layout and cleanup */ gvLayoutJobs(Gvc, G); /* take layout engine from command line */ gvFreeLayout(Gvc, G); - - /* Delete graph */ - agclose(G); } - } else { + } + else if ((G = gvPluginsGraph(Gvc))) { + gvLayoutJobs(Gvc, G); /* take layout engine from command line */ + gvRenderJobs(Gvc, G); + } + else { while ((G = gvNextInputGraph(Gvc))) { if (prev) { gvFreeLayout(Gvc, prev); diff --git a/lib/common/input.c b/lib/common/input.c index 8918bcaae..4e628cc34 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -32,6 +32,7 @@ static char *genericItems = "\n\ -lv - Use external library 'v'\n\ -ofile - Write output to 'file'\n\ -O - Automatically generate an output filename based on the input filename with a .'format' appended. (Causes all -ofile options to be ignored.) \n\ + -P - Internally generate a graph of the current plugins. \n\ -q[l] - Set level of message suppression (=1)\n\ -s[v] - Scale input by 'v' (=72)\n\ -y - Invert y coordinate in output\n"; @@ -180,6 +181,30 @@ void global_def(const char *dcl, sym->fixed = 1; } +static void gvg_init(GVC_t *gvc, graph_t *g, char *fn, int gidx) +{ + GVG_t *gvg; + + gvg = zmalloc(sizeof(GVG_t)); + if (!gvc->gvgs) + gvc->gvgs = gvg; + else + gvc->gvg->next = gvg; + gvc->gvg = gvg; + gvg->gvc = gvc; + gvg->g = g; + gvg->input_filename = fn; + gvg->graph_index = gidx; +} + +static graph_t *P_graph; + +graph_t *gvPluginsGraph(GVC_t *gvc) +{ + gvg_init(gvc, P_graph, "", 0); + return P_graph; +} + void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv) { char c; @@ -275,6 +300,9 @@ void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv) exit(1); } break; + case 'P': + P_graph = gvplugin_graph(gvc); + break; case 'V': fprintf(stderr, "%s - %s version %s (%s)\n", gvc->common.cmdname, gvc->common.info[0], @@ -441,7 +469,6 @@ graph_t *gvNextInputGraph(GVC_t *gvc) static char *fn; static FILE *fp; static int fidx, gidx; - GVG_t *gvg; while (!g) { if (!fp) { @@ -465,16 +492,7 @@ graph_t *gvNextInputGraph(GVC_t *gvc) g = agread(fp); #endif if (g) { - gvg = zmalloc(sizeof(GVG_t)); - if (!gvc->gvgs) - gvc->gvgs = gvg; - else - gvc->gvg->next = gvg; - gvc->gvg = gvg; - gvg->gvc = gvc; - gvg->g = g; - gvg->input_filename = fn; - gvg->graph_index = gidx++; + gvg_init(gvc, g, fn, gidx++); break; } fp = NULL; diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 9d0f21cd1..194cfe650 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -70,6 +70,7 @@ extern char *gvcUsername(GVC_t*); /* parse command line args - minimally argv[0] sets layout engine */ extern int gvParseArgs(GVC_t *gvc, int argc, char **argv); extern graph_t *gvNextInputGraph(GVC_t *gvc); +extern graph_t *gvPluginsGraph(GVC_t *gvc); /* Compute a layout using a specified engine */ extern int gvLayout(GVC_t *gvc, graph_t *g, const char *engine); diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index a3ea79480..25d36ebe7 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -43,6 +43,8 @@ extern "C" { extern void gvplugin_write_status(GVC_t * gvc); extern char *gvplugin_list(GVC_t * gvc, api_t api, const char *str); + extern Agraph_t * gvplugin_graph(GVC_t * gvc); + /* job */ extern void gvjobs_output_filename(GVC_t * gvc, const char *name); diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index b9389e484..fd113cf49 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -31,6 +31,8 @@ #include "gvcint.h" #include "gvcproc.h" +#include "const.h" + extern const int Demand_Loading; /* @@ -454,3 +456,18 @@ void gvplugin_write_status(GVC_t * gvc) } } + +Agraph_t * gvplugin_graph(GVC_t * gvc) +{ + Agraph_t *g; + Agnode_t *n; + + aginit(); + /* set persistent attributes here */ + agnodeattr(NULL, "label", NODENAME_ESC); + + g = agopen("G", AGDIGRAPH); + n = agnode(g, "plugins graph under-construction"); + + return g; +}