Graphviz 14.1.2~dev.20260118.1035
Loading...
Searching...
No Matches
gvpack.cpp
Go to the documentation of this file.
1
6/*************************************************************************
7 * Copyright (c) 2011 AT&T Intellectual Property
8 * All rights reserved. This program and the accompanying materials
9 * are made available under the terms of the Eclipse Public License v1.0
10 * which accompanies this distribution, and is available at
11 * https://www.eclipse.org/legal/epl-v10.html
12 *
13 * Contributors: Details at https://graphviz.org
14 *************************************************************************/
15
16
17/*
18 * Written by Emden R. Gansner
19 */
20
21
22
23#include "config.h"
24
25#include <getopt.h>
26#include <algorithm>
27#include <cassert>
28#include <gvc/gvc.h>
29#include <cgraph/ingraphs.h>
30#include <common/render.h>
31#include <common/utils.h>
32#include <neatogen/neatoprocs.h>
33#include <iostream>
34#include <limits>
35#include <map>
36#include <optional>
37#include <pack/pack.h>
38#include <set>
39#include <stddef.h>
40#include <string>
41#include <utility>
42#include <util/alloc.h>
43#include <util/exit.h>
44#include <vector>
45#include "openFile.h"
46
47extern "C" {
48#ifdef GVDLL
49 __declspec(dllimport)
50#endif
52}
53
55 { "gvplugin_neato_layout_LTX_library", 0 },
56 { 0, 0 }
57};
58
59/* gvpack:
60 * Input consists of graphs in dot format.
61 * The graphs should have pos, width and height set for nodes,
62 * bb set for clusters, and, optionally, spline info for edges.
63 * The graphs are packed geometrically and combined
64 * into a single output graph, ready to be sent to neato -s -n2.
65 * -m <i> specifies the margin, in points, about each graph.
66 */
67
68typedef struct {
69 char *name;
70 char *value;
71} attr_t;
72
73static int verbose = 0;
74static char **myFiles = 0;
75static FILE *outfp; /* output; stdout by default */
76static std::vector<attr_t> G_args; // Storage for -G arguments
77static bool doPack; /* Do packing if true */
78static char* gname = const_cast<char*>("root");
79
80#define NEWNODE(n) ((node_t*)ND_alg(n))
81
82static const char useString[] =
83 "Usage: gvpack [-gnuv?] [-m<margin>] {-array[_rc][n]] [-o<outf>] <files>\n\
84 -n - use node granularity\n\
85 -g - use graph granularity\n\
86 -array* - pack as array of graphs\n\
87 -G<n>=<v> - attach name/value attribute to output graph\n\
88 -m<n> - set margin to <n> points\n\
89 -s<gname> - use <gname> for name of root graph\n\
90 -o<outfile> - write output to <outfile>\n\
91 -u - no packing; just combine graphs\n\
92 -v - verbose\n\
93 -? - print usage\n\
94If no files are specified, stdin is used\n";
95
96static void usage(int v)
97{
98 std::cout << useString;
100}
101
102/* setNameValue:
103 * If arg is a name-value pair, add it to the list
104 * and return 0; otherwise, return 1.
105 */
106static int setNameValue(char *arg)
107{
108 char *rhs = const_cast<char*>("true");
109
110 if (char *p = strchr(arg, '=')) {
111 *p++ = '\0';
112 rhs = p;
113 }
114 G_args.push_back(attr_t{arg, rhs});
115
116 return 0;
117}
118
119/* setUInt:
120 * If arg is an integer, value is stored in v
121 * and function returns 0; otherwise, returns 1.
122 */
123static int setUInt(unsigned int *v, char *arg)
124{
125 char *p;
126 unsigned int i;
127
128 i = (unsigned int) strtol(arg, &p, 10);
129 if (p == arg) {
130 std::cerr << "Error: bad value in flag -" << (arg - 1) << " - ignored\n";
131 return 1;
132 }
133 *v = i;
134 return 0;
135}
136
137static Agsym_t *agraphattr(Agraph_t *g, char *name, const char *value) {
138 return agattr_text(g, AGRAPH, name, value);
139}
140
141static Agsym_t *agnodeattr(Agraph_t *g, char *name, const char *value) {
142 return agattr_text(g, AGNODE, name, value);
143}
144
145static Agsym_t *agedgeattr(Agraph_t *g, char *name, const char *value) {
146 return agattr_text(g, AGEDGE, name, value);
147}
148
149static void init(int argc, char *argv[], pack_info* pinfo)
150{
151 int c;
152
153 agnodeattr(nullptr, const_cast<char*>("label"), NODENAME_ESC);
154 pinfo->mode = l_clust;
155 pinfo->margin = CL_OFFSET;
156 pinfo->doSplines = true; // Use edges in packing
157 pinfo->fixed = nullptr;
158 pinfo->sz = 0;
159
160 opterr = 0;
161 while ((c = getopt(argc, argv, ":na:gvum:s:o:G:?")) != -1) {
162 switch (c) {
163 case 'a': {
164 auto buf = std::string("a") + optarg + "\n";
165 parsePackModeInfo(buf.c_str(), pinfo->mode, pinfo);
166 break;
167 }
168 case 'n':
169 parsePackModeInfo ("node", pinfo->mode, pinfo);
170 break;
171 case 's':
172 gname = optarg;
173 break;
174 case 'g':
175 parsePackModeInfo ("graph", pinfo->mode, pinfo);
176 break;
177 case 'm':
178 setUInt(&pinfo->margin, optarg);
179 break;
180 case 'o':
181 if (outfp != nullptr)
182 fclose(outfp);
183 outfp = openFile("gvpack", optarg, "w");
184 break;
185 case 'u':
186 pinfo->mode = l_undef;
187 break;
188 case 'G':
189 if (*optarg)
190 setNameValue(optarg);
191 else
192 std::cerr << "gvpack: option -G missing argument - ignored\n";
193 break;
194 case 'v':
195 verbose = 1;
196 Verbose = 1;
197 break;
198 case ':':
199 std::cerr << "gvpack: option -" << (char)optopt
200 << " missing argument - ignored\n";
201 break;
202 case '?':
203 if (optopt == '\0' || optopt == '?')
204 usage(0);
205 else {
206 std::cerr << "gvpack: option -" << (char)optopt << " unrecognized\n";
207 usage(1);
208 }
209 break;
210 }
211 }
212 argv += optind;
213 argc -= optind;
214
215 if (argc > 0) {
216 myFiles = argv;
217 }
218 if (!outfp)
219 outfp = stdout; /* stdout the default */
220 if (verbose)
221 std::cerr << " margin " << pinfo->margin << '\n';
222}
223
224/* init_node_edge:
225 * initialize node and edge attributes
226 */
227static void init_node_edge(Agraph_t * g)
228{
229 node_t *n;
230 edge_t *e;
231 int nG = agnnodes(g);
232 attrsym_t *N_pos = agfindnodeattr(g, const_cast<char*>("pos"));
233 attrsym_t *N_pin = agfindnodeattr(g, const_cast<char*>("pin"));
234
235 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
237 user_pos(N_pos, N_pin, n, nG); /* set user position if given */
238 }
239 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
240 for (e = agfstout(g, n); e; e = agnxtout(g, e))
242 }
243}
244
245/* init_graph:
246 * Initialize attributes. We always do the minimum required by
247 * libcommon. If fill is true, we use init_nop (neato -n) to
248 * read in attributes relevant to the layout.
249 */
250static void init_graph(Agraph_t *g, bool fill, GVC_t *gvc) {
251 int d;
252 node_t *n;
253 edge_t *e;
254
255 aginit (g, AGRAPH, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
256 aginit (g, AGNODE, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
257 aginit (g, AGEDGE, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true);
258 GD_gvc(g) = gvc;
259 graph_init(g, false);
260 d = late_int(g, agfindgraphattr(g, const_cast<char*>("dim")), 2, 2);
261 if (d != 2) {
262 std::cerr << "Error: graph " << agnameof(g) << " has dim = " << d
263 << " (!= 2)\n";
264 graphviz_exit(1);
265 }
266 Ndim = GD_ndim(g) = 2;
268 if (fill) {
269 if (int ret = init_nop(g, 0)) {
270 if (ret < 0)
271 std::cerr << "Error loading layout info from graph " << agnameof(g) << '\n';
272 else if (ret > 0)
273 std::cerr << "gvpack does not support backgrounds as found in graph "
274 << agnameof(g) << '\n';
275 graphviz_exit(1);
276 }
277 if (Concentrate) { /* check for edges without pos info */
278 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
279 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
280 if (ED_spl(e) == nullptr) ED_edge_type(e) = IGNORED;
281 }
282 }
283 }
284 }
285}
286
287/* cloneAttrs:
288 * Copy all attributes from old object to new. Assume
289 * attributes have been initialized.
290 */
291static void cloneDfltAttrs(Agraph_t *old, Agraph_t *new_graph, int attr_kind) {
292 for (Agsym_t *a = agnxtattr(old, attr_kind, 0); a; a = agnxtattr(old, attr_kind, a)) {
293 if (aghtmlstr(a->defval)) {
294 agattr_html(new_graph, attr_kind, a->name, a->defval);
295 } else {
296 agattr_text(new_graph, attr_kind, a->name, a->defval);
297 }
298 }
299}
300static void cloneAttrs(void *old, void *new_graph) {
301 int attr_kind = AGTYPE(old);
302 char* s;
303 Agraph_t *g = agroot(old);
304 Agraph_t *ng = agroot(new_graph);
305
306 for (Agsym_t *a = agnxtattr(g, attr_kind, 0); a; a = agnxtattr(g, attr_kind, a)) {
307 s = agxget (old, a);
308 if (aghtmlstr(s)) {
309 char *scopy = agstrdup_html(ng, s);
310 agset(new_graph, a->name, scopy);
311 agstrfree(ng, scopy, true); // drop the extra reference count we bumped for scopy
312 } else {
313 agset(new_graph, a->name, s);
314 }
315 }
316}
317
318/* cloneEdge:
319 * Note that here, and in cloneNode and cloneCluster,
320 * we do a shallow copy. We thus assume that attributes
321 * are not disturbed. In particular, we assume they are
322 * not deallocated.
323 */
324static void cloneEdge(Agedge_t *old, Agedge_t *new_edge) {
325 cloneAttrs(old, new_edge);
326 ED_spl(new_edge) = ED_spl(old);
327 ED_edge_type(new_edge) = ED_edge_type(old);
328 ED_label(new_edge) = ED_label(old);
329 ED_head_label(new_edge) = ED_head_label(old);
330 ED_tail_label(new_edge) = ED_tail_label(old);
331 ED_xlabel(new_edge) = ED_xlabel(old);
332}
333
334static void cloneNode(Agnode_t *old, Agnode_t *new_node) {
335 cloneAttrs(old, new_node);
336 ND_coord(new_node).x = POINTS(ND_pos(old)[0]);
337 ND_coord(new_node).y = POINTS(ND_pos(old)[1]);
338 ND_height(new_node) = ND_height(old);
339 ND_ht(new_node) = ND_ht(old);
340 ND_width(new_node) = ND_width(old);
341 ND_lw(new_node) = ND_lw(old);
342 ND_rw(new_node) = ND_rw(old);
343 ND_shape(new_node) = ND_shape(old);
344 ND_shape_info(new_node) = ND_shape_info(old);
345 ND_xlabel(new_node) = ND_xlabel(old);
346}
347
348static void cloneCluster(Agraph_t *old, Agraph_t *new_cluster) {
349 // string attributes were cloned as subgraphs
350 GD_label(new_cluster) = GD_label(old);
351 GD_bb(new_cluster) = GD_bb(old);
352}
353
354namespace {
356struct AttributeValue {
357 std::string value;
358 size_t instances;
359};
360} // namespace
361
363using attr_map_t = std::map<std::string, AttributeValue>;
364
365/* fillDict:
366 * Fill newdict with all the name-value attributes of
367 * objp. If the attribute has already been defined and
368 * has a different default, set default to "".
369 */
370static void fillDict(attr_map_t &newdict, Agraph_t *g, int attr_kind) {
371
372 for (Agsym_t *a = agnxtattr(g, attr_kind, 0); a; a = agnxtattr(g, attr_kind, a)) {
373 char *name = a->name;
374 char *value = a->defval;
375 auto it = newdict.find(name);
376 if (it == newdict.end()) {
377 newdict.insert({name, AttributeValue{value, 1}});
378 } else if (it->second.value == value)
379 ++it->second.instances;
380 }
381}
382
383/* fillGraph:
384 * Use all the name-value entries in the dictionary d to define
385 * to define universal node/edge/graph attributes for g.
386 * For a non-empty default value, the attribute must be defined and the
387 * same in all graphs.
388 */
389static void fillGraph(Agraph_t *g, const attr_map_t &d,
390 Agsym_t *(*setf)(Agraph_t *, char *, const char *),
391 size_t cnt) {
392 for (const auto &kv : d) {
393 const std::string &name = kv.first;
394 const std::string &value = kv.second.value;
395 const size_t &attr_cnt = kv.second.instances;
396 if (cnt == attr_cnt)
397 setf(g, const_cast<char *>(name.c_str()), value.c_str());
398 else
399 setf(g, const_cast<char *>(name.c_str()), "");
400 }
401}
402
403/* initAttrs:
404 * Initialize the attributes of root as the union of the
405 * attributes in the graphs gs.
406 */
407static void initAttrs(Agraph_t *root, std::vector<Agraph_t*> &gs) {
408 attr_map_t n_attrs;
409 attr_map_t e_attrs;
410 attr_map_t g_attrs;
411
412 for (Agraph_t *g : gs) {
413 fillDict(g_attrs, g, AGRAPH);
414 fillDict(n_attrs, g, AGNODE);
415 fillDict(e_attrs, g, AGEDGE);
416 }
417
418 fillGraph(root, g_attrs, agraphattr, gs.size());
419 fillGraph(root, n_attrs, agnodeattr, gs.size());
420 fillGraph(root, e_attrs, agedgeattr, gs.size());
421}
422
423static void cloneGraphAttr(Agraph_t * g, Agraph_t * ng)
424{
425 cloneAttrs(g, ng);
426 cloneDfltAttrs(g, ng, AGNODE);
427 cloneDfltAttrs(g, ng, AGEDGE);
428}
429
431using used_t = std::multiset<std::string>;
432
433/* xName:
434 * Create a name for an object in the new graph using the
435 * dictionary names and the old name. If the old name has not
436 * been used, use it and add it to names. If it has been used,
437 * create a new name using the old name and a number.
438 * Note that returned string will immediately made into an agstring.
439 */
440static std::string xName(used_t &names, char *oldname) {
441 size_t previous_instances = names.count(oldname);
442 names.insert(oldname);
443 if (previous_instances > 0) {
444 return std::string(oldname) + "_gv" + std::to_string(previous_instances);
445 }
446 return oldname;
447}
448
449#define MARK(e) (ED_alg(e) = e)
450#define MARKED(e) (ED_alg(e))
451#define SETCLUST(g,h) (GD_alg(g) = h)
452#define GETCLUST(g) ((Agraph_t*)GD_alg(g))
453
454/* cloneSubg:
455 * Create a copy of g in ng, copying attributes, inserting nodes
456 * and adding edges.
457 */
458static void
459cloneSubg(Agraph_t *g, Agraph_t *ng, Agsym_t *G_bb, used_t &gnames) {
460 node_t *n;
461 node_t *nn;
462 edge_t *e;
463 edge_t *ne;
464 node_t *nt;
465 node_t *nh;
466 Agraph_t *subg;
467 Agraph_t *nsubg;
468
469 cloneGraphAttr(g, ng);
470 if (doPack)
471 agxset(ng, G_bb, ""); /* Unset all subgraph bb */
472
473 /* clone subgraphs */
474 for (subg = agfstsubg (g); subg; subg = agnxtsubg (subg)) {
475 nsubg = agsubg(ng, xName(gnames, agnameof(subg)).data(), 1);
476 agbindrec (nsubg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
477 cloneSubg(subg, nsubg, G_bb, gnames);
478 /* if subgraphs are clusters, point to the new
479 * one so we can find it later.
480 */
481 if (is_a_cluster(subg))
482 SETCLUST(subg, nsubg);
483 }
484
485 /* add remaining nodes */
486 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
487 nn = NEWNODE(n);
488 agsubnode(ng, nn, 1);
489 }
490
491 /* add remaining edges. libgraph doesn't provide a way to find
492 * multiedges, so we add edges bottom up, marking edges when added.
493 */
494 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
495 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
496 if (MARKED(e))
497 continue;
498 nt = NEWNODE(agtail(e));
499 nh = NEWNODE(aghead(e));
500 ne = agedge(ng, nt, nh, nullptr, 1);
501 agbindrec (ne, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true);
502 cloneEdge(e, ne);
503 MARK(e);
504 }
505 }
506}
507
508/* cloneClusterTree:
509 * Given old and new subgraphs which are corresponding
510 * clusters, recursively create the subtree of clusters
511 * under ng using the subtree of clusters under g.
512 */
513static void cloneClusterTree(Agraph_t * g, Agraph_t * ng)
514{
515 int i;
516
517 cloneCluster(g, ng);
518
519 if (GD_n_cluster(g)) {
520 GD_n_cluster(ng) = GD_n_cluster(g);
521 void *const p = gv_calloc(1 + GD_n_cluster(g), sizeof(Agraph_t *));
522 GD_clust(ng) = new (p) Agraph_t *[1 + GD_n_cluster(g)]{};
523 for (i = 1; i <= GD_n_cluster(g); i++) {
524 Agraph_t *c = GETCLUST(GD_clust(g)[i]);
525 GD_clust(ng)[i] = c;
526 cloneClusterTree(GD_clust(g)[i], c);
527 }
528 }
529}
530
531/* cloneGraph:
532 * Create and return a new graph which is the logical union
533 * of the graphs gs.
534 */
535static Agraph_t *cloneGraph(std::vector<Agraph_t *> &gs, GVC_t *gvc,
536 Agdesc_t kind) {
537 Agraph_t *root;
538 Agraph_t *subg;
539 Agnode_t *n;
540 Agnode_t *np;
541 bool doWarn = true;
542
543 if (verbose)
544 std::cerr << "Creating clone graph\n";
545 root = agopen(gname, kind, &AgDefaultDisc);
546 initAttrs(root, gs);
547 Agsym_t *const G_bb = agfindgraphattr(root, const_cast<char*>("bb"));
548 if (doPack) assert(G_bb);
549
550 /* add command-line attributes */
551 for (attr_t &a : G_args) {
552 if (Agsym_t *rv = agfindgraphattr(root, a.name))
553 agxset(root, rv, a.value);
554 else
555 agattr_text(root, AGRAPH, a.name, a.value);
556 }
557
558 /* do common initialization. This will handle root's label. */
559 init_graph(root, false, gvc);
561
562 used_t gnames; // dict of used subgraph names
563 used_t nnames; // dict of used node names
564 for (size_t i = 0; i < gs.size(); i++) {
565 Agraph_t *g = gs[i];
566 if (verbose)
567 std::cerr << "Cloning graph " << agnameof(g) << '\n';
568 GD_n_cluster(root) += GD_n_cluster(g);
569 GD_has_labels(root) |= GD_has_labels(g);
570
571 /* Clone nodes, checking for node name conflicts */
572 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
573 if (doWarn && agfindnode(root, agnameof(n))) {
574 std::cerr << "Warning: node " << agnameof(n) << " in graph[" << i << "] "
575 << agnameof(g) << " already defined\n"
576 << "Some nodes will be renamed.\n";
577 doWarn = false;
578 }
579 np = agnode(root, xName(nnames, agnameof(n)).data(), 1);
580 agbindrec (np, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
581 ND_alg(n) = np;
582 cloneNode(n, np);
583 }
584
585 /* wrap the clone of g in a subgraph of root */
586 subg = agsubg(root, xName(gnames, agnameof(g)).data(), 1);
587 agbindrec (subg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
588 cloneSubg(g, subg, G_bb, gnames);
589 }
590
591 /* set up cluster tree */
592 if (GD_n_cluster(root)) {
593 int j, idx;
594 void *const p = gv_calloc(1 + GD_n_cluster(root), sizeof(graph_t *));
595 GD_clust(root) = new (p) graph_t *[1 + GD_n_cluster(root)]{};
596
597 idx = 1;
598 for (Agraph_t *g : gs) {
599 for (j = 1; j <= GD_n_cluster(g); j++) {
600 Agraph_t *c = GETCLUST(GD_clust(g)[j]);
601 GD_clust(root)[idx++] = c;
602 cloneClusterTree(GD_clust(g)[j], c);
603 }
604 }
605 }
606
607 return root;
608}
609
610/* readGraphs:
611 * Read input, parse the graphs, use init_nop (neato -n) to
612 * read in all attributes need for layout.
613 * Return the list of graphs. If cp != nullptr, set it to the number
614 * of graphs read.
615 * We keep track of the types of graphs read. They all must be
616 * either directed or undirected. If all graphs are strict, the
617 * combined graph will be strict; other, the combined graph will
618 * be non-strict.
619 *
620 * @param kind [out] The type to use for the combined graph
621 */
622static std::vector<Agraph_t *> readGraphs(GVC_t *gvc,
623 std::optional<Agdesc_t> &kind) {
624 std::vector<Agraph_t*> gs;
625 ingraph_state ig;
626
627 /* set various state values */
629 Nop = 2;
630
631 newIngraph(&ig, myFiles);
632 while (Agraph_t *g = nextGraph(&ig)) {
633 if (verbose)
634 std::cerr << "Reading graph " << agnameof(g) << '\n';
635 if (agnnodes(g) == 0) {
636 std::cerr << "Graph " << agnameof(g) << " is empty - ignoring\n";
637 continue;
638 }
639 if (!kind.has_value()) {
640 kind = g->desc;
641 }
642 else if (kind->directed != g->desc.directed) {
643 std::cerr << "Error: all graphs must be directed or undirected\n";
644 graphviz_exit(1);
645 } else if (!agisstrict(g))
646 kind = g->desc;
647 init_graph(g, doPack, gvc);
648 gs.push_back(g);
649 }
650
651 return gs;
652}
653
654/* compBB:
655 * Compute the bounding box containing the graphs.
656 * We can just use the bounding boxes of the graphs.
657 */
658static boxf compBB(std::vector<Agraph_t*> &gs) {
659 boxf bb, bb2;
660
661 bb = GD_bb(gs[0]);
662
663 for (size_t i = 1; i < gs.size(); i++) {
664 bb2 = GD_bb(gs[i]);
665 bb.LL.x = std::min(bb.LL.x, bb2.LL.x);
666 bb.LL.y = std::min(bb.LL.y, bb2.LL.y);
667 bb.UR.x = std::max(bb.UR.x, bb2.UR.x);
668 bb.UR.y = std::max(bb.UR.y, bb2.UR.y);
669 }
670
671 return bb;
672}
673
674#ifdef DEBUG
675void dump(Agraph_t * g)
676{
677 node_t *v;
678 edge_t *e;
679
680 for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
681 std::cerr << agnameof(v) << '\n';
682 for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
683 std::cerr << " " << agnameof(agtail(e)) << " -- " << agnameof(aghead(e))
684 << '\n';
685 }
686 }
687}
688
689void dumps(Agraph_t * g)
690{
691 graph_t *subg;
692
693 for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) {
694 dump(subg);
695 std::cerr << "====\n";
696 }
697}
698#endif
699
700int main(int argc, char *argv[])
701{
702 Agraph_t *g;
703 pack_info pinfo;
704 GVC_t * gvc;
705
706 init(argc, argv, &pinfo);
707
708 doPack = (pinfo.mode != l_undef);
709
711 gvc = gvContextPlugins(lt_preloaded_symbols, DEMAND_LOADING);
712 std::optional<Agdesc_t> kind; // type of graph
713 std::vector<Agraph_t*> gs = readGraphs(gvc, kind);
714 if (gs.empty())
715 graphviz_exit(0);
716
717 /* pack graphs */
718 if (doPack) {
719 if (packGraphs(gs.size(), gs.data(), 0, &pinfo)) {
720 std::cerr << "gvpack: packing of graphs failed.\n";
721 graphviz_exit(1);
722 }
723 }
724
725 /* create union graph and copy attributes */
726 assert(kind.has_value());
727 g = cloneGraph(gs, gvc, *kind);
728
729 /* compute new top-level bb and set */
730 if (doPack) {
731 GD_bb(g) = compBB(gs);
733 attach_attrs(g);
734 }
735 agwrite(g, outfp);
736 graphviz_exit(0);
737}
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:39
void common_init_edge(edge_t *e)
Definition utils.c:509
bool is_a_cluster(Agraph_t *g)
Definition utils.c:695
#define CL_OFFSET
Definition const.h:142
#define NODENAME_ESC
Definition const.h:80
#define IGNORED
Definition const.h:30
#define GVSPLINES
Definition const.h:164
#define agnodeattr(g, n, v)
Definition dotinit.c:276
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
#define POINTS(a_inches)
Definition geom.h:62
#define POINTS_PER_INCH
Definition geom.h:58
int State
Definition globals.h:63
bool Concentrate
Definition globals.h:59
int Nop
Definition globals.h:55
double PSinputscale
Definition globals.h:56
unsigned short Ndim
Definition globals.h:62
static bool Verbose
Definition gml2gv.c:26
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:198
int agnnodes(Agraph_t *g)
Definition graph.c:157
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Definition attr.c:336
int agset(void *obj, char *name, const char *value)
Definition attr.c:477
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:365
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:524
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:460
Agsym_t * agattr_html(Agraph_t *g, int kind, char *name, const char *value)
agattr_text, but creates HTML-like values
Definition attr.c:340
Agdisc_t AgDefaultDisc
Definition graph.c:277
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:255
#define ED_xlabel(e)
Definition types.h:590
#define ED_head_label(e)
Definition types.h:587
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:28
#define ED_spl(e)
Definition types.h:595
#define agtail(e)
Definition cgraph.h:977
#define ED_edge_type(e)
Definition types.h:582
#define ED_tail_label(e)
Definition types.h:596
#define aghead(e)
Definition cgraph.h:978
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:43
#define ED_label(e)
Definition types.h:589
#define agfindgraphattr(g, a)
Definition types.h:613
#define GD_has_labels(g)
Definition types.h:368
#define GD_clust(g)
Definition types.h:360
int agisstrict(Agraph_t *g)
Definition graph.c:188
#define GD_bb(g)
Definition types.h:354
#define GD_n_cluster(g)
Definition types.h:389
Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
creates a new graph with the given name and kind
Definition graph.c:44
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:669
#define GD_ndim(g)
Definition types.h:390
#define GD_label(g)
Definition types.h:374
#define GD_gvc(g)
Definition types.h:355
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition node.c:143
#define ND_ht(n)
Definition types.h:500
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:50
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
Agnode_t * agsubnode(Agraph_t *g, Agnode_t *n, int createflag)
Definition node.c:254
#define agfindnodeattr(g, a)
Definition types.h:615
#define ND_alg(n)
Definition types.h:484
#define ND_rw(n)
Definition types.h:525
#define ND_height(n)
Definition types.h:498
#define ND_width(n)
Definition types.h:536
#define ND_lw(n)
Definition types.h:506
#define ND_xlabel(n)
Definition types.h:503
#define ND_shape_info(n)
Definition types.h:529
#define ND_pos(n)
Definition types.h:520
#define agfindnode(g, n)
Definition types.h:611
#define ND_coord(n)
Definition types.h:490
#define ND_shape(n)
Definition types.h:528
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:145
#define AGTYPE(obj)
returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
Definition cgraph.h:216
Agraph_t * agroot(void *obj)
Definition obj.c:170
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
void aginit(Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
attach new records to objects of specified kind
Definition rec.c:172
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
Definition rec.c:91
int aghtmlstr(const char *)
Definition refstr.c:440
int agstrfree(Agraph_t *, const char *, bool is_html)
Definition refstr.c:417
char * agstrdup_html(Agraph_t *, const char *)
returns a pointer to a reference-counted HTML-like copy of the argument string, creating one if neces...
Definition refstr.c:397
Agraph_t * agfstsubg(Agraph_t *g)
Definition subg.c:75
Agraph_t * agnxtsubg(Agraph_t *subg)
Definition subg.c:80
Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
Definition subg.c:55
GVC_t * gvContextPlugins(const lt_symlist_t *builtins, int demand_loading)
Definition gvc.c:35
void attach_attrs(graph_t *g)
Definition output.c:416
static GVC_t * gvc
Definition gv.cpp:27
#define agraphattr(g, n, s)
Definition gv.cpp:23
Graphviz context library.
static int verbose
Definition gvpack.cpp:73
static void cloneClusterTree(Agraph_t *g, Agraph_t *ng)
Definition gvpack.cpp:513
#define MARK(e)
Definition gvpack.cpp:449
static void cloneCluster(Agraph_t *old, Agraph_t *new_cluster)
Definition gvpack.cpp:348
static void cloneDfltAttrs(Agraph_t *old, Agraph_t *new_graph, int attr_kind)
Definition gvpack.cpp:291
static Agraph_t * cloneGraph(std::vector< Agraph_t * > &gs, GVC_t *gvc, Agdesc_t kind)
Definition gvpack.cpp:535
std::multiset< std::string > used_t
names that have already been used during generation
Definition gvpack.cpp:431
static void init_node_edge(Agraph_t *g)
Definition gvpack.cpp:227
lt_symlist_t lt_preloaded_symbols[]
Definition gvpack.cpp:54
static std::vector< attr_t > G_args
Definition gvpack.cpp:76
static char * gname
Definition gvpack.cpp:78
static int setNameValue(char *arg)
Definition gvpack.cpp:106
static void init_graph(Agraph_t *g, bool fill, GVC_t *gvc)
Definition gvpack.cpp:250
#define NEWNODE(n)
Definition gvpack.cpp:80
static void cloneSubg(Agraph_t *g, Agraph_t *ng, Agsym_t *G_bb, used_t &gnames)
Definition gvpack.cpp:459
#define MARKED(e)
Definition gvpack.cpp:450
static void cloneNode(Agnode_t *old, Agnode_t *new_node)
Definition gvpack.cpp:334
static FILE * outfp
Definition gvpack.cpp:75
static boxf compBB(std::vector< Agraph_t * > &gs)
Definition gvpack.cpp:658
static bool doPack
Definition gvpack.cpp:77
static void fillDict(attr_map_t &newdict, Agraph_t *g, int attr_kind)
Definition gvpack.cpp:370
static std::string xName(used_t &names, char *oldname)
Definition gvpack.cpp:440
static void cloneEdge(Agedge_t *old, Agedge_t *new_edge)
Definition gvpack.cpp:324
static void fillGraph(Agraph_t *g, const attr_map_t &d, Agsym_t *(*setf)(Agraph_t *, char *, const char *), size_t cnt)
Definition gvpack.cpp:389
#define SETCLUST(g, h)
Definition gvpack.cpp:451
static int setUInt(unsigned int *v, char *arg)
Definition gvpack.cpp:123
static const char useString[]
Definition gvpack.cpp:82
static void cloneGraphAttr(Agraph_t *g, Agraph_t *ng)
Definition gvpack.cpp:423
static void initAttrs(Agraph_t *root, std::vector< Agraph_t * > &gs)
Definition gvpack.cpp:407
static void cloneAttrs(void *old, void *new_graph)
Definition gvpack.cpp:300
static std::vector< Agraph_t * > readGraphs(GVC_t *gvc, std::optional< Agdesc_t > &kind)
Definition gvpack.cpp:622
static void init(int argc, char *argv[], pack_info *pinfo)
Definition gvpack.cpp:149
static char ** myFiles
Definition gvpack.cpp:74
std::map< std::string, AttributeValue > attr_map_t
attribute name → value collection of those we have seen
Definition gvpack.cpp:363
gvplugin_library_t gvplugin_neato_layout_LTX_library
static Agsym_t * agedgeattr(Agraph_t *g, char *name, const char *value)
Definition gvpack.cpp:145
#define GETCLUST(g)
Definition gvpack.cpp:452
static const char * usage
Definition gvpr.c:54
Agraph_t * nextGraph(ingraph_state *sp)
Definition ingraphs.c:61
ingraph_state * newIngraph(ingraph_state *sp, char **files)
Definition ingraphs.c:140
supports user-supplied data
void graph_init(graph_t *g, bool use_rankdir)
Definition input.c:599
bool user_pos(attrsym_t *posptr, attrsym_t *pinptr, node_t *np, int nG)
Definition neatoinit.c:74
int init_nop(Agraph_t *g, int adjust)
Definition neatoinit.c:512
static attrsym_t * N_pos
Definition neatoinit.c:53
void neato_init_node(node_t *n)
Definition neatoinit.c:59
static FILE * openFile(const char *argv0, const char *name, const char *mode)
Definition openFile.h:8
pack_mode parsePackModeInfo(const char *p, pack_mode dflt, pack_info *pinfo)
Definition pack.c:1211
int packGraphs(size_t ng, Agraph_t **gs, Agraph_t *root, pack_info *info)
Definition pack.c:1092
support for connected components
@ l_clust
Definition pack.h:55
@ l_undef
Definition pack.h:55
void dotneato_postprocess(Agraph_t *g)
Definition postproc.c:691
graph descriptor
Definition cgraph.h:284
unsigned directed
Definition cgraph.h:285
graph or subgraph
Definition cgraph.h:424
Agdesc_t desc
Definition cgraph.h:426
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:640
Definition gvcint.h:81
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
void * address
Definition gvcext.h:41
pack_mode mode
Definition pack.h:72
int sz
Definition pack.h:69
bool doSplines
use splines in constructing graph shape
Definition pack.h:71
bool * fixed
Definition pack.h:73
unsigned int margin
Definition pack.h:70
double x
Definition geom.h:29
double y
Definition geom.h:29
int main()
Definition grammar.c:90