-
Notifications
You must be signed in to change notification settings - Fork 0
/
ilint
executable file
·69 lines (63 loc) · 1.84 KB
/
ilint
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
#!/bin/sh
build() {
if [ "$BUILD" ]; then "$BUILD"
elif [ -f 'Makefile' ]; then make
elif [ -f 'makefile' ]; then make
elif [ -f 'build.sh' ]; then ./build.sh
elif [ -f 'make.sh' ]; then ./make.sh
elif [ -f 'build' ]; then ./build
elif [ -f 'make' ]; then ./make
else
echo "Error: no makefile or build script found in the current directory"
echo "Please set the BUILD environment variable to your build command"
exit 1
fi
}
check_build() {
path="$1"
if CFLAGS="-O0" CXXFLAGS="-O0" build >/dev/null 2>/dev/null; then
echo "${path#./}:$lineno REDUNDANT"
else
echo "${path#./}:$lineno required"
fi
}
process_file() {
path="$1"
basename="$(basename "$path" ".${path##*.}")"
orig="$path~"
while [ -e "$orig" ]; do orig="$orig~"; done
trap 'mv "$orig" "$path"; exit' HUP INT QUIT TERM
mv "$path" "$orig"
grep -n '^#include' "$orig" | cut -d':' -f1 |
while read -r lineno; do
line="$(sed "${lineno}q;d" "$orig")"
if [ "${line%.*}." != "#include \"$basename." ]; then
sed "${lineno}d" "$orig" > "$path"
check_build "$path"
fi
done
mv "$orig" "$path"
trap - INT HUP QUIT TERM
}
process_directory() {
find "$1" -name '*.c' -o -name '*.C' -o -name '*.cc' -o -name '*.cpp' -o \
-name '*.cxx' -o -name '*.c++' -o -name '*.h' -o -name '*.H' -o \
-name '*.hh' -o -name '*.hpp' -o -name '*.hxx' -o -name '*.h++' |
while IFS='' read -r path; do
process_file "$path"
done
}
main() {
if ! build >/dev/null 2>/dev/null; then
echo "Error: initial test build failed"
exit 1
fi
for path in "${@:-.}"; do
if [ -d "$path" ]; then
process_directory "$path"
else
process_file "$path"
fi
done
}
main "$@"