subdir=
findopt=
cpioopt="-p"
typeset -Z2 mon day year hour min
typeset -u rtime dtime
eval `date '+mon=%m day=%d year=%y'`
dstr=
hour=00
min=00
arg=
last=
lcmd=
if test ! -d "$1" -a ! -d "${HOME}/$1"
then
	print - "$0: Error - no directory specified for backup files"
	exit 1
fi
first="$1"
shift
while true
do case "$1" in
	'')		break;;
	/[sS])		findopt="$findopt -depth"; cpioopt="${cpioopt}d"
			subdir=Y;;
	/[mM])		cpioopt="${cpioopt}m";;
	/[nN])		;;
	/[pP])		;;
	/[eElL]:*)	hstr=${1#*:}
			hour=${hstr%%[.:]*}
			hstr=${hstr#*[.:]}
			min=${hstr%[.:]*}
			rtime=${1%%:*}
			;;
	/[aAbB]:*)	dstr=${1#*:}
			mon=${dstr%%[-/]*}
			dstr=${dstr#*[-/]}
			day=${dstr%[-/]*}
			year=${dstr#*[-/]}
			dtime=${1%%:*}
			;;
	*)	arg="$arg $1"
		;;
   esac
   shift
done
now=$PWD
cd $first
if test -n "$dtime$rtime"
then
	trap "rm /tmp/dsh$$" 0
	trap exit 1 2 3 15
	touch "${mon}${day}${hour}${min}${year}" /tmp/dsh$$
	if test "$dtime" = "/A" -o "$rtime" = "/E"
	then	findopt="$findopt !"
	fi
	findopt="$findopt -newer /tmp/dsh$$"
	if test "$arg" != ""
	then	temp=`ls -t /tmp/dsh$$ $arg`
		if test "$dtime" = "/A" -o "$rtime" = "/E"
		then	arg=${temp#*/tmp/dsh$$?}
		else	arg=${temp%?/tmp/dsh$$*}
		fi
		if test "$temp" = "$arg"
		then	print - "Nothing to restore"
			rm /tmp/dsh$$ ; exit 1
		fi
	fi
fi
if test -n "$subdir"
then
	_Ducmd "find $arg $findopt -print | cpio $cpioopt $now"
else
	_Ducmd "ls $arg | cpio $cpioopt $now"
fi
