根据@marapet的回答,我编写了一个脚本,并认为其他人也可以受益于拥有副本。 它还在Snap!C ++中作为clean-dependencies.gvpr
。
# Run with:
#
# /usr/bin/gvpr -o clean-dependencies.dot -f clean-dependencies.gvpr dependencies.dot
#
# Clean up the dependencies.svg from double dependencies
# In other words if A depends on B and C, and B also depends on C, we
# can remove the link between A amd C, it's not necessary in our file.
BEG_G {
edge_t direct_edges[int];
node_t children[int];
node_t n = fstnode($G);
while(n != NULL) {
// 1. extract the current node direct children
//
int direct_pos = 0;
edge_t e = fstout_sg($G, n);
while(e != NULL) {
direct_edges[direct_pos] = e;
children[direct_pos] = opp(e, n);
direct_pos = direct_pos + 1;
e = nxtout_sg($G, e);
}
// 2. find all of the grand children
// and see whether some are duplicates, if so delete the
// original (direct) edge
//
int child_pos = direct_pos;
int c = 0;
for(c = 0; c < child_pos; ++c) {
e = fstout_sg($G, children[c]);
while(e != NULL) {
node_t o = opp(e, children[c]);
int idx;
for(idx = 0; idx < direct_pos; ++idx) {
if(children[idx] == o) {
if(direct_edges[idx] != NULL) {
delete($G, direct_edges[idx]);
direct_edges[idx] = NULL;
}
break;
}
}
e = nxtout_sg($G, e);
}
}
n = nxtnode_sg($G, n);
}
}
END_G {
$O = $G;
}
我想提到几点:gvpr函数似乎不能接受数组作为输入。此外,我最初尝试使用递归方法,但局部变量会被进一步的调用破坏(即在递归调用返回时,变量的值是来自子调用的值...所以变量是一个函数的“本地”的,但仍然只有一个实例,没有堆栈!)
希望以后的版本能解决这些问题。
$ gvpr -V
gvpr version 2.38.0 (20140413.2041)
相比尝试在CMake中解决我的图形问题,这已经是一种更简单的方法。
![enter image description here](https://istack.dev59.com/F01j6.webp)
更新
我最终编写了一个Python脚本来完成这项工作。可以很容易地从定义为Makefile的树中删除重复项。但是,读取.dot数据并进行修复要困难得多。然而,在我的情况下,我可以访问该数据,您可能没有这个权限。