#!/bin/sh
#list the tapsets in the tapsets.tmpl file and properally format the file neames
less tapsets.tmpl | grep "\.stp" | grep ! > checkfile
less checkfile | sed 's/!Itapset\///g' > checkfile2
#change to the tapset directory and check the tapsets there
cd ../../tapset/
ls -R | grep "\.stp" > ../doc/SystemTap_Tapset_Reference/checkfile1
#change back to the tapset directory and order the tapset names
#then diff the files to examine the differences
cd ../doc/SystemTap_Tapset_Reference
sort -d checkfile2 | uniq > checkfiles
sort -d checkfile1 | uniq > checkfile1s
diff checkfiles checkfile1s > checkdiff
diff checkfile1s checkfiles > checkdiff1
diff=`less checkdiff | wc -l `
zero='0'
one='1'
if [ "$diff" -gt "$one" ]
then
	docs=`less checkfiles | wc -l `
	tapsets=`less checkfile1s | wc -l `
	doctapdiff=`expr $docs - $tapsets` #differece between line count
	#if $docs is greater than there are more tapset documents
	#then there are tapsets being used
	#if there are more $tapsets then there are tapsets that have
	#been excluded from the documentation
	if [ "$doctapdiff" -gt "$zero" ]
	then
		echo You have more Documentation than tapsets, specifically:
		less checkdiff1 | grep ">" 
	else
		echo You have Tapsets that are undocumented, specifically:
		less checkdiff | grep ">"
	fi
else
	echo You have no missing Tapsets from documentation or excessive documentation!
fi

#at the end we need to make sure we remove any files that we created
#change to proper directory first
rm checkfile checkfiles checkfile1 checkfile1s checkdiff checkdiff1 checkfile2
