#!/bin/sh # # lint_includes -- look for unneeded includes via lint # # Runs lint, looks for the following messages: # E_INCL_MNO_US include file may be unnecessary: %s # E_INCL_MNO_US_TITLE include file may be unnecessary # E_INCL_MNUSD include file may be unnecessary: %s # E_INCL_MNUSD_TITLE include file may be unnecessary # E_INCL_NO_US include file is unnecessary: %s # E_INCL_NO_US_TITLE include file is unnecessary # E_INCL_NUSD include file is unnecessary: %s # E_INCL_NUSD_TITLE include file is unnecessary # ProgName=`basename $0` Verbose=0 # Turn on almost everything, but use one-line errors for greping. LINTOPTS='-errchk -errhdr=%all -errfmt=simple -errsecurity -Nlevel -Ncheck=macro -XCC -Xtransition -errtags' main() { if [ $# -lt 1 ]; then say "$ProgName error: you must supply at least one C file" say "Usage: $0 file" exit 1 fi if [ "$1" = "-v" ]; then Verbose=1 shift fi lint $LINTOPTS "$@" 2>&1 |\ if [ $Verbose -eq 1 ]; then cat else postprocess fi } # # postprocess -- make multi-line message single-line and filter. # postprocess() { nawk ' BEGIN { prev = ""; } /.*/ { # print ">>> " $0; if ( $0 ~ /^lint/) { # print "<<< lint error" # Lint error, print it print $0; prev = ""; } else if ($0 ~ /E_INCL_[MN][NOU]/) { # print "<<< matched" # Matched, see if it was multi-line if ($0 !~ /^"/ && prev != "") { # print "<<< multi-line"; printf("%s ", prev); prev = ""; } # print "<<< the matched line"; print $0; } else if ($0 ~ /^"/) { # beginning of a possible multi-line message # print "<<< saved for possible multi-line"; prev = $0; } } ' } say() { echo "$@" 1>&2 } main "$@"