RetroArch/qb/qb.init.sh

73 lines
1.2 KiB
Bash
Raw Normal View History

2019-01-25 15:00:28 +00:00
# Only add standalone functions to this file which are easy to source anywhere.
# die:
# Prints a warning or an exit error.
# $1 = exit code, use : to not exit when printing warnings
# $@ = exit or warning messages
die()
{ ret="$1"
shift 1
case "$ret" in
2019-10-16 02:27:36 +00:00
: ) printf %s\\n "$@" >&2; return 0 ;;
0 ) printf %s\\n "$@" ;;
* ) printf %s\\n "$@" >&2 ;;
2019-01-25 15:00:28 +00:00
esac
2019-10-16 02:27:36 +00:00
exit "$ret"
2019-01-25 15:00:28 +00:00
}
# exists:
# Finds executable files in the $PATH
# $@ = files
exists()
{ v=1
while [ $# -gt 0 ]; do
arg="$1"
shift 1
2020-01-14 18:20:07 +00:00
case "$arg" in
''|*/ )
:
;;
*/* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
printf %s\\n "$arg"
v=0
fi
;;
* )
p=":$PATH"
while [ "$p" != "${p#*:}" ]; do
p="${p#*:}"
d="${p%%:*}/$arg"
if [ -f "$d" ] && [ -x "$d" ]; then
printf %s\\n "$d"
v=0
break
fi
done
;;
esac
2019-01-25 15:00:28 +00:00
done
return $v
}
# match:
# Compares a variable against a list of variables
# $1 = variable
# $@ = list of variables
match()
{
var="$1"
shift
for string do
case "$string" in
"$var" ) return 0 ;;
esac
done
return 1
}
2020-01-13 17:17:00 +00:00
# next:
# Check if the next argument starts with a dash
# $1 = arg
next () { case "$1" in -*) return 0 ;; *) return 1 ;; esac; }