#!/bin/sh # incgrep --- search all header files in known include directories for pattern # Author: Noah Friedman # Created: 1996-01-29 # Copyright (C) 1995, 1996, 2004, 2005 Noah S. Friedman # $Id: incgrep,v 2.5 2005/10/02 18:38:43 friedman Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, you can either send email to this # program's maintainer or write to: The Free Software Foundation, # Inc.; 51 Franklin Street, Fifth Floor; Boston, MA 02110-1301, USA. # Commentary: # This script works better if you have GCC version 2+ and GNU `find'. # Code: cc=${CC-gcc} cpp=cpp includes=' /usr/local/gnu/include /usr/local/include /usr/include ' if ($cc -v) > /dev/null 2>&1; then version=`$cc -v 2>&1 \ | sed -ne '/gcc version/!d' -e 's/gcc version *//p'` case "$version" in 2.95.* | [3-9].* ) cpp=`$cc -print-prog-name=cpp` ;; 2.* ) ccdir=`$cc -print-libgcc-file-name | sed -e 's/\/[^/]*$//'` cpp=$ccdir/cpp ;; esac case $1 in -lang-* ) lang=`echo "$1" | sed -e 's/^-lang-//'` cpp="$cpp -x $lang" shift ;; esac includes=`$cpp -v 2>&1 < /dev/null \ | sed -ne '/#include <...> search starts here:/!d n :l /^End of search list./!{ p n b l }'` fi follow= if (find --version) > /dev/null 2>&1 ; then follow=-follow else case `(uname -s) 2> /dev/null` in FreeBSD ) follow=-follow ;; esac fi { case $lang in c++ ) find $includes $follow -type f -print ;; * ) find $includes $follow -name '*.h' -print ;; esac } 2> /dev/null | xargs grep ${1+"$@"} # incgrep ends here.