-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetallinclude
executable file
·93 lines (72 loc) · 1.62 KB
/
getallinclude
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
89
90
91
92
93
#!/bin/bash
#
# getallinclude
#
######################################################
#
# REQUIRES THESE BASH SCRIPTS
#
# getinclude
#
######################################################
#
# Text attributes
#
attr_bold="\033[1m"
attr_under="\033[4m"
attr_OFF="\033[0m"
BLD="$attr_bold"
UND="$attr_under"
OFF="$attr_OFF"
declare -i optcount=0
declare filepath
declare inclist
declare incpath
declare dir
declare -i stat
declare -i _LOCALINCLUDE_=16
declare -i _NOINCLUDES_=8
declare usagestr=$(
cat <<EOF
$(basename $0) [options] filepath
NOTE: This is intended to be executed from the top of a kernel tree.
Parses the given files in a directory for #include declarations.
filepath - the complete path, including directories to the file to search.
Options
-h - this help text
\0
EOF
)
sage() {
echo -e "$usagestr"
exit $1
}
while getopts h OPTION; do
case "$OPTION" in
h ) optcount=$((optcount+1))
usage 1
;;
* ) echo "unrecognized option -$OPTION"
echo -e "$usagestr"
exit 127
esac
done
shift $optcount
[ $# -eq 1 ] || { echo -e "\nNeed the filepath!"; exit 1; }
shopt -s extglob
shopt -s globstar
filepath="$1"
[ -f "$filepath" ] || {
echo -e "\n\t$BLD$filepath not a file! $OFF"
exit $_NOINCLUDES_
}
dir=$(dirname $filepath)
inclist="$(grep "#include" "$filepath" | cut -d':' -f2)"
[ "$inclist" ] || exit $_NOINCLUDES_
while read line; do
incpath=$(getinclude "$line");
# If the call to getinclude() returned the exit code _LOCALINCLUDE_
# then the include path is local to the current directory.
#
[ $? -eq $_LOCALINCLUDE_ ] && echo $dir/$incpath || echo $incpath
done <<< "$inclist"