Revision 9bb57c0b119ee75c9e49842a686c0ca07970e37c authored by Colin Percival on 25 January 2010, 23:48:47 UTC, committed by Colin Percival on 25 January 2010, 23:48:47 UTC
to HEAD in r185029; but this is an "inspired by" commit rather than a
literal merge, since this region of code in HEAD has other non-MFCable
changes.

The namei lookups this unbreaks are required for ZFS extended attributes;
prior to this commit, an attempt to look up (list, read, write, delete)
extended attributes would be handled as an attempt to look up a file in
the current directory if an extended attribute directory existed ("at vp"
was mishandled as "right here").

Reviewed by:	jhb
Approved by:	re (kib)
Found by:	Henrik Wiest & libarchive
1 parent 0ddd204
Raw File
getans
#!/bin/sh
# getans prompt type default  results_filename
#  type is one of 
#   number  
#   integer
#   neginteger
#   file    default=default filename
#   path        
#   yesno   default=0,1 corres yes or no 
#   string (default)

RAWPMPT=$1
TYP=$2
DFLT=$3
OFNM=$4

ny0="no"; ny1="yes"
if [ ${TYP} = "yesno" ]; then
    eval ny=\$ny${DFLT}
    pmpt="${RAWPMPT} [$ny]: "
else
    if [ -z "${DFLT}" ]; then
        pmpt="${RAWPMPT}"
    else
        pmpt="${RAWPMPT} [${DFLT}]: "
    fi
fi
if [ x"`echo -n`" = x-n ]
then
    c=\\c
else
    n=-n
fi

while :
do
    echo $n "$pmpt"$c
    read input
    case "$TYP" in
    number)
	tmp=`echo $input | tr -d 0123456789.`
	if [ -n "$tmp" ]; then
	    echo "Invalid number.  Please try again."
	    continue
	fi
	;;

    integer)
	tmp=`echo $input | tr -d 0123456789`
	if [ -n "$tmp" ]; then
	    echo "Invalid integer.  Please try again."
	    continue
	fi
	;;

    neginteger)
	if [ "x$input" != "x-1" ]; then
	    tmp=`echo $input | tr -d 0123456789`
	    if [ -n "$tmp" ]; then
	        echo "Invalid integer.  Please try again."
	        continue
	    fi
	fi
        ;;

    file)
	if [ -z "$input" ]; then
	    input=${DFLT}
	fi
	if [ ! -f "$input"  -a ! -d "$input" ]; then
	    echo "The file $input does not exist.  Please try again."
	    continue
	fi
	;;

    path)
	if [ -z "$input" ];  then
	    input="${DFLT}"
	fi
	if [ ! -f "$input" ]; then
            path=`echo $PATH | sed -e s'/::/ . /g' -e 's/:/ /g'`
	    x=
            for elt in $path;  do
		if [ -f "$elt/$input" ]; then  x=1; break; fi
	    done
	    if [ -z "$x" ] ;then 
                echo "The command $input was not found.  Please try again."
	        continue
            fi
	fi
	;;

    yesno)
	if [ -z "$input" ];  then  
            input="${DFLT}"
        else
            case $input in 
            y | yes)
                input=1 ;;
            n | no)
                input=0 ;;
            *)
	        echo 'Please answer "yes" or "no".'
	        continue ;;
            esac
        fi
        ;;

    *)	;;
    esac
    break
done

if [ -z "$input" ]; then
    input="${DFLT}"
fi

echo $input > ${OFNM}
back to top