[go: up one dir, main page]

Menu

[9202b6]: / scripts / graph.sh  Maximize  Restore  History

Download this file

35 lines (27 with data), 818 Bytes

 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
#!/bin/bash
# Create a header dependency graph from the source files in a directory.
# Output is in the DOT language. The 'dot' application is part of
# graphviz <http://www.graphviz.org>
#
# Usage: graph.sh DIRECTORY [VIEWER]
#
# Serving suggestion:
# graph.sh world | dot -Tps -o /tmp/graph.ps && evince /tmp/graph.ps
if [ "$#" == "2" ]; then
$0 $1 | dot -Tps -o /tmp/graph.ps && $2 /tmp/graph.ps
exit 1
fi
if [ "$#" != "1" ]; then
echo "Usage: graph.sh DIRECTORY [VIEWER]"
exit 1
fi
cd $1
echo "digraph $(basename $PWD) {"
# Find and format the header dependencies
grep "#include.*\.h\"" *.cc *.h |\
sed 's!\(.*\)\.[cch]\+:#include "\(.*\)\.[cch]\+"!"\1" -> "\2";!' |\
grep -v "^\(.*\) -> \1" |\
grep -v "test_"
# Make sure independent headers are shown.
ls -1 *.h | sed 's/\.h$//'
echo "}"