/usr/bin/codechanges is in pmccabe 2.6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | #!/bin/sh -f
# $Header: /gjd/tools/pmccabe/codechanges 1.12 2001/10/25 23:51:46 bame Exp $
# Find a "good", e.g., "new" (circa 1988?), awk
goodawk()
{
for AWK in gawk nawk awk
do
$AWK -v foo=bar 'function f() { print 1 }' >/dev/null 2>&1 && return
done
echo "I can't find a new enough 'awk' (tried gawk, nawk and awk) in" >&2
echo "your \$PATH to run this program -- sorry." >&2
exit 5
}
FIND()
{
(
cd $1 &&
find . -type f -a \
\( \
-name *.[cC] \
-o -name *.[hH] \
-o -name *.*sh \
-o -name *.mak \
-o -name *akefile \
-o -name *.cpp \
-o -name *.cxx \
-o -name *.C \
-o -name *.cc \
-o -name *.hh \
\) -print | sort
)
}
parsediff()
{
$AWK -v dir1="$1" -v dir2="$2" '
# Skip noise lines
BEGIN {
printf("%s\t%s\t%s\tOld File, New File\n", "NEW", "DELETED", "CHANGED");
}
(/^>/) { next }
(/^</) { next }
($1 == "---") { next }
function wc(fname, nlines) {
nlines = 0;
while (getline < fname > 0)
{
nlines++
}
return nlines
}
($1 == "Add") {
#print "DEBUG: adding", lines, "lines from", fname
eof()
file1 = "NEWFILE"
file2 = $2
addtotal += $3;
eof()
next
}
($1 == "Delete") {
#print "DEBUG: deleting", lines, "lines from", fname
eof()
file2 = "DELETED"
file1 = $2
deltotal += $3;
eof()
next
}
function eof() {
if (file1 != "" && (addtotal > 0 || deltotal > 0 || chgtotal > 0))
{
printf("%d\t%d\t%d\t%s %s\n",
addtotal, deltotal, chgtotal, file1, file2);
taddtotal += addtotal;
tdeltotal += deltotal;
tchgtotal += chgtotal;
}
file1 = ""
addtotal = 0;
deltotal = 0;
chgtotal = 0;
}
($1 == "diff") {
#print "DEBUG: ", $0
eof();
file1 = $(NF - 1)
file2 = $(NF)
next
}
(/c/) {
n=split($0,tmparray,"c");
# do left side of c and then right
leftchg = parse(tmparray[1]) + 0;
rightchg = parse(tmparray[n])+ 0;
if(leftchg == rightchg) {
change = leftchg;
}
# assume that smaller side is change and the difference is add or delete
else if(leftchg > rightchg) {
#print "DEBUG=", leftchg, rightchg
change = rightchg ;
deltotal += (leftchg - rightchg)
#print "deleted via change " leftchg - rightchg
}
else if(leftchg < rightchg) {
change = leftchg
addtotal += (rightchg-leftchg)
#print "DEBUG<", leftchg, rightchg
#print "added via change " rightchg - leftchg
};
# print "change ", change, "left changed ", \
#leftchg , "right changed ", rightchg, "INPUT= ", m, $0;
chgtotal += change;
next
}
# parse if comma separated or return value if no comma
function parse(str, localval, localarray,localcount) {
localcount=split(str, localarray, ",")
if(localcount == 1)
localval = 1;
else
localval = (localarray[localcount]+0 - \
localarray[localcount-1] +1)
#print "DEBUG return value", localval, str
return(localval);
}
(/d/) {
n=split($0,tmparray,"d");
#uses line range before the d
deleted = parse(tmparray[1]);
deltotal += deleted;
#print "deleted " deleted, "DEBUG", $0;
next
}
(/a/) {
# print "DEBUG:", file1, file2, $0
n=split($0,tmparray,"a");
# uses line range after the a
added = parse(tmparray[n]);
addtotal += added;
#print "added ", added , "DEBUG", m, $0;
next
}
{ print "?????????", $0 }
END {
eof();
printf("%d\t%d\t%d\tTOTAL\n",
taddtotal, tdeltotal, tchgtotal);
}
'
}
# Need to pick up 'decomment'
PATH=$PATH:$(dirname $0)
goodawk
if [ X$1 = X-n ]
then
DECOMMENT=cat
shift 1
else
DECOMMENT=decomment
fi
if [ $# != 2 ]
then
cat >&2 <<!!!
\$Header: /gjd/tools/pmccabe/codechanges 1.12 2001/10/25 23:51:46 bame Exp $
Usage: $0 [-n] old-directory new-directory
$0 [-n] old-file new-file
-n don't bother to de-comment the files first
BUG: doesn't handle re-named files/directories
!!!
exit 2
fi
TMPDIR=$(mktemp -d)
#TMPDIR=/tmp/ddiff
mkdir -p $TMPDIR
if [ -f $1 -o -f $2 ]
then
{
echo "diff $1 $2"
$DECOMMENT $1 > $TMPDIR/A
$DECOMMENT $2 > $TMPDIR/B
$DECOMMENT $dir2/$fname | diff -bw -- $TMPDIR/A $TMPDIR/B
} | parsediff
rm -fr $TMPDIR
exit
fi
dir1=$1
dir2=$2
printf '%s' "$dir1 ..." >&2
FIND $dir1 > $TMPDIR/A
printf '\n%s' "$dir2 ..." >&2
FIND $dir2 > $TMPDIR/B
echo >&2
comm $TMPDIR/A $TMPDIR/B |
while IFS="" read f
do
set -- $f
fname=$1
case $f in
" "*)
echo "diff $dir1/$fname $dir2/$fname"
$DECOMMENT $dir1/$fname > $TMPDIR/C
$DECOMMENT $dir2/$fname | diff -bw -- $TMPDIR/C -
;;
" "*)
lines=$($DECOMMENT $dir2/$fname | wc -l)
echo "Add $dir2/$fname $lines"
;;
*)
lines=$($DECOMMENT $dir1/$fname | wc -l)
echo "Delete $dir1/$fname $lines"
;;
esac
done |
tee $TMPDIR/D |
parsediff $dir1 $dir2
rm -fr $TMPDIR
|