Debian Codegraph @

cmd/gvpr/lib/group

raw
1 /* Collapse all nodes with group = X into a single node */
2 BEG_G {
3 node_t metaN;
4 graph_t g = graph ("metagraph", "S");
5 $tvtype = TV_ne;
6 $O = g;
7 }
8
9 /* create only one node with given name/value */
10 N[group == "X"] {
11 if (!metaN) {
12 metaN = node (g, $.name);
13 }
14 }
15
16 /* duplicate all others */
17 N[group != "X"] { node (g, $.name); }
18
19 /* Create an edge only if at least one of the nodes
20 * is not a collapsed node */
21 E {
22 node_t t;
23 node_t h;
24 if ($.tail.group == "X") {
25 if ($.head.group == "X") return;
26 t = metaN;
27 h = node (g, $.head.name);
28 }
29 else if ($.head.group == "X") {
30 t = node (g, $.tail.name);
31 h = metaN;
32 }
33 else {
34 t = node (g, $.tail.name);
35 h = node (g, $.head.name);
36 }
37 edge (t, h, "");
38 }
39
40 /* set g to be output graph */