#!/bin/bash #set -ex ## Rough statistics on routines (code / notes / blank) [ -z "$*" ] && { echo 'No branch path(s) given => QUIT'; exit 2; } branches=$* export LC_NUMERIC='en_GB.UTF-8' ## Decimal separator fmt='%-50s %7d(%4.1f%%) %7d(%4.1f%%) %7d(%4.1f%%) %7d\n' for branch in $branches; do cod_sum=0; not_sum=0; blk_sum=0; lin_sum=0 paths="$branch/NEMOGCM/NEMO $branch/src" [ -z "$( ls $paths 2> /dev/null )" ] && continue printf "%-50s %7s(ratio) %7s(ratio) %7s(ratio) %7s\n" \ '' code notes blank all for dir in $( find $paths -type d -mindepth 1 -maxdepth 1 2> /dev/null ); do files=$( find $dir -name "*.[fFh]90" 2> /dev/null ) cod_nb=$( grep -h '^ *[^! ]' $files | wc -l ); not_nb=$( grep -h '^ *!' $files | wc -l ) blk_nb=$( grep -h '^ *$' $files | wc -l ) lin_nb=$(( cod_nb + not_nb + blk_nb )) cod_ratio=$( echo "scale = 3; ( ${cod_nb} / ${lin_nb} ) * 100" | bc ) not_ratio=$( echo "scale = 3; ( ${not_nb} / ${lin_nb} ) * 100" | bc ) blk_ratio=$( echo "scale = 3; ( ${blk_nb} / ${lin_nb} ) * 100" | bc ) dir=$( echo $dir | awk -F/ '{printf "%s/%s/%s", $(NF-2), $(NF-1), $(NF)}' ) printf "$fmt" $dir \ ${cod_nb} ${cod_ratio} ${not_nb} ${not_ratio} ${blk_nb} ${blk_ratio} \ $lin_nb cod_sum=$(( cod_sum + cod_nb )); not_sum=$(( not_sum + not_nb )) blk_sum=$(( blk_sum + blk_nb )); lin_sum=$(( lin_sum + lin_nb )) done cod_ratio=$( echo "scale = 3; ( ${cod_sum} / ${lin_sum} ) * 100" | bc ) not_ratio=$( echo "scale = 3; ( ${not_sum} / ${lin_sum} ) * 100" | bc ) blk_ratio=$( echo "scale = 3; ( ${blk_sum} / ${lin_sum} ) * 100" | bc ) branch=$( echo $branch | awk -F/ '{print $NF}' ) printf "$fmt" $branch \ ${cod_sum} ${cod_ratio} ${not_sum} ${not_ratio} ${blk_sum} ${blk_ratio} \ ${lin_sum} echo done exit 0