mirror of
https://github.com/NaomiAmethyst/dots.git
synced 2025-08-05 16:48:38 +00:00
clean up err, support E* style errs
This commit is contained in:
parent
635b742aee
commit
ea78f108d8
1 changed files with 46 additions and 7 deletions
|
@ -10,16 +10,55 @@ unkey_host ()
|
||||||
|
|
||||||
err ()
|
err ()
|
||||||
{
|
{
|
||||||
if ( command -v ruby > /dev/null 2>&1 ); then
|
case $@ in
|
||||||
ruby -e "puts Errno.constants.find_all{|err| eval('Errno::' + err + '::Errno') == $@ }"
|
E*)
|
||||||
elif [ -e /usr/include/errno.h ] ; then
|
unset errno
|
||||||
cpp -dM /usr/include/errno.h | grep -w "E.* $@"
|
if [ "${errno}" = "" ] && ( command -v python > /dev/null 2>&1 ); then
|
||||||
|
errno=`python -c "import errno;print(errno.$@)" 2>/dev/null`
|
||||||
|
fi
|
||||||
|
if [ "${errno}" = "" ] && ( command -v ruby > /dev/null 2>&1 ); then
|
||||||
|
errno=`ruby -e "puts Errno::$@::Errno if (Errno::$@)" 2>/dev/null`
|
||||||
|
fi
|
||||||
|
if [ "${errno}" = "" ] && [ -e /usr/include/errno.h ] ; then
|
||||||
|
errno=`cpp -dM /usr/include/errno.h | grep -w "$@" | grep -oE '[0-9]+' 2>/dev/null`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "${errno}" ] ; then
|
||||||
|
errstr="$@ = $errno"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${errstr}" ] ; then
|
||||||
|
echo $errstr
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
unset errconst
|
||||||
|
if [ "${errconst}" = "" ] && ( command -v python > /dev/null 2>&1 ); then
|
||||||
|
errconst=`python -c "import errno;print(errno.errorcode[$@])" 2>/dev/null`
|
||||||
|
fi
|
||||||
|
if [ "${errconst}" = "" ] && ( command -v ruby > /dev/null 2>&1 ); then
|
||||||
|
errconst=`ruby -e "puts Errno.constants.find_all{|err| eval('Errno::' + err + '::Errno') == $@ }"`
|
||||||
|
fi
|
||||||
|
if [ "${errconst}" = "" ] && [ -e /usr/include/errno.h ] ; then
|
||||||
|
errconst=`cpp -dM /usr/include/errno.h | grep -w "E.* $@"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${errconst}" ] ; then
|
||||||
|
echo $errconst
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
errno=$@
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if ( command -v perl > /dev/null 2>&1 ) ; then
|
if ( command -v perl > /dev/null 2>&1 ) ; then
|
||||||
perl -MPOSIX -e 'print strerror($ARGV[0])."\n";' $@
|
perl -MPOSIX -e 'print strerror($ARGV[0])."\n";' $errno
|
||||||
elif ( command -v python > /dev/null 2>&1 ) ; then
|
elif ( command -v python > /dev/null 2>&1 ) ; then
|
||||||
python -c "import os;print(os.strerror($@))"
|
python -c "import os;print(os.strerror($errno))"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue