]> matita.cs.unibo.it Git - helm.git/blob - components/STATS/patch_deps.sh
tagged 0.5.0-rc1
[helm.git] / components / STATS / patch_deps.sh
1 #!/bin/sh
2 # script args: source_file target_file
3
4 use_clusters='no'
5 if [ ! -z "$USE_CLUSTERS" ]; then
6   use_clusters=$USE_CLUSTERS
7 fi
8
9 # args: file snippet
10 # file will be modified in place
11 include_dot_snippet ()
12 {
13   echo "Adding to $1 graphviz snippet $2 ..."
14   sed -i "/digraph/r $2" $1
15 }
16
17 # args: stats file
18 # file will be modified in place
19 include_loc_stats ()
20 {
21   echo "Adding to $1 KLOCs stats from $2 ..."
22   tmp=`mktemp tmp.stats.XXXXXX`
23   for l in `cat $2`; do
24     module=$(basename $(echo $l | cut -d : -f 1))
25     stat=$(echo $l | cut -d : -f 2)
26     if [ "$stat" = "LOC" ]; then
27       locs=$(echo $l | cut -d : -f 3)
28       klocs=$(echo "scale=1; $locs / 1000" | bc)
29       if [ "$klocs" = "0" ]; then klocs=".1"; fi
30       printf '  %s [label="%s\\n%s klocs"];\n' $module $module $klocs >> $tmp
31     fi
32   done
33   include_dot_snippet $1 $tmp
34   rm $tmp
35 }
36
37 # args: file patch
38 apply_patch ()
39 {
40   if [ -f "$2" ]; then
41     echo "Applying to $1 patch $2 ..."
42     patch $1 $2
43   fi
44 }
45
46 cp $1 $2
47 include_loc_stats $2 .stats
48 apply_patch $2 STATS/deps.patch
49 include_dot_snippet $2 STATS/daemons.dot
50 if [ "$use_clusters" = "yes" ]; then
51   include_dot_snippet $2 STATS/clusters.dot
52 fi
53