-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdiff
executable file
·97 lines (82 loc) · 2.06 KB
/
pdiff
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/ksh
echo "@(#) $Id: pdiff,v 1.2 1998/07/21 18:53:59 bame Exp $" >&2
cycocvt()
{
awk 'BEGIN {OFS="\t"}{print $8 "/" $9, $1, $2, $3, $7}'
}
case $# in
2) olddir=$1; newdir=$2; usefind=true;;
4) olddir=$1; oldlist=$2; newdir=$3; newlist=$4; usefind=false;;
*)
echo "Usage: $0 old-code-directory new-code-directory" >&2
echo "Usage: $0 old-code-directory old-files-list new-code-directory new-files-list" >&2
exit 2
;;
esac
pmccabe -V >&2
printf 'Analyzing %s ...' "$olddir" >&2
if $usefind
then
(cd $olddir && find . -type f -name '*.[cChH]*' -print | xargs pmccabe -C)
else
(cd $olddir && cat $oldlist | xargs pmccabe -C)
fi | cycocvt | sort >old.1
printf "\nAnalyzing %s ..." "$newdir" >&2
if $usefind
then
(cd $newdir && find . -type f -name '*.[cChH]*' -print | xargs pmccabe -C)
else
(cd $newdir && cat $newlist | xargs pmccabe -C)
fi | cycocvt | sort >new.1
echo >&2
echo >&2
{
echo "@@@@@ common"
join old.1 new.1
echo "@@@@@ old"
join -v 1 old.1 new.1
echo "@@@@@ new"
join -v 2 old.1 new.1
} | awk '
BEGIN {
OFS = "\t"
print "", "Modified McCabe Cyclomatic Complexity"
print "", "| Traditional McCabe Cyclomatic Complexity"
print "", "| | # Statements in function"
print "", "| | | # lines in function"
print "", "+-------+--------+------+---------------file name/function name"
}
($1 == "@@@@@") { file = $2; next }
(file == "common") {
print "", total($6 - $2, $7 - $3, $8 - $4, $9 - $5), $1
}
(file == "old") {
print "Deleted", total(-$2, -$3, -$4, -$5), $1
}
(file == "new") {
print "New", total($2, $3, $4, $5), $1
}
function total(m1, m2, statements, lines, s)
{
tm1 += m1
tm2 += m2
tstatements += statements
tlines += lines
if (m1 > 0)
s = s "+";
s = s m1 "\t";
if (m2 > 0)
s = s "+";
s = s m2 "\t";
if (statements > 0)
s = s "+";
s = s statements "\t";
if (lines > 0)
s = s "+";
s = s lines "\t";
return s
}
END {
print "-----", total(tm1, tm2, tstatements, tlines), "Total"
}
'