File: audit-includes

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (114 lines) | stat: -rw-r--r-- 3,325 bytes parent folder | download
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/sh
# Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
#
# This program is made available under the GNU GPL version 2.0 or
# greater. See the accompanying file COPYING for details.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.

# Check all C++ source files to make sure they obey the header file rules.

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_gettext_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;;
	(gettext.h)
	  if [ "$file" != "base.hh" ]
	  then shouldnt_gettext_h="$shouldnt_gettext_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_gettext_h" ]; then
      echo "*** Unwanted #include \"gettext.h\":"
      echo "$shouldnt_gettext_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
  }