#!/bin/bash

SOURCEFILE="$HOME/.www/data/doc/Index"
TMPFILE=/tmp/countit.$$
YEARS="1991 1992 1993 1994 1995 1996 1997 1998 1999 2000"
MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
GREP=grep
NECHO='/bin/echo -n'

/bin/rm -f "${TMPFILE}"
trap '/bin/rm -f ${TMPFILE}; exit 1' 1 2 3 15

TODAY="`date '+%h %Y'`"

${GREP} "^ Date:" "${SOURCEFILE}"	> "${TMPFILE}"

echo "REVIEWS POSTED IN COMP.SYS.AMIGA.REVIEWS, PER MONTH"
echo "(As of `date '+%a, %h %d %Y, %T'`)"
echo ''
echo "Month		Reviews		Running Total	Graph"
LLLL="======================================================================="
echo "$LLLL"

total=0

for year in ${YEARS}
do
	for month in ${MONTHS}
	do
		${NECHO} "${month}, ${year}:	"
		num=`${GREP} -w "${month} .*, ${year}" ${TMPFILE} | wc -l`
		total=`expr $total + $num`

		if [ $num -eq 0 ]
		then
			${NECHO} $num '		"'
		else
			${NECHO} $num "		$total"
		fi

		${NECHO} '		'
		i=0
		stars=""
		while [ $i -lt $num ]
		do
			stars='*'"${stars}"
			i=`expr $i + 1`
		done
		echo "$stars"

		if [ "$month $year" = "$TODAY" ]
		then
			echo "$LLLL"
			echo "TOTAL		$total		$total"
			/bin/rm -f "${TMPFILE}"
			exit 0
		fi
	done
done


echo "$LLLL"
echo "TOTAL		$total		$total"
/bin/rm -f "${TMPFILE}"
exit 0
