#!/bin/sh

# This is Eli's code diff.

# It is a diff that...  removes comments, removes {}'s, removes whitespace
# ... for the purposes of diff'ing code without worrying about people's editors
# dicking around with tabs or choosing a new {} style or that blocks of commented
# out dead code no longer exist.

# wget http://sed.sourceforge.net/grabbag/scripts/remccoms3.sed
# ... into your path to remove C style comments

#ugh, probably a better *nix way to do this.  Passing the first block of -args along to diff
# if we have three arguments, not if we don't.  @@ Does not support using multiple blocks of arguments
# or --named arguments, probably should count from right to left and pass all the rest but this is
# sh, hate sh and can't be bothered at the moment.

if [ $# -eq 2 ]; then
	first=$1;
	second=$2;
	args="";
fi

if [ $# -eq 3 ]; then
	first=$2;
	second=$3;
	args=$1;
fi


echo $first
echo $second
echo $args

# in order..
# remcomms3 to strip out comments
# tr to get rid of }
# tr to get rid of {
# no more blank lines

cat $first | ~/.bin/remccoms3.sed | tr "}" " " | tr "{" " " | sed '/^[[:space:]]*$/d' > /tmp/codediff.1.tmp
cat $second | ~/.bin/remccoms3.sed | tr "}" " " | tr "{" " " | sed '/^[[:space:]]*$/d' > /tmp/codediff.2.tmp

# the ignore whitespace argument is baked in, everything else specify manually
diff -w $args /tmp/codediff.1.tmp /tmp/codediff.2.tmp

rm /tmp/codediff.1.tmp
rm /tmp/codediff.2.tmp
