forked from marckhoury/mars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.c
48 lines (41 loc) · 1.1 KB
/
graph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
*
* Author: Marc Khoury <[email protected]>
*
* Copyright (C) 2014 Marc Khoury
*
* This version is released under the Eclipse Public License
* with the Graphviz distribution.
*
* A version is also available on GitHub: https://github.com/marckhoury/mars
* If you make improvements or bug fixes to this code it would be much
* appreciated if you could also contribute those changes back to the
* GitHub repository.
*/
#include "graph.h"
static Agnode_t** nodes;
void init_graph(Agraph_t* g)
{
int i = 0;
Agnode_t* n;
weight = agattr(g, AGEDGE, "weight", "1.0");
pos = agattr(g, AGNODE, "pos", "");
color = agattr(g, AGNODE, "color", "black");
comment = agattr(g, AGRAPH, "cmd", "");
nodes = (Agnode_t**) malloc(sizeof(Agnode_t*)*agnnodes(g));
for(n = agfstnode(g); n; n = agnxtnode(g,n)) {
agbindrec(n, (char*)"nodedata", sizeof(nodedata_t),1);
setid(n,i);
nodes[i] = n;
i++;
}
}
Agnode_t* get_node(int id)
{
return nodes[id];
}
void clean_up(Agraph_t* g)
{
agclean(g, AGNODE, "nodedata");
free(nodes);
}