monotone

monotone Mtn Source Tree

Root/audit-includes

1#! /bin/sh
2
3egrep -H "$(printf '^[ \t]*#[ \t]*include\\>')" "$@" |
4 sed -e "$(printf 's/:[ \t]*#[ \t]*include[ \t]*[<\"]/ /')" -e 's/[>"]$//' |
5 {
6 current=""
7 lack_base_hh=""
8 late_base_hh=""
9 shouldnt_base_hh=""
10 shouldnt_config_h=""
11 shouldnt_string=""
12 shouldnt_iosfwd=""
13 found_base_hh=f
14
15 while read file header; do
16 if [ "$file" != "$current" ]; then
17 if [ "$current" != "" ] && [ $found_base_hh = f ]; then
18 lack_base_hh="$lack_base_hh $current"
19fi
20case $file in
21 (*.hh|*.h) found_base_hh=skip ;;
22 (*) found_base_hh=f ;;
23esac
24 fi
25
26 case "$header" in
27 # The rules for base.hh are:
28# No header file should include base.hh.
29# All source files should include base.hh, as their very first
30# inclusion.
31
32 (base.hh)
33 case "$file" in
34 (*.hh|*.h) shouldnt_base_hh="$shouldnt_base_hh $file" ;;
35 ($current) late_base_hh="$late_base_hh $file"
36 found_base_hh=t ;;
37 (*) found_base_hh=t ;;
38 esac
39;;
40
41# The rules for these are simple: nobody should include them
42# (except base.hh itself).
43(config.h)
44 if [ "$file" != "base.hh" ]
45 then shouldnt_config_h="$shouldnt_config_h $file"
46 fi;;
47(string)
48 if [ "$file" != "base.hh" ]
49 then shouldnt_string="$shouldnt_string $file"
50 fi;;
51(iosfwd)
52 if [ "$file" != "base.hh" ]
53 then shouldnt_iosfwd="$shouldnt_iosfwd $file"
54 fi;;
55 esac
56 current="$file"
57 done
58 if [ $found_base_hh = f ]; then
59 lack_base_hh="$lack_base_hh $current"
60 fi
61
62 status=0
63 if [ -n "$lack_base_hh" ]; then
64 echo "*** Missing #include \"base.hh\":"
65 echo "$lack_base_hh" | tr -s ' ' | fmt | sed 's/^/ /'
66 status=1
67 fi
68 if [ -n "$late_base_hh" ]; then
69 echo "*** Late #include \"base.hh\":"
70 echo "$late_base_hh" | tr -s ' ' | fmt | sed 's/^/ /'
71 status=1
72 fi
73 if [ -n "$shouldnt_base_hh" ]; then
74 echo "*** Unwanted #include \"base.hh\":"
75 echo "$shouldnt_base_hh" | tr -s ' ' | fmt | sed 's/^/ /'
76 status=1
77 fi
78 if [ -n "$shouldnt_config_h" ]; then
79 echo "*** Unwanted #include \"config.h\":"
80 echo "$shouldnt_config_h" | tr -s ' ' | fmt | sed 's/^/ /'
81 status=1
82 fi
83 if [ -n "$shouldnt_string" ]; then
84 echo "*** Unwanted #include <string>:"
85 echo "$shouldnt_string" | tr -s ' ' | fmt | sed 's/^/ /'
86 status=1
87 fi
88 if [ -n "$shouldnt_iosfwd" ]; then
89 echo "*** Unwanted #include <iosfwd>:"
90 echo "$shouldnt_iosfwd" | tr -s ' ' | fmt | sed 's/^/ /'
91 status=1
92 fi
93 exit $status
94 }

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status