C-Module dependency graph


I wrote a script to create a module dependency graph from a set of files using graphviz. This script works only for C.

1. Result


The graph shows how the modules are dependent.



2. Script


You need to change the project path to run the script.

#!/bin/bash
# Author: Andreas Tobola
# http://www.tnotes.de/CDependencyGraph
FILE_OUT="rat2src.dot"
echo "digraph G {" > $FILE_OUT
echo "rankdir=LR;" >> $FILE_OUT
echo "fontsize=24;" >> $FILE_OUT
for mfile in `ls ./rat2src`
do
  module=`echo $mfile | sed 's/[.]/ /' | awk '{print $1}'`
  echo $module" ("$mfile")"
  modlist=`cat ./rat2src/$mfile | grep -v '<' |  grep '#include'| awk '{print $2}'  | sed 's/<//g'  | sed 's/>//g' | sed 's/[.]/ /g' | sed 's/"//g' | awk '{print $1}' | grep -v $module`
  for link in $modlist
  do
     echo "   "$link
     echo "\""$module"\" -> \""$link"\"" >> $FILE_OUT
  done
done
echo "}" >> $FILE_OUT
echo "graphviz..."
dot -Tpng $FILE_OUT  -o rat2moddep.png



Siehe auch
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki