summaryrefslogtreecommitdiffstats
path: root/tests/load-functions
blob: 34361588e2720360717ef79206156552b32a9110 (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- sh -*-
# See LICENSE file for copyright and license details.

parallelindex=0
p () {
	(
		set +ev
		pid=$$-$parallelindex
		a=.a-$pid.tmp
		b=.b-$pid.tmp
		log=.x-$pid.tmp
		( set -ev ; $t "$@" ) > $log 2>&1
		r=$?
		test $r = 0 || cat -- $log >&2
		rm -f -- .?-$pid.tmp
		exit $r
	) &
	eval parallelpid$(( ++parallelindex ))=$!
}
await () {
	while (( parallelindex )); do
		parallelvar=parallelpid$(( parallelindex-- ))
		eval wait '$'$parallelvar
	done
}


stderr () {
	("$@") 2>&1 >/dev/null
}

getlist () {
	getlist_list="$1"
	shift 1
	if test $# = 0; then set cat; fi
	"$@" < libsyscalls.h \
	| tr , '\n' \
	| sed -n 's/^[[:space:]]*LIBSYSCALLS_'"${getlist_list}"'_\([A-Z0-9_]\{1,\}\([[:space:]]*=[[:space:]]*[[:space:]0-9A-Fa-fxXULul()^&|!*/<>~+-]\{1,\}\)\{0,1\}\)\([^A-Za-z0-9_].*\)*$/\1/p' \
	| tr = ' ' \
	| (i=0; while read name value; do
		if test -n "$value"; then
			i=$(( $(printf '%s\n' "$value" | tr -d 'ULul') ))
			i=$(printf '%s\n' "$i" | cut -d . -f 1)
		fi
		printf '%i %s\n' $(( i++ )) $name;
	done)
}

getnamelist () {
	getlist "$@" | cut -d ' ' -f 2
}

getnumlist () {
	getlist "$@" | cut -d ' ' -f 1
}

getname () {
	(getlist "$1" | grep "^$2 " | cut -d ' ' -f 2 | tee /dev/stderr | grep . >/dev/null) 2>&1
}

getnum () {
	(getlist "$1" | grep " $2"\$ | cut -d ' ' -f 1 | tee /dev/stderr | grep . >/dev/null) 2>&1
}

lookupname () {
	(printf '%s\n' "$1" | grep "^$2 " | cut -d ' ' -f 2 | tee /dev/stderr | grep . >/dev/null) 2>&1
}

lookupnum () {
	(printf '%s\n' "$1" | grep " $2"\$ | cut -d ' ' -f 1 | tee /dev/stderr | grep . >/dev/null) 2>&1
}

issupported () {
	if test $# = 1; then
		printf '%s\n' ${SUPPORTED_OSES} | grep -i "^$1"\$ > /dev/null
	else
		printf '%s\n' ${SUPPORTED_OSES} | grep -i "^$1"\$ > /dev/null &&
		env | sed -n 's/^SUPPORTED_'"$1"'_ARCHES=//p' | xargs printf '%s\n' | grep -i "^$2"\$ > /dev/null
	fi
}

cpp_enum_clean () {
	$CPP < libsyscalls.h 2>/dev/null | grep -v '#' | tr '\n,{}' ' \n\n\n'
}

min () {
	printf '%s\n' "$@" | tr -d + | sort -n | sed -n 1p
}