forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqb.init.sh
72 lines (68 loc) · 1.19 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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
: ) printf %s\\n "$@" >&2; return 0 ;;
0 ) printf %s\\n "$@" ;;
* ) printf %s\\n "$@" >&2 ;;
esac
exit "$ret"
}
# exists:
# Finds executable files in the $PATH
# $@ = files
exists()
{ v=1
while [ $# -gt 0 ]; do
arg="$1"
shift 1
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
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
}
# next:
# Check if the next argument starts with a dash
# $1 = arg
next () { case "$1" in -*) return 0 ;; *) return 1 ;; esac; }