| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# dgrep -- grep through files belonging to an installed Debian package |
| 4 |
|
| 5 |
# Copyright (C) 2001 Matt Zimmerman <[email protected]> |
| 6 |
|
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2, or (at your option) |
| 10 |
# any later version. |
| 11 |
|
| 12 |
# This program is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
|
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program; if not, write to the Free Software |
| 19 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 |
# 02111-1307, USA. |
| 21 |
|
| 22 |
set -e |
| 23 |
|
| 24 |
prog=`echo $0 | sed 's|.*/d||'` |
| 25 |
|
| 26 |
case "$prog" in |
| 27 |
grep|egrep|fgrep|zgrep|zegrep|zfgrep) ;; |
| 28 |
*) echo >&2 "dgrep: Unrecognized invocation: $0"; exit 1 ;; |
| 29 |
esac |
| 30 |
|
| 31 |
# Option parser modeled after the one in zgrep from GNU grep |
| 32 |
|
| 33 |
recursive=0 |
| 34 |
opts="" |
| 35 |
pat="" |
| 36 |
after_args="" |
| 37 |
while test $# -ne 0; do |
| 38 |
case "$1" in |
| 39 |
--recursive|--d*=recurse) echo >&2 "dgrep: recursive grep not supported" |
| 40 |
exit 1 |
| 41 |
;; |
| 42 |
--d*=skip) ;; |
| 43 |
--d*=read) echo >&2 "dgrep: --directories=read not supported"; exit 1 ;; |
| 44 |
--help) |
| 45 |
echo "Usage: dgrep [most grep options] <pattern> <package>..."; exit 0 ;; |
| 46 |
--*) ;; |
| 47 |
-*) |
| 48 |
case "$1" in |
| 49 |
-*r*) echo >&2 "dgrep: recursive grep not supported"; exit 1 ;; |
| 50 |
esac |
| 51 |
;; |
| 52 |
esac |
| 53 |
case "$after_args$1" in |
| 54 |
-[ef]) opts="$opts $1"; shift; pat=$1 ;; |
| 55 |
-[ABCdm]) opts="$opts $1 $2"; shift ;; |
| 56 |
--) opts="$opts $1"; after_args=1 ;; |
| 57 |
-*) opts="$opts $1" ;; |
| 58 |
*) |
| 59 |
if test -z "$pat"; then |
| 60 |
pat=$1 |
| 61 |
else |
| 62 |
break |
| 63 |
fi |
| 64 |
;; |
| 65 |
esac |
| 66 |
shift |
| 67 |
done |
| 68 |
|
| 69 |
# *SIGH*, unfortunately needed for GNU grep 3.8 |
| 70 |
case "$prog" in |
| 71 |
egrep) prog=grep; opts="$opts -E" ;; |
| 72 |
fgrep) prog=grep; opts="$opts -F" ;; |
| 73 |
esac |
| 74 |
|
| 75 |
for pkgglob in "$@"; do dglob -0f "$pkgglob"; done | xargs -0r "$prog" $opts "$pat" |