From: Emden R. Gansner Date: Mon, 8 Jul 2013 15:46:46 +0000 (-0400) Subject: Allow user to specify root graph name in gvpack; fix bug 2282 X-Git-Tag: LAST_LIBGRAPH~32^2~158^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=832a4d26a852a3ea276f5ace02c8a7d9023a8996;p=graphviz Allow user to specify root graph name in gvpack; fix bug 2282 --- diff --git a/cmd/tools/gvpack.c b/cmd/tools/gvpack.c index 5dad5b401..ab9b985f0 100644 --- a/cmd/tools/gvpack.c +++ b/cmd/tools/gvpack.c @@ -95,6 +95,7 @@ static int G_cnt; /* No. of -G arguments */ static int G_sz; /* Storage size for -G arguments */ static attr_t *G_args; /* Storage for -G arguments */ static int doPack; /* Do packing if true */ +static char* gname = "root"; #define NEWNODE(n) ((node_t*)ND_alg(n)) @@ -105,6 +106,7 @@ static char *useString = -array* - pack as array of graphs\n\ -G= - attach name/value attribute to output graph\n\ -m - set margin to points\n\ + -s - use for name of root graph\n\ -o - write output to \n\ -u - no packing; just combine graphs\n\ -v - verbose\n\ @@ -216,7 +218,7 @@ static void init(int argc, char *argv[], pack_info* pinfo) pinfo->fixed = 0; opterr = 0; - while ((c = getopt(argc, argv, ":na:gvum:o:G:")) != -1) { + while ((c = getopt(argc, argv, ":na:gvum:s:o:G:")) != -1) { switch (c) { case 'a': len = strlen(optarg) + 2; @@ -232,6 +234,9 @@ static void init(int argc, char *argv[], pack_info* pinfo) case 'n': pinfo->mode = l_node; break; + case 's': + gname = optarg; + break; case 'g': pinfo->mode = l_graph; break; @@ -354,17 +359,26 @@ static void cloneDfltAttrs(Agraph_t *old, Agraph_t *new, int kind) Agsym_t *a; for (a = agnxtattr(old, kind, 0); a; a = agnxtattr(old, kind, a)) { - agattr (new, kind, a->name, a->defval); + if (aghtmlstr(a->defval)) + agattr (new, kind, a->name, agstrdup_html(new, a->defval)); + else + agattr (new, kind, a->name, a->defval); } } static void cloneAttrs(void *old, void *new) { int kind = AGTYPE(old); Agsym_t *a; + char* s; Agraph_t *g = agroot(old); + Agraph_t *ng = agroot(new); for (a = agnxtattr(g, kind, 0); a; a = agnxtattr(g, kind, a)) { - agset(new, a->name, agxget(old, a)); + s = agxget (old, a); + if (aghtmlstr(s)) + agset(new, a->name, agstrdup_html(ng, s)); + else + agset(new, a->name, s); } } #else @@ -759,9 +773,9 @@ static Agraph_t *cloneGraph(Agraph_t ** gs, int cnt, GVC_t * gvc) if (verbose) fprintf(stderr, "Creating clone graph\n"); #ifndef WITH_CGRAPH - root = agopen("root", kind); + root = agopen(gname, kind); #else - root = agopen("root", kind, &AgDefaultDisc); + root = agopen(gname, kind, &AgDefaultDisc); #endif initAttrs(root, gs, cnt); G_bb = agfindgraphattr(root, "bb");