forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
qb.init.sh
43 lines (41 loc) · 864 Bytes
/
qb.init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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
printf %s\\n "$@" >&2
case "$ret" in
: ) return 0 ;;
* ) exit "$ret" ;;
esac
}
# exists:
# Finds executable files in the $PATH
# $@ = files
exists()
{ v=1
while [ $# -gt 0 ]; do
arg="$1"
shift 1
case "$arg" in ''|*/) continue ;; esac
x="${arg##*/}"
z="${arg%/*}"
[ ! -f "$z/$x" ] || [ ! -x "$z/$x" ] && [ "$z/$x" = "$arg" ] &&
continue
[ "$x" = "$z" ] && [ -x "$z/$x" ] && [ ! -f "$arg" ] && z=
p=":$z:$PATH"
while [ "$p" != "${p#*:}" ]; do
p="${p#*:}"
d="${p%%:*}"
if [ -f "$d/$x" ] && [ -x "$d/$x" ]; then
printf %s\\n "$d/$x"
v=0
break
fi
done
done
return $v
}