-
Notifications
You must be signed in to change notification settings - Fork 1
/
getinclude
executable file
·55 lines (39 loc) · 1.01 KB
/
getinclude
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
#!/bin/bash
#
# getinclude
#
declare -i argcount=1
declare includestring
declare leadstring
declare includefile
declare -i _LOCALINCLUDE_=16
declare usagestr=$(
cat <<EOF
$(basename $0) includestring
NOTE: This is intended to be executed from the top of a kernel tree.
Extracts the include filename, including full path, from the string.
If the string does not start with #include, it will be ignored and
the script will exit silently with no affect, but with a nonzero
value.
includestring - the string containing '#include'
\0
EOF
)
usage() {
echo -e "$usagestr"
exit $1
}
[ $# -eq "$argcount" ] || usage 1
shopt -s extglob
includestring="$1"
leadstring=$(echo "$includestring" | cut -d' ' -f1)
[ "$leadstring" == "#include" ] || exit 1
includefile=$(echo "$includestring" | cut -d' ' -f2)
if [ "${includefile:0:1}" == '"' ]; then
includefile=$(echo $includefile | sed -r 's/"//g')
echo "$includefile"
exit $_LOCALINCLUDE_
else
echo "include/$(echo $includefile | sed -r "s/<|>//g")"
exit 0
fi