#
# rrmdir
#
# Remove a directory and recursively its parents. Quietly stops
# at an unremovable directory.
#

set -ue
myname=${0}

root=/

while [ $# -ne 0 ]
do
	case "${1}" in
	-r)
		root="${2}" ; shift 2 ;;
	-*)
		echo "${myname}: \"${1}\": Unknown option" >&2 ; exit 1 ;;
	*)
		break ;;
	esac
done

for dir
do
	while rmdir ${root}/${dir} 2>/dev/null
	do
		dir="`ignore expr \
			${dir-.}'/' : '\(/\)[^/]*/$' \
			\| ${dir-.}'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
			\| .`"
		case ${dir} in
		. | /)	break ;;
		esac
	done
done