-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaudit-includes
94 lines (88 loc) · 2.55 KB
/
audit-includes
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
#! /bin/sh
egrep -H "$(printf '^[ \t]*#[ \t]*include\\>')" "$@" |
sed -e "$(printf 's/:[ \t]*#[ \t]*include[ \t]*[<\"]/ /')" -e 's/[>"]$//' |
{
current=""
lack_base_hh=""
late_base_hh=""
shouldnt_base_hh=""
shouldnt_config_h=""
shouldnt_string=""
shouldnt_iosfwd=""
found_base_hh=f
while read file header; do
if [ "$file" != "$current" ]; then
if [ "$current" != "" ] && [ $found_base_hh = f ]; then
lack_base_hh="$lack_base_hh $current"
fi
case $file in
(*.hh|*.h) found_base_hh=skip ;;
(*) found_base_hh=f ;;
esac
fi
case "$header" in
# The rules for base.hh are:
# No header file should include base.hh.
# All source files should include base.hh, as their very first
# inclusion.
(base.hh)
case "$file" in
(*.hh|*.h) shouldnt_base_hh="$shouldnt_base_hh $file" ;;
($current) late_base_hh="$late_base_hh $file"
found_base_hh=t ;;
(*) found_base_hh=t ;;
esac
;;
# The rules for these are simple: nobody should include them
# (except base.hh itself).
(config.h)
if [ "$file" != "base.hh" ]
then shouldnt_config_h="$shouldnt_config_h $file"
fi;;
(string)
if [ "$file" != "base.hh" ]
then shouldnt_string="$shouldnt_string $file"
fi;;
(iosfwd)
if [ "$file" != "base.hh" ]
then shouldnt_iosfwd="$shouldnt_iosfwd $file"
fi;;
esac
current="$file"
done
if [ $found_base_hh = f ]; then
lack_base_hh="$lack_base_hh $current"
fi
status=0
if [ -n "$lack_base_hh" ]; then
echo "*** Missing #include \"base.hh\":"
echo "$lack_base_hh" | tr -s ' ' | fmt | sed 's/^/ /'
status=1
fi
if [ -n "$late_base_hh" ]; then
echo "*** Late #include \"base.hh\":"
echo "$late_base_hh" | tr -s ' ' | fmt | sed 's/^/ /'
status=1
fi
if [ -n "$shouldnt_base_hh" ]; then
echo "*** Unwanted #include \"base.hh\":"
echo "$shouldnt_base_hh" | tr -s ' ' | fmt | sed 's/^/ /'
status=1
fi
if [ -n "$shouldnt_config_h" ]; then
echo "*** Unwanted #include \"config.h\":"
echo "$shouldnt_config_h" | tr -s ' ' | fmt | sed 's/^/ /'
status=1
fi
if [ -n "$shouldnt_string" ]; then
echo "*** Unwanted #include <string>:"
echo "$shouldnt_string" | tr -s ' ' | fmt | sed 's/^/ /'
status=1
fi
if [ -n "$shouldnt_iosfwd" ]; then
echo "*** Unwanted #include <iosfwd>:"
echo "$shouldnt_iosfwd" | tr -s ' ' | fmt | sed 's/^/ /'
status=1
fi
exit $status
}