-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindinclude
More file actions
executable file
·115 lines (90 loc) · 2.06 KB
/
findinclude
File metadata and controls
executable file
·115 lines (90 loc) · 2.06 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#
# findinclude
#
######################################################
#
# REQUIRES THESE BASH SCRIPTS
#
# getallincludes
# 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 -i _FOUNDIT_=32
declare -i _NOINCLUDES_=8
declare -i stat
declare incfile
declare srcfile
declare inclist
declare b_verbose=false
declare usagestr=$(
cat <<EOF
$(basename $0) [options] incfile srcfile
Search the given source file for the given include file. If the include
file we are seeking is not in the source file, then each of the include
files in the source file will be recursively searched for the given
include file.
incfile - the include file we are seeking
srcfile - the source file that we believe contains it or contains other
include files that contain it.
Options
-v - verbose output shows each file parsed
-h - this help text
\0
EOF
)
usage() {
echo -e "$usagestr"
exit $1
}
while getopts hv OPTION; do
case "$OPTION" in
h ) optcount=$((optcount+1))
;;
v ) optcount=$((optcount+1))
b_verbose=true
;;
* ) echo "unrecognized option -$OPTION"
echo -e "$usagestr"
exit 127
esac
done
shift $optcount
[ $# -eq 2 ] || usage 1
incfile="$1"
srcfile="$2"
IFS=
$b_verbose && echo -e "$(basename $0) $incfile $srcfile" || echo -n '.'
inclist=$(getallinclude $srcfile)
[ $? -eq $_NOINCLUDES_ ] && {
# $b_verbose && echo -e "$BLD\tno includes detected in $srcfile$OFF"
exit $_NOINCLUDES_
}
# echo "$inclist"
while read line; do
echo "$line" | grep -w "$incfile" 2>&1 > /dev/null
[ $? -eq 0 ] && {
$b_verbose || echo
echo -e "$BLD"$srcfile" contains "$incfile$OFF""
$b_verbose && echo
exit $_FOUNDIT_
}
done <<< "$inclist"
while read line; do
[ -f "$line" ] || continue
$b_verbose && findinclude -v "$incfile" "$line" \
|| findinclude "$incfile" "$line"
stat=$?
[ $stat -eq $_FOUNDIT_ ] && exit 0
done <<< "$inclist"
exit 1