#!/bin/sh # # COUNT_CHANGE_REPORT.sh # # count the number of lines changed in a file # $1..$n are the names of files and directories to count # Directories are recursed into. Modified from origional # PureAtria version to account for printing of empty files and # allow for filtering of source file types. The report # prints lines of code changed for each file within the # past week, month, quarter, half-year and year. # # NOTE: This works for ClearCase version 2.x or better. # # Author: Charles W. Clarke III (ABS) # email: charles@abs-consulting.com # URL: http://www.abs-consulting.com # Date: Aug. 16, 1996 ############################################################ # History: 08/16/96 : Created for A Better Solution, Inc. ############################################################ make6wide() { echo $1 | sed -e "s/^\(.\)$/#####\1/" \ -e "s/^\(..\)$/####\1/" \ -e "s/^\(...\)$/###\1/" \ -e "s/^\(....\)$/##\1/" \ -e "s/^\(.....\)$/#\1/" } if [ $# = 0 ] then SEARCH_POINT="`pwd`" else if [ "$*" = "." ] then SEARCH_POINT="`pwd`" else SEARCH_POINT="$*" fi fi SORTED_PNS=/tmp/sorted_pns.$$ PNS=/tmp/count_pns.$$ ANN=/tmp/ann.$$ GRAND=/tmp/grand.$$ rm -f $PNS $ANN $GRAND $SORTED_PNS trap '/bin/rm -f $PNS $ANN $GRAND; exit 1' 1 2 3 9 15 # Make a list of files you want cleartool find $SEARCH_POINT -name "*.c" -nxname -type f -print >> $PNS cleartool find $SEARCH_POINT -name "*.h" -nxname -type f -print >> $PNS cleartool find $SEARCH_POINT -name "*.sh" -nxname -type f -print >> $PNS cleartool find $SEARCH_POINT -name "*.csh" -nxname -type f -print >> $PNS cleartool find $SEARCH_POINT -name "*.ksh" -nxname -type f -print >> $PNS sort $PNS > $SORTED_PNS # Setup report header grand_total=0 grand_week=0 grand_month=0 grand_quarter=0 grand_half_year=0 grand_year=0 NUMFILES=`wc -l <$SORTED_PNS` echo " Lines changed in the past period (cummulative): Total Lines Week Week% Month Month% Quartr Quart% HalfYr HlfYr% Year Year% File ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------------" cat $SORTED_PNS | while read PN ; do # Annotate file and count lines changed if cleartool annotate -force -nco -nheader -fmt "%BAd|" -out $ANN $PN >/dev/null ; then total=`wc -l <$ANN` grand_total=`expr $grand_total + $total` past_week=`cat $ANN | grep '^#####' | wc -l` grand_week=`expr $grand_week + $past_week` if [ $total = 0 ] then percent_week=`expr 0 - 0` else percent_week=`expr $past_week \* 100 / $total` fi past_month=`cat $ANN | grep '^####' | wc -l` grand_month=`expr $grand_month + $past_month` if [ $total = 0 ] then percent_month=`expr 0 - 0` else percent_month=`expr $past_month \* 100 / $total` fi past_quarter=`cat $ANN | grep '^###' | wc -l` grand_quarter=`expr $grand_quarter + $past_quarter` if [ $total = 0 ] then percent_quarter=`expr 0 - 0` else percent_quarter=`expr $past_quarter \* 100 / $total` fi past_half_year=`cat $ANN | grep '^##' | wc -l` grand_half_year=`expr $grand_half_year + $past_half_year` if [ $total = 0 ] then percent_half_year=`expr 0 - 0` else percent_half_year=`expr $past_half_year \* 100 / $total` fi past_year=`cat $ANN | grep '^#' | wc -l` grand_year=`expr $grand_year + $past_year` if [ $total = 0 ] then percent_year=`expr 0 - 0` else percent_year=`expr $past_year \* 100 / $total` fi echo "`make6wide $total`" \ "#`make6wide $past_week`" `make6wide "($percent_week%)"` \ "#`make6wide $past_month`" `make6wide "($percent_month%)"` \ "#`make6wide $past_quarter`" `make6wide "($percent_quarter%)"` \ "#`make6wide $past_half_year`" `make6wide "($percent_half_year%)"` \ "#`make6wide $past_year`" `make6wide "($percent_year%)"` "#$PN" | sed -e 's/#/ /g' fi rm -f $ANN # shell variables set inside while-loop are in a different scope and don't survive rm -f $GRAND echo "grand_total=$grand_total grand_week=$grand_week grand_month=$grand_month grand_quarter=$grand_quarter grand_half_year=$grand_half_year grand_year=$grand_year" >$GRAND done if [ -r $GRAND ] ; then #restore variables . $GRAND fi echo "====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ==========" if [ "$grand_total" != 0 ] ; then percent_week=`expr $grand_week \* 100 / $grand_total` percent_month=`expr $grand_month \* 100 / $grand_total` percent_quarter=`expr $grand_quarter \* 100 / $grand_total` percent_half_year=`expr $grand_half_year \* 100 / $grand_total` percent_year=`expr $grand_year \* 100 / $grand_total` fi echo "`make6wide $grand_total`" \ "#`make6wide $grand_week`" `make6wide "($percent_week%)"` \ "#`make6wide $grand_month`" `make6wide "($percent_month%)"` \ "#`make6wide $grand_quarter`" `make6wide "($percent_quarter%)"` \ "#`make6wide $grand_half_year`" `make6wide "($percent_half_year%)"` \ "#`make6wide $grand_year`" `make6wide "($percent_year%)"` \ " " $NUMFILES "files" | sed -e 's/#/ /g' rm -f $PNS $ANN $GRAND $SORTED_PNS PROMPT="CODE_CHANGE_REPORT for $SEARCH_POINT was completed." clearprompt yes_no -pre -mask yes -def yes -pro "$PROMPT"