File: dgrep

package info (click to toggle)
debian-goodies 0.47
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 208 kB
  • ctags: 55
  • sloc: sh: 526; python: 453; makefile: 46
file content (69 lines) | stat: -rwxr-xr-x 2,016 bytes parent folder | download | duplicates (6)
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
#!/bin/sh

# dgrep -- grep through files belonging to an installed Debian package

# Copyright (C) 2001 Matt Zimmerman <mdz@debian.org>

# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

set -e

prog=`echo $0 | sed 's|.*/d||'`

case "$prog" in
    grep|egrep|fgrep|zgrep) ;;
    *) echo >&2 "dpkg-grep: Unrecognized invocation: $0"; exit 1 ;;
esac

# Option parser modeled after the one in zgrep from GNU grep

recursive=0
opts=""
pat=""
after_args=""
while test $# -ne 0; do
    case "$1" in
        --recursive|--d*=recurse) echo >&2 "recursive grep not supported"
            exit 1
            ;;
        --d*=skip) ;;
        --d*=read) echo >&2 "--directories=read not supported"; exit 1 ;;
        --help)
            echo "Usage: dgrep [most grep options] <pattern> <package>..."; exit 0 ;;
        --*) ;;
        -*)
            case "$1" in
                -*r*) echo >&2 "recursive grep not supported"; exit 1 ;;
            esac
            ;;
    esac
    case "$after_args$1" in
        -[ef]) opts="$opts $1"; shift; pat=$1 ;;
        -[ABCdm]) opts="$opts $1 $2"; shift ;;
        --) opts="$opts $1"; after_args=1 ;;
        -*) opts="$opts $1" ;;
        *)
            if test -z "$pat"; then
                pat=$1
            else
                break
            fi
            ;;
    esac
    shift
done

exec dglob -0f "$@" | xargs -0r $prog $opts $pat