#!/bin/bash

if [ $# -lt 2 ]; then
	echo "usage: $0 css1 css2"
	exit 1
fi

FIRST=$1
SEC=$2

function cssdiff()
{

	FIRST=$1
	SEC=$2

	RET=0

	fclasses=`grep "{" ${FIRST} | tr -d "{" | tr "," "\n" | awk '{$1=$1};1' | tr " " "_" |sort |uniq`
	sclasses=`grep "{" ${SEC} | tr -d "{" | tr "," "\n" | awk '{$1=$1};1' | tr " " "_" |sort |uniq`

	for class in $fclasses; do

		if ! (echo "$sclasses" | grep $class >/dev/null); then
			echo "$class" |tr "_" " "
			RET=1
		fi

	done

	return $RET

}

################################

if ! [ -f $FIRST ]; then
	echo "$FIRST not found"
	exit 11
fi

if ! [ -f $SEC ]; then
	echo "$SEC not found"
	exit 12
fi

cdiff=`cssdiff $FIRST $SEC`
ERR=$?

if ! [ "$ERR" == "0" ]; then
	echo "Missing CSS styles in $SEC:"
	echo "$cdiff"
else
	echo "No missing CSS styles found in $SEC"
fi

exit $ERR
