Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
neatopack.c
Go to the documentation of this file.
1
4
5/*************************************************************************
6 * Copyright (c) 2011 AT&T Intellectual Property
7 * All rights reserved. This program and the accompanying materials
8 * are made available under the terms of the Eclipse Public License v1.0
9 * which accompanies this distribution, and is available at
10 * https://www.eclipse.org/legal/epl-v10.html
11 *
12 * Contributors: Details at https://graphviz.org
13 *************************************************************************/
14
15#include <graphviz/cgraph.h>
16#include <graphviz/gvc.h>
17#include <graphviz/pack.h>
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdio.h>
21#include <stdlib.h>
22
23int main(int argc, char *argv[]) {
24 GVC_t *gvc = gvContext();
25
26 FILE *fp;
27 if (argc > 1)
28 fp = fopen(argv[1], "r");
29 else
30 fp = stdin;
31 graph_t *g = agread(fp, NULL);
32
33 aginit(g, AGRAPH, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
34 aginit(g, AGNODE, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
35
36 size_t ncc;
37 graph_t **cc = ccomps(g, &ncc, NULL);
38
39 for (size_t i = 0; i < ncc; i++) {
40 graph_t *sg = cc[i];
41 (void)graphviz_node_induce(sg, NULL);
42 gvLayout(gvc, sg, "neato");
43 }
44 pack_graph(ncc, cc, g, 0);
45
46 gvRender(gvc, g, "ps", stdout);
47
48 for (size_t i = 0; i < ncc; i++) {
49 graph_t *sg = cc[i];
50 gvFreeLayout(gvc, sg);
51 agdelete(g, sg);
52 }
53 free(cc);
54
55 agclose(g);
56
57 return gvFreeContext(gvc);
58}
void free(void *)
node NULL
Definition grammar.y:149
size_t graphviz_node_induce(Agraph_t *g, Agraph_t *edgeset)
Definition node_induce.c:9
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:96
Agraph_t * agread(void *chan, Agdisc_t *disc)
constructs a new graph
Definition grammar.c:2274
int agdelete(Agraph_t *g, void *obj)
deletes object. Equivalent to agclose, agdelnode, and agdeledge for obj being a graph,...
Definition obj.c:19
@ 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:169
int gvFreeLayout(GVC_t *gvc, graph_t *g)
Definition gvlayout.c:105
int gvLayout(GVC_t *gvc, graph_t *g, const char *engine)
Definition gvc.c:52
GVC_t * gvContext(void)
Definition gvc.c:24
int gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out)
Definition gvc.c:84
int gvFreeContext(GVC_t *gvc)
Definition gvcontext.c:64
GVC_t * gvc
Definition htmlparse.c:99
Agraph_t ** ccomps(Agraph_t *g, size_t *ncc, char *pfx)
Definition ccomps.c:205
int pack_graph(size_t ng, Agraph_t **gs, Agraph_t *root, bool *fixed)
Pack subgraphs followed by postprocessing.
Definition pack.c:1093
graph or subgraph
Definition cgraph.h:425
Definition gvcint.h:80
int main()