#!/bin/sh
#	cmp - cmp 2 directories

#  Henry Grebler    14 Jun 01  Tell user if he specified a file (not dir).
#  Henry Grebler    13 Oct 98  Remove . from path to avoid problems when
#				one of the dirs contains progs for another
#				architecture.
#  Henry Grebler    24 Aug 93  First cut.
#=============================================================================#


cat <<XXX
cmp - compare 2 directories
usage: cmp [dir1] dir2		(default current dir)

XXX
 
	if [ "$3" != "" ]
	then
		echo "Can't imagine what to do with a 3rd arg."
		exit 1
	fi

        p1=$1
        if [ "$p1" = "" ]
        then
                echo -n "dir: "
                read p1
                if [ "$p1" = "" ]; then exit 2; fi
        fi
	if [ ! -d $p1 ]
	then
		echo $p1 does not exist or is not a directory
		exit 3
	fi


	if [ "$2" != "" ]
	then
		if [ ! -d $2 ]
		then
			echo $2 does not exist or is not a directory
			exit 4
		fi
		dir=`cd $2;pwd`
		cd $p1
	else
		dir=$p1
	fi

	PATH=`echo $PATH | sed 's/.://'`

cat <<XXX
Comparing directories:	`pwd`
		  and:	`(cd $dir;pwd)`

The following files differ:

XXX
	for i in `ls -A`
	do
		if [ ! \( -f $dir/$i -o -d $dir/$i \) ]
		then
			echo $i only in `pwd`
			continue
		fi
		cmp -s ./$i $dir/$i
		status=$?
		if [ $status -eq 1 ]
		then
			echo $i
		elif [ $status -eq 2 ]
		then
#			echo hello
			echo error encountered with '"'`pwd`/$i'"' or '"'$dir/$i'"'
		fi
	done
