#!/bin/bash 
#
# $Id$
#
# Mesures quality improvement of mondorescue project
#

# Adapt to your needs
dname=`dirname $0`
prem=`echo $dname |cut -c1`
if [ ${prem} == "/" ]; then
        export TOOLHOME=$dname
else
        export TOOLHOME=${PWD}/$dname
fi

d=$TOOLHOME/..

if [ $# -gt 0 ]; then
	if [ -d $1 ]; then
		d=$1
	fi
fi

echo "Working on $d"
echo " "
cd $d

# How many sprintf/strcat/strcpy vs asprintf are they
for s in asprintf mr_asprintf sprintf strcat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free; do
	echo "monodrescue $s usage : "
	tot=0
	for i in `find . -name '*.c' -o -name '*.h' |  egrep -v '\.svn|/\*|monitas|mindi-busybox' | xargs grep -r -c -w $s | egrep -v ":0$"`; do
			echo " === $i"
			((tot=$tot+`echo $i | cut -d: -f2`))
	done
	echo "total $s usage : $tot"
done

echo " "
echo "Qualimetry: "
find . -name '*.c' -o -name '*.h' |  egrep -v '\.svn|/\*|monitas|/\*|mindi-busybox' | xargs grep -r asprintf | egrep -v '/\*' | egrep -v 'asprintf\(&' > /tmp/mondo.quality
cat /tmp/mondo.quality
echo "monodrescue uses : `cat /tmp/mondo.quality | wc -l` asprintf without &"
find . -name '*.c' -o -name '*.h' |  egrep -v '\.svn|/\*|monitas|/\*|mindi-busybox' | xargs grep -r getline | egrep -v '/\*' | egrep -v 'getline\(&' > /tmp/mondo.quality
cat /tmp/mondo.quality
echo "monodrescue uses : `cat /tmp/mondo.quality | wc -l` getline without &"

echo " "
echo "Splint: "
find . -name '*.c' -o -name '*.h' | xargs splint +posixlib -Dlinux

rm -f /tmp/mondo.quality
