#! /bin/sh

goal="test regular links with 63 & 1024 character pathnames"
bru=${BRU:-bru}

# Parse our args.  Options include:
#
#	-s	Print our one line test goal and quit
#

while true
do
	case $1 in
		-d)	dflag="on"
			shift
			;;
		-g)	echo $goal
			exit 0
			;;
		*bru*)	bru=$1
			shift
			;;
		*)	break
			;;
	esac
done

if [ "$dflag" != "on" ]
then
	trap "rm -f bru.out* ; ../bin/rmtree tmpdir000 ; exit 1" 1 2 13 15
fi

# First clean up any stuff that may be left from a previous test.

rm -f bru.out*
if test -d tmpdir000
then
	../bin/rmtree tmpdir000
fi

# Run test.

top=`pwd`
for i in 0 1 2 3 4 5 6 7 8 9
do
	for j in 0 1 2 3 4 5 6 7 8 9
	do
		mkdir tmpdir0${i}${j}
		cd tmpdir0${i}${j}
		path="${path}tmpdir0${i}${j}/"
		if [ "tmpdir0${i}${j}" = "tmpdir005" ]
		then
			touch 0101000070 abc
			file1=${path}abc
		fi
	done
done
for i in 100 101
do
	mkdir tmpdir${i}
	cd tmpdir${i}
	path="${path}tmpdir${i}/"
done
ln ${top}/$file1 abcd
chgrp 0 abcd
chmod 666 abcd
chgrp 0 abcd
chown 0 abcd
file2=${path}abcd
cd $top

(echo ${file1}; echo ${file2}) | $bru -cvvf bru.out1 -
echo "bru exit status was $?"

$bru -ivvf bru.out1
echo "bru exit status was $?"

$bru -dvvf bru.out1
echo "bru exit status was $?"

$bru -tvvf bru.out1
echo "bru exit status was $?"

(echo ${file2}; echo ${file1}) | $bru -cvvf bru.out2 -
echo "bru exit status was $?"

$bru -ivvf bru.out2
echo "bru exit status was $?"

$bru -dvvf bru.out2
echo "bru exit status was $?"

$bru -tvvf bru.out2
echo "bru exit status was $?"

if [ "$dflag" != "on" ]
then
	../bin/rmtree tmpdir000
	rm -f bru.out*
fi
exit 0
