File: pdiff

package info (click to toggle)
pmccabe 2.8-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 876 kB
  • sloc: ansic: 3,084; cpp: 1,080; sh: 401; makefile: 42
file content (122 lines) | stat: -rwxr-xr-x 2,210 bytes parent folder | download | duplicates (2)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh

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

cycocvt()
{
    local line

    while read line
    do
	set -- $line
	printf "%s/%s\t%s\t%s\t%s\t%s\n" $8, $9, $1, $2, $3, $7
    done
}

find_sources()
{
    find . -type f -print |
        grep			\
	    -e '\.[cChH]$'	\
	    -e '\.cpp$' 	\
	    -e '\.cxx$' 	\
	    -e '\.c++$' 	\
	    -e '\.cc$'
}

trap "rm -f old.1 new.1" 0 1 2 3 15

printf 'Analyzing %s ...' "$olddir" >&2

(
    cd $olddir

    if $usefind
    then
	find_sources
    else
	cat $oldlist
    fi | xargs pmccabe -C
) | cycocvt | sort >old.1

printf "\nAnalyzing %s ..." "$newdir" >&2

(
    cd $newdir

    if $usefind
    then
	find_sources
    else
	cat $oldlist
    fi | xargs pmccabe -C
) | 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"
    }
'