3 # usage: inclosure [ -I dir ] ... [ -G header-name ] ... header-name ...
5 # Locates each standard header and argument header-name in the
6 # specified "-I" include path (default is /usr/include) and parses
7 # any header names out of its #include directives. These names are
8 # treated recursively to identify a _transitive_closure_ of standard
9 # header names, which is sorted and sent to standard output. Headers
10 # not specified with -G, and included somewhere but not located are
13 # Each header reported by this program must be "shadowed" by a
14 # file of the same name in a C++ header. See
15 # http://www.cantrip.org/cheaders.html
18 # - Cannot cope with header file names that contain spaces
19 # - Ignores comment-block delimiters
20 # - Ignores sub-includes under #include_next headers.
23 echo "this-compensates-for-a-stupid-bug-in-GNU-fgrep." >$OLDH
28 IGNORES
=/tmp
/ignores$$
29 echo "this-compensates-for-a-stupid-bug-in-GNU-fgrep.">$IGNORES
31 trap "rm -f $NEW $HDRS $OLDH $IGNORES" 0
35 while [ $# != 0 -a "$1" != "${1#-}" ]; do
37 case "$FLAG" in -I|
-G)
39 if [ "$ARG" = "" ]; then
44 echo "$0: $FLAG needs an argument."
51 -I) INCPATH
="$INCPATH $ARG" ;;
52 -G) echo " $ARG " >>$IGNORES ;;
55 INCPATH
=${INCPATH-"/usr/include"}
59 STDHDRS
="assert.h ctype.h errno.h float.h limits.h \
60 locale.h math.h setjmp.h signal.h stdarg.h stddef.h \
61 stdio.h stdlib.h string.h time.h wchar.h wctype.h "
64 for file in $STDHDRS $OTHERS; do
68 until cmp -s $OLDH $HDRS; do # (until no new headers found)
70 fgrep
-v -f $OLDH $HDRS \
73 for dir
in $INCPATH; do
75 if [ -f "$name" ]; then
81 if [ "$found" = no
]; then # && echo " $file " | fgrep -v -q -f $IGNORES
82 echo "$0: warning: header $file not found in include path." $1>&2
86 '/^[ ]*#[ ]*include[ ]*<[^>]*>/s/^[^<]*<\([^>]*\)>.*/\1/p' \
89 for ignore
in `cat $IGNORES`; do
90 if [ "$ignore" = "$file" ]; then drop
=yes; fi
92 case "$file" in /*) drop
=yes;; esac # no absolute paths
93 case $drop in no
) echo "$file";; esac
96 cat $OLDH $NEW |
sort -u -o $HDRS